You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When exporting a chart, each line of multiline caption text should begin at the same x position.
Actual behaviour
Lines 2+ are completely left-aligned, ignoring chart spacing and any other factors that determine the position of the first line of caption text.
I believe this is caused by a bug in the TextBuilder.modifyDOM function. This line in particular grabs the x attribute value of the SVG (I think), and then sets the x attribute for all tspans (which replace br tags when generating SVG) to it. This has the result of resetting the text position to x=0, causing lines 2+ to be incorrectly positioned in multiline captions.
I think the solution is to use the x position of the parent text.highcharts-subtitle element.
As you can see, the tspan resets the x position from 10 to 0.
Product version
Highcharts 9.1.2
Affected browser(s)
All
Workaround
Because Highcharts copies all attributes from the br tag when generating the tspan tag, adding a dx attribute to all br tags that moves the tspan over to align with the first line will fix it. See the following example:
In that example, I've set dx to 10 (the chart left-spacing), which produces a <tspan x="0" dx="10" ...> element in the exported SVG, which perfectly aligns with the first line of text.
The text was updated successfully, but these errors were encountered:
@khlieng Thanks for the incredibly fast response! Yes I indeed was misunderstanding the purpose of the useHTML option and didn't actually need it, so disabling it completely solves the issue for my use-case.
Expected behaviour
When exporting a chart, each line of multiline caption text should begin at the same x position.
Actual behaviour
Lines 2+ are completely left-aligned, ignoring chart spacing and any other factors that determine the position of the first line of caption text.
I believe this is caused by a bug in the
TextBuilder.modifyDOM
function. This line in particular grabs thex
attribute value of the SVG (I think), and then sets thex
attribute for all tspans (which replacebr
tags when generating SVG) to it. This has the result of resetting the text position tox=0
, causing lines 2+ to be incorrectly positioned in multiline captions.I think the solution is to use the
x
position of the parenttext.highcharts-subtitle
element.Live demo with steps to reproduce
https://jsfiddle.net/5f18dywv/1/
Click the Export button to export the chart. Note how the "Bar" line is misaligned.
Here's the caption text node from the above demo:
As you can see, the
tspan
resets thex
position from10
to0
.Product version
Highcharts 9.1.2
Affected browser(s)
All
Workaround
Because Highcharts copies all attributes from the
br
tag when generating thetspan
tag, adding adx
attribute to allbr
tags that moves thetspan
over to align with the first line will fix it. See the following example:https://jsfiddle.net/2xu0s9de/
In that example, I've set
dx
to10
(the chart left-spacing), which produces a<tspan x="0" dx="10" ...>
element in the exported SVG, which perfectly aligns with the first line of text.The text was updated successfully, but these errors were encountered: