javascript - Align svg text inline with d3.js legend -


i'm trying use susie lu's legend plugin.

here plnk of work far;

http://plnkr.co/edit/wrowpyu4paqwr8f5oojw?p=preview

image below achieve (just layout, content/colour doesn't matter)

enter image description here

i've tried standard float:left + display: inline on classes attached text/rectangles didn't work me. maybe making mistake. i'm not sure if should doing inside d3 script or in css file anyway?

hope simple fix - appreciated!

thanks

those attributes (float:left + display: inline) work on html elements, legend library here produces svg

it's possible, needs little bit of work

http://plnkr.co/edit/yrfrwetmfdmje06mg5ky?p=preview

 var cells= d3.selectall(".cell");    var cellgap = legendlinear.shapewidth()+(legendlinear.shapepadding()/4);     cells.select("text")       .attr ("transform", "translate("+cellgap+" 13)")       .style ("text-anchor", "start")    ;      var offset = 0;    cells.each (function(d,i) {       var d3sel = d3.select(this);       var textwidth = d3sel.select("text").node().getcomputedtextlength();       var offsetinc = textwidth + legendlinear.shapewidth() + legendlinear.shapepadding();       d3sel.attr("transform", "translate("+offset+" 0)");       offset += offsetinc;    }); 

this firstly moves text element each legend 'cell' right of colour swatch rather below.

then moves g elements hold label , swatch horizontally apart dependent on width of label (and swatch , declared padding) using .getcomputedtextlength() , running total offset.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -