Why does transform-origin not work for Firefox using inline SVG and is there an alternative?
I've solved the problem but I am (as yet) unable to give you a comprehensive reasoning why it works.
The first important thing to know is that you can chain SVG Transforms.
So, wherever you write transform="scale(2)"
, you can add a translate(x, y)
to the chain, like this:
transform="scale(2) translate(x, y)"
So far, so good... but if scale
is 2
, then what values should we give to x
and y
of translate
?
To find out, I decided to superimpose larger and subimpose smaller scaled versions of your SVG shape (one for each colour of the rainbow) and see what patterns I could find.
Over the top of your grey shape, I positioned an identically sized green shape.
I gave the green shape a transform of:
transform="scale(1) translate(0, 0)"
so that it would be exactly congruent with your original grey shape.
Then I set about subimposing larger scaled versions (yellow, orange, red) and superimposing smaller scaled versions (blue, indigo, violet).
I predicted that x
and y
in each case would relate to the scale
factor applied to that shape and also to the overall size of the original viewBox
.
With 3 smaller versions and 3 larger versions, the pattern emerged:
- Red,
8
times as large /x
&y
transform value is50% of ((1000 / 8) - 1000)
- Orange,
4
times as large /x
&y
transform value is50% of ((1000 / 4) - 1000)
- Yellow,
2
times as large /x
&y
transform value is50% of ((1000 / 2) - 1000)
- Green,
1
times as large /x
&y
transform value is50% of ((1000 / 1) - 1000)
- Blue,
0.5
times as large /x
&y
transform value is50% of ((1000 / 0.5) - 1000)
- Indigo,
0.25
times as large /x
&y
transform value is50% of ((1000 / 0.25) - 1000)
- Violet,
0.125
times as large /x
&y
transform value is50% of ((1000 / 0.125) - 1000)
From this, we can conclude, that if you are positioning a shape centered at 50%, 50%
of your viewBox
and you want to display the shape in that same position with scale(2)
, you must also apply a translate
for x
of:
50% of ((width of canvas / scale-factor) - (width of canvas))
where 50%
corresponds to the x
position you want to centre the shape over.
And a translate
for y
of:
50% of ((height of canvas / scale-factor) - (height of canvas))
where 50%
corresponds to the y
position you want to centre the shape over.
This works consistently, but I haven't spent enough time staring at it yet, to properly understand why.
Working Example:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000">
<!-- Grey Original --><path fill="#555" d="M500 500 400 400 400 600 600 600 600 400z" />
<!-- Red Transform [50% of ((1000 / 8) - 1000) is -437.5] --><path fill="rgb(255, 0, 0)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(8) translate(-437.5, -437.5)" />
<!-- Orange Transform [50% of ((1000 / 4) - 1000) is -375] --><path fill="rgb(255, 125, 0)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(4) translate(-375, -375)" />
<!-- Yellow Transform [50% of ((1000 / 2) - 1000) is -250] --><path fill="rgb(255, 255, 0)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(2) translate(-250, -250)" />
<!-- Green Transform [50% of ((1000 / 1) - 1000) is 0] --><path fill="rgb(0, 125, 0)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(1) translate(0, 0)" />
<!-- Blue Transform [50% of ((1000 / 0.5) - 1000) is 500] --><path fill="rgb(0, 0, 125)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(0.5) translate(500, 500)" />
<!-- Indigo Transform [50% of ((1000 / 0.25) - 1000) is 1500] --><path fill="rgb(63, 0, 255)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(0.25) translate(1500, 1500)" />
<!-- Violet Transform [50% of ((1000 / 0.125) - 1000) is 3500] --><path fill="rgb(199, 125, 243)" d="M500 500 400 400 400 600 600 600 600 400z" transform="scale(0.125) translate(3500, 3500)" />
</svg>
Implementing an alternative solution with Pandas `transform`
If want always same year then first join years with date without year
:
df = pd.DataFrame({'release_date':['2062-10-04','1980-12-10'],'release_year':[1962,1980]})
print (df)
release_date release_year
0 2062-10-04 1962
1 1980-12-10 1980
df['release_date'] = pd.to_datetime(df['release_year'].astype(str) +
df['release_date'].str[4:])
print (df)
release_date release_year
0 1962-10-04 1962
1 1980-12-10 1980
Related Topics
How to Have Both CSS and SCSS in Angular
Change The Color Profile of a Page in CSS
CSS Rules for Webkit Based Browsers
Tailwind CSS + Vuejs Single File Component and Vs Code Integration
How to Divide Bootstrap Col-Md Div to Half Vertically
Definition List with Inline Pairs
How to Make The New Facebook Post Embed Feature Responsive
Text in Outlook Doesn't Use Line-Height
Larger Div Centered Inside Smaller Div
How to Make Bootstrap Readonly Input Field Look Like Normal Text
Bootstrap: How to Create a Series of Div on One Line Hiding The Overflowing Divs
Background Color for Text (Only)
How to Rotate a Font Icon 45 Degrees
Radio Buttons Show Unwanted White Background in Chrome. Firefox Is Fine
How to Make a Flexbox Container That Stretches to Fit Wrapped Items
Center Text Larger Than Container? (Without Using Separate Child Element)
Is There an Equivalent of Spriting for Svg Images in Web Pages