vertical alignment of text element in SVG

According to SVG spec, alignment-baseline only applies to <tspan>, <textPath>, <tref> and <altGlyph>. My understanding is that it is used to offset those from the <text> object above them. I think what you are looking for is dominant-baseline. Possible values of dominant-baseline are: auto | use-script | no-change | reset-size | ideographic | alphabetic | … Read more

Scale and mirror SVG object

To apply both scale and flip, just list both in your transform: transform=”scale(2,2) scale(-1,1)” Or simply combine the values: transform=”scale(-2,2)” Of course, the issue you have with negative scales is that the objects get flipped across the origin (top left) of the SVG, so they can go off the edge of the document. You need … Read more

How to convert/save d3.js graph to pdf/jpeg

To display your svg within a canvas, you first have to convert it using a parser/renderer utility such as http://code.google.com/p/canvg/ (code adapted from: Convert SVG to image (JPEG, PNG, etc.) in the browser, not tested) // the canvg call that takes the svg xml and converts it to a canvas canvg(‘canvas’, $(“#my-svg”).html()); // the canvas … Read more

Default background color of SVG root element

SVG 1.2 Tiny has viewport-fill I’m not sure how widely implemented this property is though as most browsers are targetting SVG 1.1 at this time. Opera implements it FWIW. A more cross-browser solution currently would be to stick a <rect> element with width and height of 100% and fill=”red” as the first child of the … Read more

Find svg viewbox that trim whitespace around

You can simply set your svg’s viewBox to its Bounding Box. function setViewbox(svg) { var bB = svg.getBBox(); svg.setAttribute(‘viewBox’, bB.x + ‘,’ + bB.y + ‘,’ + bB.width + ‘,’ + bB.height); } document.querySelector(‘button’).addEventListener(‘click’, function() { setViewbox(document.querySelector(‘svg’)); }); svg { border: 1px solid } <svg version=”1.1″ id=”svg” xmlns=”http://www.w3.org/2000/svg” xmlns:xlink=”http://www.w3.org/1999/xlink” x=”0px” y=”0px” viewBox=”0 0 500 300″ … Read more