1 pv.SvgScene.label = function(scenes) { 2 var g = this.group(scenes); 3 for (var i = 0; i < scenes.length; i++) { 4 var s = scenes[i]; 5 6 /* visible */ 7 if (!s.visible) continue; 8 var fill = pv.color(s.textStyle); 9 if (!fill.opacity) continue; 10 11 /* text-baseline, text-align */ 12 var x = 0, y = 0, dy = 0, anchor = "start"; 13 switch (s.textBaseline) { 14 case "middle": dy = ".35em"; break; 15 case "top": dy = ".71em"; y = s.textMargin; break; 16 case "bottom": y = "-" + s.textMargin; break; 17 } 18 switch (s.textAlign) { 19 case "right": anchor = "end"; x = "-" + s.textMargin; break; 20 case "center": anchor = "middle"; break; 21 case "left": x = s.textMargin; break; 22 } 23 24 var text = this.cache(s, "text", "text"); 25 text.setAttribute("pointer-events", "none"); 26 text.setAttribute("x", x); 27 text.setAttribute("y", y); 28 text.setAttribute("dy", dy); 29 text.setAttribute("text-anchor", anchor); 30 text.setAttribute("transform", 31 "translate(" + s.left + "," + s.top + ")" 32 + (s.textAngle ? " rotate(" + 180 * s.textAngle / Math.PI + ")" : "")); 33 text.setAttribute("fill", fill.color); 34 text.setAttribute("fill-opacity", fill.opacity); 35 text.style.font = s.font; 36 text.style.textShadow = s.textShadow; 37 text.appendChild(document.createTextNode(s.text)); 38 g.appendChild(text); 39 } 40 }; 41