-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Text.tspan("xy").newLine(): undocumented and unexpected behavior #1088
Comments
Yes maybe the naming is a bit off. The json representation of this node marks a line as "newLined" which would be already a better naming. The way newlines are realized is best done by having this method on a tspan that starts a new line. This might be a bit odd but everything else might get out of hand. Beside that, your last syntax proposal looks like it is easily implementable. And since it does not breaks any old behavior we could even ship it as a feature. add.newLine(function(line) {
line.tspan(...)
}) This would then lead to nested tspans which is allowed by the specs. However, calling newLine on those tspans wouldnt have any effect. |
Sounds good. So basically, the new 'newLine' would be just a wrapper around 'tspan' which calls 'newLine' and returns the tspan, correct? Somehow I think 'newLine' as the name for this new method would be confusing (because now there would be two methods (on 'Text' and 'tspan') with the same name but different behauviour, if I understand everything correctly). Maybe just 'line' would be okay? In this context, I'd prefer this name anyway.
Would 'newLine' on inner tspans automatically have no effect, or would there need to be a check in 'newLine'? |
correct!
I agree!
When building our lines with svg.js we only check the first level of tspans. So calling newLine on a deeper nested tspan would just not recognized by the function building the lines. It is silently ignored. Therefore nothing "bad" happens. A check is unneccesary. |
Okay, sound pretty simple. Will you implement this? Or should I give it a try? :) |
Well you can if you want. But only if you see any benefit for you with that. I am in the process of creating a new release anyway atm. So it might be faster when I do it instead of reviewing a PR forth and back :D |
I agree, and there wouldn't be a significant benefit for me personally (now that I know how 'newline()' works). Thanks for your work :) |
### Fixed - fixed `zoom()` method of runner which was passed a wrong parameter - fixed positioning methods of `TSpan` to position them by its bounding box - fixed `flip()` method which flips correctly by center by default now and accepts correct arguments - fixed a case in `rbox()` where not always all values of the box were updated - fixed `getOrigin()` function used by `transform()` so that all origin (#1085) popssibilities specified in the docs are working - fixed positioning of text by its baseline when using `amove()` - fixed tons of typings in the svg.d.ts file ### Added - added second Parameter to `SVG(el, isHTML)` which allows to explicitely create elements in the HTML namespace (#1058) - added `unlink()` and `linker()` to hyperlinked elements to remove or access the underling `<a>` element - added `wrap()` method to `Dom` which lets you wrap an element by another one - added `orient()` method to `Marker` - added `options` parameter to `dispatch()` and `fire()` to allow for more special needs - added `newLine()` constructor to `Text` to create a tspan marked as new line (#1088) - added lots of tests in es6 format
I comment in this section, but this is probably a problem for itself, and again it refers to tspans, and their dx value. I've been working with svg that isn't attached to the DOM, and I've come to the conclusion that this part is causing the problem (tspan): |
Today I experimented with text in svg.js and it seems newLine() doesn't have enough documentation (and the behavior was unexpected for me).
Here is the example from the documentation for
Text
:I'd expect the following regarding the first three spans:
But the result is:
To me (and probably many other people) 'newLine' means "insert new line character" or "break line". But it seems 'newLine' here means "create new line with this tspan".
I think another name than 'newLine' would have been better here to reduce confusion (for example 'toNewLine' or 'asNewLine').
Even more strange is that a tspan without 'newLine' at the end doesn't show up in the visible area of the SVG. Why does this happen?
I think the documentation needs to be updated to explain what 'newLine' actually does, and how tspans after a 'newLine' behave.
Besides, that, wouldn't there be other APIs that are less confusing?
For example, if 'Text' had a 'newLine' function, we could do the following:
I don't know if this would be easy to archive, but to me, this seems like a much more userfriendly and intuitive API.
What do you think?
The text was updated successfully, but these errors were encountered: