Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-transforms-1] 'view-box' definition doesn't make sense #4662

Closed
tabatkins opened this issue Jan 10, 2020 · 10 comments
Closed

[css-transforms-1] 'view-box' definition doesn't make sense #4662

tabatkins opened this issue Jan 10, 2020 · 10 comments
Labels
Closed Rejected as Wontfix by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-box-3 Current Work css-transforms-1 Current Work SVG

Comments

@tabatkins
Copy link
Member

tabatkins commented Jan 10, 2020

In https://drafts.csswg.org/css-transforms-1/#valdef-transform-box-view-box, the 'view-box' value refers to the nearest SVG viewport. It then goes into greater detail, saying:

If a viewBox attribute is specified for the SVG viewport creating element:

  • The reference box is positioned at the origin of the coordinate system established by the viewBox attribute.

  • The dimension of the reference box is set to the width and height values of the viewBox attribute.

As a concrete example, say you want a 100x100 coordinate system, with a "padding" of 20 on all edges. You'd write that as viewBox="-20 -20 140 140", giving you coordinates between [-20, 120] to use.

Following this spec text then, the box implied by view-box is at the 0,0 coordinate of the viewport (20 units in from the top and left), but it's 140 units wide and tall, extending out past the visible viewport area.

I suspect this really just means "yeah, it's the whole viewport, from top-left corner to bottom-right corner", in which case we can delete the entire attempt at greater detail.

If it really does mean to start it at the 0,0 coordinate (which is outside the viewport if the x/y values are positive!), then I have no idea what width/height it really wants, but the currently-specified values are nonsensical.

@tabatkins tabatkins added the css-transforms-1 Current Work label Jan 10, 2020
@tabatkins tabatkins changed the title [css-transforms-1] 'viewbox' definition doesn't make sense [css-transforms-1] 'view-box' definition doesn't make sense Jan 10, 2020
@tabatkins
Copy link
Member Author

Related: since the *-box value are currently scattered around at least four specs, and have conflicting definitions in at least one case, @fantasai has begun collecting them into Box instead: https://drafts.csswg.org/css-box-3/#keywords

@heycam
Copy link
Contributor

heycam commented Jan 15, 2020

Consider this content:

<svg width="100" height="100" viewBox="1000 1000 1000 1000">
  <rect x="1000" y="1000" width="500" height="500" transform="rotate(1)"/>
</svg>

We have transform-box: view-box; transform-origin: 0 0; from the initial value and the UA sheet. The origin for the rotation needs to be (0, 0) in the rect's coordinate space (i.e., far off-screen to the top-left), not the top-left corner of the viewport.

As for the size of the box,

<svg width="100" height="100" viewBox="1000 1000 1000 1000">
  <rect x="1000" y="1000" width="500" height="500" style="transform: translate(25%, 0);"/>
</svg>

This translates the rectangle horizontally into the middle of the viewport in Firefox and Chrome. Whether you consider the percentage to resolve against the width of a (0, 0, 1000, 1000) reference box, or visually against the width of the viewport, I guess doesn't matter. (Though maybe it would matter with preserveAspectRatio involved?)

@tabatkins
Copy link
Member Author

Having the ability to make a % relative to the visible viewport is useful, yes, but the zero point is still arbitrary and unrelated. Or the opposite - the zero point might be reasonable, but then the visible viewport area is arbitrary and unrelated. There's no connection between the box used to size translates and the point used to center rotates/scales, unlike in the other values.

If the visible viewport's width/height and start/start corner were used, I'd be fine.

Is there a reason this particular choice of values was made?

@heycam
Copy link
Contributor

heycam commented Jan 15, 2020

I don't disagree that a box that has its origin be at (0, 0) and its size the size from the viewBox is strange. Given the way we retrofitted CSS' transform-related properties into SVG, the origin must be at (0, 0) for compatibility with existing SVG content. That leaves us with considering something different for the size of the box, but I really don't know if there is anything more useful we could choose.

@tabatkins
Copy link
Member Author

In what context does SVG use this concept?

@AmeliaBR AmeliaBR added the SVG label Jan 21, 2020
@AmeliaBR
Copy link
Contributor

The definition may sometimes create unintuitive results, but this is how transforms and percentages have always been defined in SVG. Transforms are relative to the 0,0 origin, regardless of where that is in the graphic (or even if it is way outside the graphic). And percentage width/height are always relative to the full viewBox width/height, regardless of how that is offset from the origin.

And the basic behavior is definitely useful, if you're used to working with SVG viewBox intentionally (e.g., to create a centered coordinate system) and sizing SVG elements in percentages relative to that origin. (I don't have any examples doing this, but mostly because the support hasn't existed to really make it worth playing around with transform-origin for SVG.)

In your case of fudging the viewBox width/height to create padding, the results are less useful, but I'm not sure what would be more useful? In your example of viewBox="-20 -20 140 140", you probably want 100% = 100 units, but I'm not sure how the browser is supposed to guess that. Best to avoid setting your transform origin in percentages at all in that case.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-transforms-1] 'view-box' definition doesn't make sense, and agreed to the following:

  • RESOLVED: No change to the behavior, add a note to the spec
  • RESOLVED: move the box keyword definitions on css-box and publish a new working draft
  • RESOLVED: rebase the rest of the spec referring to these definitions to point to css-box
  • RESOLVED: Move margin-trim to css-box-4 before republishing
The full IRC log of that discussion <emilio> Topic: [css-transforms-1] 'view-box' definition doesn't make sense
<astearns> github: https://github.com//issues/4662
<emilio> TabAtkins: the definition seems to not make sense
<emilio> ... the origin and size of the box are not related
<emilio> ... says that the origin of the coordinate space is the viewbox start
<emilio> ... and the size is the size of the viewbox
<emilio> ... so for example if you have a viewbox="20 20 100 100"
<emilio> ... the origin of the coordinate space is outside of the viewport, such as the origin is at (-20, -20)
<emilio> ... so that the viewbox is based off a rectangle outside of the svg's viewport
<emilio> heycam: so before CSS transforms, in svg you couldn't use percents inside transform so this was a non-issue
<emilio> ... I wonder if the issue is the way we're defining this rectangle
<emilio> ... Maybe it doesn't make sense to define that rect
<emilio> emilio: for percents in transforms you just need a basis so you don't need any origin right?
<RossenF2F> q?
<emilio> fantasai: yeah but other stuff references the view-box
<emilio> TabAtkins: and the origin matters for rotations and scales
<emilio> emilio: fair
<emilio> myles_: pretend you use transform-box: view-box and rotate by 3deg or something, what would you expect?
<emilio> TabAtkins: multiple acceptable answers, but the issue is that the size and the origin are not related, unlike other boxes
<emilio> fantasai: the issue is that this is how transforms have been defined in SVG
<emilio> fantasai: [reads AmeliaBR's comment in the issue]
<emilio> https://github.com//issues/4662#issuecomment-576496516
<emilio> TabAtkins: ok if it's what SVG uses by default then sure, whatever
<emilio> ... but I'd like it to be called out explicitly
<emilio> faceless2: The way we see the viewbox is just a translate transform
<emilio> ... I'm not sure it's as confusing as it sounds
<emilio> TabAtkins: my issue is that if you choose transform-origin: 100% 100% the point you get makes no sense
<emilio> ... but sure if it's legacy then fine, I thought it was invented recently as it was added after other changes
<emilio> ... so I'm ok with the behavior but I want to clarify that this is legacy svg behavior
<emilio> fantasai: there are other specs that reference these values somewhat inconsistently
<emilio> ... we copied them all out into the box model module
<TabAtkins> https://drafts.csswg.org/css-box/#keywords
<emilio> ... I want to change the definition of viewbox to account for this and then change all specs to reference those definitions
<emilio> ... any objections to doing that?
<emilio> RossenF2F: it seems something we should do, and seems we should close this with no change
<emilio> ... with the note added to the spec explaining why
<emilio> TabAtkins: I guess we'll add it to the box spec
<emilio> RossenF2F: sure
<emilio> fantasai: do we need another keyword to reference the box tab was talking about? (size of viewbox at the position of viewbox?)
<emilio> RossenF2F: probably not
<emilio> ... objections to the proposed resolution?
<emilio> RESOLVED: No change to the behavior, add a note to the spec
<emilio> RESOLVED: move the box keyword definitions on css-box and publish a new working draft
<emilio> RESOLVED: rebase the rest of the spec referring to these definitions to point to css-box
<emilio> fantasai: I propose to move the only non-css2 feature in css-box (margin-trim) to level 4 and move this to CR and co. fast so that other specs can depend on it
<emilio> RossenF2F: sounds reasonable, objections?
<fantasai> s/spe referring/specs referring/
<fantasai> s/spec referring/specs referring/
<emilio> RESOLVED: Move margin-trim to css-box-4 before republishing

@tabatkins
Copy link
Member Author

Ah yeah, centered coordinates (like viewBox="-.5 -.5 1 1") happen to be fairly meaningful here. It's still weird that, say, transform-origin: 100% 100%; puts the origin off the bottom-right corner, but eh.

Ultimately, tho, it wasn't clear to me that this was just capturing the legacy behavior of SVG; it looked like a de novo addition. If it's just capturing a legacy behavior, I'm fine with it; I'd just like a note indicating that.

@fantasai
Copy link
Collaborator

fantasai commented Mar 7, 2020

OK, added this definition in. As part of that, I defined a new term, “SVG viewport origin box”. @AmeliaBR Let me know if it looks correct to you, and also if you want me to either export the term or to link to an equivalent term in the SVG spec. :)

@AmeliaBR
Copy link
Contributor

@fantasai, I'm OK with defining a new term, since SVG doesn't have an equivalent, but we need to be careful about the difference between SVG viewport and SVG viewbox (= the difference between the viewport coordinate system and the initial user coordinate system).

Suggested wording:

view-box
Refers to the nearest SVG viewport element’s origin box, which is a rectangle with the width and height of the initial SVG user coordinate system established by the viewBox attribute for that element, positioned such that its top left corner is anchored at the coordinate system origin. (In a CSS box context, treated as border-box.)

Note: When the SVG viewBox includes min-x or min-y offsets, this origin box does not actually correspond to the visible region defined by the viewBox!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Rejected as Wontfix by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-box-3 Current Work css-transforms-1 Current Work SVG
Projects
None yet
Development

No branches or pull requests

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy