@domoinc/multiline-chart
Version:
MultiLineChart - Domo Widget
31 lines (28 loc) • 1.24 kB
JavaScript
//**********************************************************************************
// This function will right-align a text element, based on its current position and content
// This is especially useful in aligning text elements created in Illustrator
//**********************************************************************************
d3.rightAlignText = function(textElem) {
var bounds = textElem.node()
.getBBox();
textElem.attr('text-anchor', 'end')
.attr('transform', function() {
return d3.select(this)
.attr('transform') + 'translate(' + (bounds.width) + ',0)';
});
return textElem;
}
//**********************************************************************************
// This function will center-align a text element, based on its current position and content
// This is especially useful in aligning text elements created in Illustrator
//**********************************************************************************
d3.centerAlignText = function(textElem) {
textElem.attr("text-anchor", "middle")
.attr("transform", function() {
var bounds = textElem.node()
.getBBox();
return d3.select(this)
.attr("transform") + "translate(" + ((bounds.width / 2)) + ",0)";
});
return textElem;
}