resizing polygons in svg using jquery - svg

I've seen problems similar to this one, but the solutions offered haven't worked for me. I have 67 polygons inside an svg tag. I want to resize the svg and its polygons. The code below doesn't scale. What are I doing wrong?
<svg version="1.1" id="svg" xmlns="http://www.w3.org/2000/svg" width="800" height="948" viewBox="0 0 800 948" transform="scale(3)" >
<polygon fill="#DCDDDE" stroke="#000000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
51.863,2.318 51.33,24.344 60.904,24.341 60.368,36.8 56.213,36.622 32.925,36.452 6.163,35.635 6.265,25.489 10.962,22.776
12.801,22.523 18.542,20.605 26.558,16.127 28.034,14.607 29.153,11.827 30.635,10.309 32.479,10.057 33.056,10.166 32.949,10.741
33.309,12.004 33.885,12.114 38.582,9.402 42.008,7.054 43.958,6.223 45.329,5.283 48.545,4.089 50.599,2.681 "/>
...(more polygons)
</svg>

You shouldn't be fiddling with the viewBox attribute. If you want to resize the SVG, change its width and height attributes.

What I finally did was take a ruler and measure the cumulative width of the polygons. Based on that, I could calculate how to resize them:
jquery:
var mapW = $('#map').width();
var mapH = Math.round(mapW * 255 / 477);
var svg = $('svg');
svg.attr('viewbox', '0 0 ' + mapW + ' ' + mapH);
svg.attr('preserveaspectratio', 'xminymin meet');
svg.attr('width', mapW+'px');
svg.attr('height', mapH+'px');
svg.attr('enable-background', "new 0 0 "+mapW + " " + mapH);
//svg.children().attr('transform', 'scale(1.2)');
var s = svg.children();
//I used a ruler to measure the width of the polygons - 360
var factor = mapW /360 ;
console.log(factor);
svg.children().attr('transform', 'scale(' + factor + ')');
//must change svg height to accommodate new height
svg.attr('height', mapH*factor+'px');

Related

Is it possible to plot circle in svg gnuplot terminal using circle svg command?

I would like to draw the family of circles using gnuplot svg terminal.
Svg has a command circle for this. All the images which I have found use svg path not circle, but circle is better because it takes less size ( optimisation).
In the gnuplot source code I have not found any command for using svg circle
grep -nR "circle"
Is it possible to plot circle in gnuplot which gives circle not path svg command?
Point types 5 and 6 are implemented as
/* 5 circle */
"\t<circle id='gpPt5' stroke-width='%.3f' stroke='currentColor' cx='0' cy='0' r='1'/>\n"
/* 6 circle (disk) filled */
"\t<use xlink:href='#gpPt5' id='gpPt6' fill='currentColor' stroke='none'/>\n"
So in principle you could place a lot of points, changing the x,y position and size of each one. This would be cumbersome in practice because the units of "pointsize" have no connection to the axis coordinates of the plot. You would have to empirically determine a scale factor, and it would change if you changed anything about the plot size or layout.
Here's a proof-of-principle example:
unset border
unset tics
set size square
set angle degree
plot sample [t=0:720] '+' using ($1*cos($1)):($1*sin($1)):($1/100.) with points pt 6 ps var
well, a SVG file is basically a text file. So, every program which can do some calculations and export some text can in principle create such a SVG file.
One attempt... (to be optimized). Basically, I started from an Inkscape SVG file with a single circle to get the text around the actual circle.
Now gnuplot generates this "Header" and "Footer" and a sequence of circles.
Code:
### generate svg output
reset session
Header = \
'<?xml version="1.0" encoding="UTF-8"?> '."\n".\
'<!-- Created with Inkscape (http://www.inkscape.org/) --> '."\n".\
'<svg width="200mm" height="200mm" version="1.1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> '."\n".\
' <metadata> '."\n".\
' <rdf:RDF> '."\n".\
' <cc:Work rdf:about=""> '."\n".\
' <dc:format>image/svg+xml</dc:format> '."\n".\
' <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> '."\n".\
' <dc:title/> '."\n".\
' </cc:Work> '."\n".\
' </rdf:RDF> '."\n".\
' </metadata> '
CircleTemplate = \
' <circle cx="'.'%g'.'" cy="'.'%g'.'" r="'.'%g'.'" fill="none" stroke="#f00" stroke-linecap="round" stroke-width=".1" style="paint-order:stroke markers fill"/> '
Footer = ' </svg> '
set print "Circles.svg"
print Header
Max = 90.
Factor1 = 12.
Factor2 = 2.5
do for [i=5:Max] {
print sprintf(CircleTemplate,100+Factor2*i/Max*cos(i*pi/Max*Factor1),100+Factor2*i/Max*sin(i*pi/Max*Factor1),i)
}
print Footer
set print
### end of code
Result:
This is not possible. I made a feature request.

Is there a way to make a map element(country/region) fly into its correct location on the map using svg animation?

I am just starting to play around with SVG animations. is it possible to make a country follow a random path to its correct place on the map? The equivalent of puzzle pieces assembling themselves when the box is opened is the best I can think of. Is this even possible with SVG animations or will something else be required?
This is what I have right now
<svg xmlns:svg="http://www.w3.org/2000/svg" viewBox="500 180 2500 1500">
<g>
<path id="US-WA" d="m 1204.9427,925.58655 c -1.3898,1.54162 -3.5681,6.4786 -0.2995,5.99944 -2.5653,2.58922 -3.3814,8.57974 -8.3992,5.99945 -1.6219,3.81537 1.3975,1.05569 2.0998,3.29967 0.4051,1.29541 -0.1592,2.49675 -0.5999,3.59966 -0.574,1.43862 -1.0531,2.67841 -0.5999,4.19962 0.9522,3.19931 -7.9766,5.68493 -8.3992,9.89904 -0.3437,3.41803 -2.4129,5.35128 -4.7996,6.89936 -1.6428,1.06557 -3.5355,1.94896 -5.0995,2.99971 -1.0386,0.69641 -3.9323,3.80031 -5.3995,2.99974 -2.3214,-1.26485 -4.2692,-0.25119 -5.0995,2.09979 1.0922,-2.53862 0.4348,-2.72427 -1.7999,-0.89992 2.8988,-1.68447 2.8988,-2.18139 0,-1.49986 3.4375,-0.54169 5.4851,-4.00727 8.6992,-5.09951 -1.4791,0.92554 -2.2605,2.696 -2.0998,4.49958 1.1896,-1.31713 2.6821,-2.51823 4.1996,-3.59966 3.3001,-1.51067 7.1003,-7.47473 3.2997,-5.39949 1.1845,-3.59217 9.6433,-5.94207 8.3992,-9.29912 -0.7286,0.44537 -1.4265,0.73373 -2.0998,1.19988 0.5808,-0.54475 1.0436,-1.2686 1.1999,-1.79983 0.5241,-1.76484 -0.3734,-3.74478 0.6,-5.3995 -1.6785,0.33627 -2.8771,1.62713 -3.2997,3.2997 -0.03,-3.66061 -9.5411,-2.9717 -13.1988,-3.59966 -6.0712,-1.04164 -10.1546,-4.19955 -15.8985,-5.69945 -3.6011,-0.94045 -7.7344,10.52732 -7.4993,14.09865 0.4944,7.49384 -4.7149,14.61007 -6.8993,21.59794 0.5058,-0.7678 1.1629,-1.73608 1.7998,-2.39975 1.0981,1.3452 2.7199,2.51886 4.4996,2.39975 -3.8928,1.13991 -8.3028,1.07697 -8.9992,5.99945 1.7737,-0.30948 3.4305,0.0307 4.7996,1.19988 -4.3035,-1.98209 -5.6594,6.11962 -9.2991,6.89936 0.7055,-1.47317 1.2194,-2.97283 1.7998,-4.49958 -0.289,0.51433 -1.36,2.46258 -2.0998,4.19962 -0.9513,2.23333 -1.3747,4.25619 0.8994,3.89962 2.6815,-0.41969 3.9566,-1.05119 6.5994,0.29996 0.1604,0.0815 0.4166,0.19315 0.5999,0.29997 0.8697,0.50617 1.9523,1.19458 2.9997,1.49987 0.5194,-0.12589 1.4274,0.31936 1.7999,0 -0.3763,0.16368 -0.7881,0.34662 -1.1999,0.29996 3.0295,3.11021 2.4204,6.05171 1.7998,8.39921 -0.621,2.3475 -1.3217,4.091 1.1999,5.3995 2.5216,1.3085 5.1278,-0.2432 8.0992,-2.3998 2.9714,-2.1566 6.495,-4.746 10.4991,-5.0995 8.0082,-0.7071 17.5494,6.3653 27.5974,5.9994 10.0479,-0.3658 14.9111,-7.1919 30.597,-9.29907 7.843,-1.05361 20.1041,-3.77898 32.097,-4.79957 5.7862,-0.49243 11.3081,-0.53657 16.4985,0.29999 0.048,-0.37868 0.261,-0.83522 0.2994,-1.19991 0.5044,-4.62142 0.3005,-8.09921 0.3005,-8.09921 l 34.1968,-59.69438 z m -8.6991,14.69864 c -4.3838,2.4582 -7.1019,6.99959 -3.8997,11.69887 2.631,-0.41669 3.1785,-3.76633 0,-3.59966 1.4791,-1.87195 0,-4.22926 2.0998,-5.69946 1.2679,-0.88982 3.6689,-0.20029 1.7999,-2.39975 z m -14.6986,15.29853 c 1.1968,-0.62576 1.5042,-0.37032 -0.8995,2.09979 -0.8773,0.49186 -1.6983,1.11039 -2.6997,1.49987 -2.5356,0.99105 -6.2994,3.05843 -6.2994,6.29941 -0.7756,0.0354 -1.6623,-0.25208 -2.3998,-0.89991 2.8184,-2.25589 5.7052,-4.56967 8.6992,-6.59938 0.4713,-0.32138 2.4028,-1.77405 3.5996,-2.39978 z" />
<animate attributeType="XML" attributeName="x" from="600" to="1000"
dur="10s" repeatCount="indefinite" />
</g>
</svg>
Any help or pointers is greatly appreciated. Thanks
Path elements don't have an x attribute. You can do the same thing with a transform animation though.
Additionally an animate element must either be the child of the path or point to the path vi the path's id. Last I checked Chrome's accessing of elements with id values containing a - sign from SMIL was buggy so given that's what you have as an id I've made the animateTransform a child of your path.
Note that SMIL can't do random on its own, you could create something that looks like a random walk but it's going to be the same each time basically. You could create random SMIL animations via javascript.
<svg xmlns:svg="http://www.w3.org/2000/svg" viewBox="500 180 2500 1500">
<g>
<path id="US-WA" d="m 1204.9427,925.58655 c -1.3898,1.54162 -3.5681,6.4786 -0.2995,5.99944 -2.5653,2.58922 -3.3814,8.57974 -8.3992,5.99945 -1.6219,3.81537 1.3975,1.05569 2.0998,3.29967 0.4051,1.29541 -0.1592,2.49675 -0.5999,3.59966 -0.574,1.43862 -1.0531,2.67841 -0.5999,4.19962 0.9522,3.19931 -7.9766,5.68493 -8.3992,9.89904 -0.3437,3.41803 -2.4129,5.35128 -4.7996,6.89936 -1.6428,1.06557 -3.5355,1.94896 -5.0995,2.99971 -1.0386,0.69641 -3.9323,3.80031 -5.3995,2.99974 -2.3214,-1.26485 -4.2692,-0.25119 -5.0995,2.09979 1.0922,-2.53862 0.4348,-2.72427 -1.7999,-0.89992 2.8988,-1.68447 2.8988,-2.18139 0,-1.49986 3.4375,-0.54169 5.4851,-4.00727 8.6992,-5.09951 -1.4791,0.92554 -2.2605,2.696 -2.0998,4.49958 1.1896,-1.31713 2.6821,-2.51823 4.1996,-3.59966 3.3001,-1.51067 7.1003,-7.47473 3.2997,-5.39949 1.1845,-3.59217 9.6433,-5.94207 8.3992,-9.29912 -0.7286,0.44537 -1.4265,0.73373 -2.0998,1.19988 0.5808,-0.54475 1.0436,-1.2686 1.1999,-1.79983 0.5241,-1.76484 -0.3734,-3.74478 0.6,-5.3995 -1.6785,0.33627 -2.8771,1.62713 -3.2997,3.2997 -0.03,-3.66061 -9.5411,-2.9717 -13.1988,-3.59966 -6.0712,-1.04164 -10.1546,-4.19955 -15.8985,-5.69945 -3.6011,-0.94045 -7.7344,10.52732 -7.4993,14.09865 0.4944,7.49384 -4.7149,14.61007 -6.8993,21.59794 0.5058,-0.7678 1.1629,-1.73608 1.7998,-2.39975 1.0981,1.3452 2.7199,2.51886 4.4996,2.39975 -3.8928,1.13991 -8.3028,1.07697 -8.9992,5.99945 1.7737,-0.30948 3.4305,0.0307 4.7996,1.19988 -4.3035,-1.98209 -5.6594,6.11962 -9.2991,6.89936 0.7055,-1.47317 1.2194,-2.97283 1.7998,-4.49958 -0.289,0.51433 -1.36,2.46258 -2.0998,4.19962 -0.9513,2.23333 -1.3747,4.25619 0.8994,3.89962 2.6815,-0.41969 3.9566,-1.05119 6.5994,0.29996 0.1604,0.0815 0.4166,0.19315 0.5999,0.29997 0.8697,0.50617 1.9523,1.19458 2.9997,1.49987 0.5194,-0.12589 1.4274,0.31936 1.7999,0 -0.3763,0.16368 -0.7881,0.34662 -1.1999,0.29996 3.0295,3.11021 2.4204,6.05171 1.7998,8.39921 -0.621,2.3475 -1.3217,4.091 1.1999,5.3995 2.5216,1.3085 5.1278,-0.2432 8.0992,-2.3998 2.9714,-2.1566 6.495,-4.746 10.4991,-5.0995 8.0082,-0.7071 17.5494,6.3653 27.5974,5.9994 10.0479,-0.3658 14.9111,-7.1919 30.597,-9.29907 7.843,-1.05361 20.1041,-3.77898 32.097,-4.79957 5.7862,-0.49243 11.3081,-0.53657 16.4985,0.29999 0.048,-0.37868 0.261,-0.83522 0.2994,-1.19991 0.5044,-4.62142 0.3005,-8.09921 0.3005,-8.09921 l 34.1968,-59.69438 z m -8.6991,14.69864 c -4.3838,2.4582 -7.1019,6.99959 -3.8997,11.69887 2.631,-0.41669 3.1785,-3.76633 0,-3.59966 1.4791,-1.87195 0,-4.22926 2.0998,-5.69946 1.2679,-0.88982 3.6689,-0.20029 1.7999,-2.39975 z m -14.6986,15.29853 c 1.1968,-0.62576 1.5042,-0.37032 -0.8995,2.09979 -0.8773,0.49186 -1.6983,1.11039 -2.6997,1.49987 -2.5356,0.99105 -6.2994,3.05843 -6.2994,6.29941 -0.7756,0.0354 -1.6623,-0.25208 -2.3998,-0.89991 2.8184,-2.25589 5.7052,-4.56967 8.6992,-6.59938 0.4713,-0.32138 2.4028,-1.77405 3.5996,-2.39978 z" >
<animateTransform attributeName="transform" type = "translate" from="600" to="1000"
dur="10s" repeatCount="indefinite" />
</path>
</g>
</svg>

svg path inside rectangle overflow

I have a svg rectange transformed 90° with border only and fill: none.
I have also a path that fills the above rectangle. Note tha i dont want to use fill attribute so as to make the rectangle green. i would like another path fill it like it has background.
<svg height="100%" width="100%" id="svg-rect-rotated" x="-166px" y="-190px">
<rect id="rect" x="463.923" y="258.923" transform="matrix(0.7071 0.7071 -0.7071 0.7071 346.2503 -262.9221)" fill="#00ff87" stroke="none" stroke-width="6.522" width="55.154" height="55.154"/>
<path id="path" style="fill:none;stroke:#00ff87;stroke-width:4.4164;stroke-miterlimit:10;" d="M490.156,251.632L492.702 251.632 489.39 252.51 493.805 252.818 488.627 253.301 494.823 254.004 487.608 254.355 496.182 255.234 486.76 255.058 497.2 256.376 485.911 255.937 498.176 257.387 485.062 257.036 499.173 258.54 484.118 257.948 500.054 259.573 482.961 258.948 501.169 260.43 482.134 259.902 502.059 261.384 481.497 260.627 502.823 262.208 480.829 261.353 503.651 263.033 479.779 262.439 504.67 264.12 478.823 263.396 505.751 265.24 477.805 264.449 506.802 266.262 476.882 265.438 507.82 267.383 476.054 266.262 508.584 268.239 475.354 267.086 509.476 269.063 474.399 268.008 510.302 269.953 473.699 268.7 511.13 270.776 473.031 269.393 511.884 271.534 472.331 270.084 512.564 272.326 471.695 270.788 513.199 272.896 471.057 271.446 513.878 273.643 470.507 272.062 514.474 274.258 469.869 272.677 515.025 274.786 469.276 273.379 515.746 275.533 468.638 273.95 516.34 276.191 468.044 274.565 516.977 276.807 467.578 275.093 517.614 277.509 466.983 275.708 518.377 278.257 466.263 276.411 519.099 279.047 465.668 277.026 519.651 279.619 465.159 277.553 520.16 280.102 464.606 278.125 520.797 280.717 463.971 278.784 521.391 281.376 463.292 279.531 522.028 282.035 462.613 280.102 522.663 282.65 461.89 280.893 523.299 283.397 461.254 281.595 523.936 283.968 460.615 282.21 524.531 284.649 459.981 282.936 525.422 285.637 458.962 283.857 525.989 286.164 457.881 284.781 524.977 287.22 456.989 285.836 523.958 288.274 457.434 286.626 523.003 289.196 458.325 287.615 522.24 290.053 458.922 288.295 521.604 290.668 459.557 288.867 520.966 291.371 460.194 289.613 520.244 292.161 460.83 290.229 519.566 292.733 461.465 290.888 518.886 293.479 462.06 291.546 518.25 294.139 462.696 292.161 517.699 294.71 463.206 292.645 517.19 295.238 463.757 293.216 516.594 295.852 464.479 294.006 515.873 296.555 465.242 294.754 515.28 297.17 465.879 295.456 514.812 297.698 466.515 296.072 514.218 298.313 467.11 296.73 513.581 298.884 467.832 297.478 512.989 299.587 468.384 298.005 512.35 300.201 468.976 298.62 511.798 300.817 469.656 299.367 511.162 301.477 470.293 299.938 510.527 302.179 470.973 300.729 509.825 302.871 471.726 301.487 509.157 303.563 472.552 302.311 508.457 304.254 473.381 303.2 507.502 305.178 474.272 304.024 506.802 306.001 475.036 304.881 505.974 306.826 476.054 306.001 505.051 307.814 477.105 307.023 504.032 308.868 478.187 308.143 503.077 309.824 479.206 309.23 502.027 310.911 480.033 310.055 501.359 311.636 480.797 310.878 500.722 312.361 481.688 311.834 499.926 313.218 482.802 312.69 498.739 314.316 483.683 313.724 497.795 315.228 484.68 314.877 496.945 316.326 485.656 315.887 496.096 317.206 486.675 317.029 495.247 317.908 488.033 318.259 494.229 318.962 489.052 319.445 493.466 319.752 490.155 320.632 492.701 320.632 " />
</svg>
if you see the jsfiddle my path overflow the rectangle. is there any way to prevent this from happening using css? or i have to create tha path again?
Either use CSS transform or SVG presentation attributes to scale/rotate/translate to adjust your elements.
I removed the matrix transformation from the rect and instead placed both rect and path inside a g element which gets a rotation transform. then the path itself gets scaled down and translated inside the rect. i think this covers what you were going for. play around some more with the code to get it where you want...
<svg viewBox="0 0 650 650">
<g id="g" transform="rotate(30)">
<rect id="rect" x="463.923" y="258.923" fill="none" stroke="#00ff87" stroke-width="6.522" width="55.154" height="55.154"></rect>
<path transform="scale(.8) translate(125,70)" id="path" style="fill:none;stroke:#00ff87;stroke-width:4.4164;stroke-miterlimit:10;" d="M490.156,251.632L492.702 251.632 489.39 252.51 493.805 252.818 488.627 253.301 494.823 254.004 487.608 254.355 496.182 255.234 486.76 255.058 497.2 256.376 485.911 255.937 498.176 257.387 485.062 257.036 499.173 258.54 484.118 257.948 500.054 259.573 482.961 258.948 501.169 260.43 482.134 259.902 502.059 261.384 481.497 260.627 502.823 262.208 480.829 261.353 503.651 263.033 479.779 262.439 504.67 264.12 478.823 263.396 505.751 265.24 477.805 264.449 506.802 266.262 476.882 265.438 507.82 267.383 476.054 266.262 508.584 268.239 475.354 267.086 509.476 269.063 474.399 268.008 510.302 269.953 473.699 268.7 511.13 270.776 473.031 269.393 511.884 271.534 472.331 270.084 512.564 272.326 471.695 270.788 513.199 272.896 471.057 271.446 513.878 273.643 470.507 272.062 514.474 274.258 469.869 272.677 515.025 274.786 469.276 273.379 515.746 275.533 468.638 273.95 516.34 276.191 468.044 274.565 516.977 276.807 467.578 275.093 517.614 277.509 466.983 275.708 518.377 278.257 466.263 276.411 519.099 279.047 465.668 277.026 519.651 279.619 465.159 277.553 520.16 280.102 464.606 278.125 520.797 280.717 463.971 278.784 521.391 281.376 463.292 279.531 522.028 282.035 462.613 280.102 522.663 282.65 461.89 280.893 523.299 283.397 461.254 281.595 523.936 283.968 460.615 282.21 524.531 284.649 459.981 282.936 525.422 285.637 458.962 283.857 525.989 286.164 457.881 284.781 524.977 287.22 456.989 285.836 523.958 288.274 457.434 286.626 523.003 289.196 458.325 287.615 522.24 290.053 458.922 288.295 521.604 290.668 459.557 288.867 520.966 291.371 460.194 289.613 520.244 292.161 460.83 290.229 519.566 292.733 461.465 290.888 518.886 293.479 462.06 291.546 518.25 294.139 462.696 292.161 517.699 294.71 463.206 292.645 517.19 295.238 463.757 293.216 516.594 295.852 464.479 294.006 515.873 296.555 465.242 294.754 515.28 297.17 465.879 295.456 514.812 297.698 466.515 296.072 514.218 298.313 467.11 296.73 513.581 298.884 467.832 297.478 512.989 299.587 468.384 298.005 512.35 300.201 468.976 298.62 511.798 300.817 469.656 299.367 511.162 301.477 470.293 299.938 510.527 302.179 470.973 300.729 509.825 302.871 471.726 301.487 509.157 303.563 472.552 302.311 508.457 304.254 473.381 303.2 507.502 305.178 474.272 304.024 506.802 306.001 475.036 304.881 505.974 306.826 476.054 306.001 505.051 307.814 477.105 307.023 504.032 308.868 478.187 308.143 503.077 309.824 479.206 309.23 502.027 310.911 480.033 310.055 501.359 311.636 480.797 310.878 500.722 312.361 481.688 311.834 499.926 313.218 482.802 312.69 498.739 314.316 483.683 313.724 497.795 315.228 484.68 314.877 496.945 316.326 485.656 315.887 496.096 317.206 486.675 317.029 495.247 317.908 488.033 318.259 494.229 318.962 489.052 319.445 493.466 319.752 490.155 320.632 492.701 320.632 " style="-webkit-transition: stroke-dashoffset 1s ease-in-out; transition: stroke-dashoffset 1s ease-in-out; stroke-dasharray: 988.003967285156px, 988.003967285156px; stroke-dashoffset: 0px;" />
</g>
</svg>
Hope this helps!

Trouble Drawing SVG Bezier Curve with jsPDF

I have a Bezier curve defined in SVG that I'd like to draw using jsPDF. I haven't been able to get the curve to render correctly using jsPDF. How do I draw the Bezier curve defined in the SVG below using jsPDF?
The curve in SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="192" version="1.1" height="288">
<path fill="black" stroke="black" d="M19.0544,25.8288C24.2384,43.2816,22.3952,46.9968,18.7376,50.510400000000004" stroke-width="0" font=" 10pt Arial"></path>
</svg>
My attempt at the curve using jsPDF:
var doc = new jsPDF();
doc.lines([[24.2384, 43.2816, 22.3952, 46.9968, 18.7376, 50.5104]], null, null, [1, 1], 'FD');
What the SVG produces when rendered (left) and what my jsPDF code produces (right):
I don't see the initial move reflected in your code. According to my reading of the documentation, shouldn't this be something more like the following?
var doc = new jsPDF();
doc.lines([[24.2384, 43.2816, 22.3952, 46.9968, 18.7376, 50.5104]], 19.0544,25.8288, [1, 1]);
Update
Didn't notice the docs say coords are relative (thanks Pomax), so try this.
var doc = new jsPDF();
var x = 19.0544;
var y = 25.8288;
doc.lines([[24.2384-x, 43.2816-y, 22.3952-x, 46.9968-y, 18.7376-x, 50.5104-y]], x,y, [1, 1]);

Using SVG, is it possible to add text to the centre of a path and align it horizontally?

I want to add text to the centre of a path and align it horizontally, NOT align along the path.
I have the following text running along the path at the centre, but I want to display it so that it is horizontal, no matter what angle the path is heading.
<text text-anchor="middle">
<textPath xlink:href="#SomePath" startOffset="50%">Some Text</textPath>
</text>
If I understand correctly you are after each individual letter being straight (i.e. pointing North) but following the path. Something like this:
Looking at the current SVG standard this does not seem to be possible.
For horizontal text layout flows, the
reference orientation for a given
glyph is the vector that starts at the
intersection point on the path to
which the glyph is attached and which
points in the direction 90 degrees
counter-clockwise from the angle of
the curve at the intersection point.
The image above is generated from SVG but this was achieved (as you can see from the imperfections) by applying individual kerning (rotation) to each letter by applying the rotate attribute:
<text id="text2897">
<textPath xlink:href="#path2890" id="textPath3304">
<tspan
rotate="69.238731 53.737518 40.30315 24.801943 358.96658 358.96658 4.1336575 357.93317 351.73267 351.73267 351.73267 348.63242 343.46533 343.46533 346.56558 347.599 347.599 347.599 347.599 347.599 347.599 346.56558 345.53217 344.49875 343.46533"
id="tspan2899">
Some sample text for path
</tspan>
</textPath>
</text>
You can calculate the necessary adjustments in rotation in script quite easily:
var tp = document.getElementById("textpath");
var rotate = "";
for(var i = 0; i < tp.getNumberOfChars(); i++)
{
rotate += -tp.getRotationOfChar(i) + " ";
}
tp.setAttribute("rotate", rotate);

Resources