1
0
Fork 0
empact/app/scripts/src/charts/charts.jsx

37 lines
957 B
React
Raw Normal View History

2015-03-13 12:08:13 +00:00
var SVGChartMixin = {
calculateViewBoxWidth: function() {
this.setState({
canvasWidth: this.refs.svg.getDOMNode().offsetWidth
});
}
};
var fontFamily = 'Helvetica Neue, Helvetica, sans-serif',
fontSize = 16;
2015-03-14 08:53:53 +00:00
function numberFormat(num) {
// FIXME: Not supported in IE10- and Safari
return Intl.NumberFormat().format(num);
}
2015-03-13 12:08:13 +00:00
function textWidth(str) {
var svg = document.createElementNS('http://www.w3.org/2000/svg', "svg");
text = document.createElementNS('http://www.w3.org/2000/svg', "text");
svg.width = 500;
svg.height = 500;
svg.style.position = 'absolute';
svg.style.left = '-1000px';
text.appendChild(document.createTextNode(str))
text.style.fontFamily = fontFamily;
text.style.fontSize = fontSize +'px';
svg.appendChild(text);
document.body.appendChild(svg);
var box = text.getBBox();
document.body.removeChild(svg);
return box.width;
}