Skip to content

Commit

Permalink
Use HTML DOM style Property instead of adding inline styles to elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Silva committed Apr 5, 2017
1 parent 2cede5f commit 3857a19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/scripts/charts/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@

// If this is a donut, we add the stroke-width as style attribute
if(options.donut && !options.donutSolid) {
pathElement.attr({
'style': 'stroke-width: ' + donutWidth.value + 'px'
});
pathElement._node.style.strokeWidth = donutWidth.value + 'px';
}

// Fire off draw event
Expand Down
18 changes: 10 additions & 8 deletions src/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ var Chartist = {
svg = new Chartist.Svg('svg').attr({
width: width,
height: height
}).addClass(className).attr({
style: 'width: ' + width + '; height: ' + height + ';'
});
}).addClass(className);

svg._node.style.width = width;
svg._node.style.height = height;

// Add the DOM node to our container
container.appendChild(svg._node);
Expand Down Expand Up @@ -971,11 +972,12 @@ var Chartist = {
if(useForeignObject) {
// We need to set width and height explicitly to px as span will not expand with width and height being
// 100% in all browsers
var content = '<span class="' + classes.join(' ') +
'" xmlns="' + Chartist.namespaces.xhtml + '" style="' +
axis.units.len + ': ' + Math.round(positionalData[axis.units.len]) + 'px; ' +
axis.counterUnits.len + ': ' + Math.round(positionalData[axis.counterUnits.len]) + 'px">' +
labels[index] + '</span>';
var content = document.createElement('span');
content.className = classes.join(' ');
content.setAttribute('xmlns', Chartist.namespaces.xhtml);
content.innerText = labels[index];
content.style[axis.units.len] = Math.round(positionalData[axis.units.len]) + 'px';
content.style[axis.counterUnits.len] = Math.round(positionalData[axis.counterUnits.len]) + 'px';

labelElement = group.foreignObject(content, Chartist.extend({
style: 'overflow: visible;'
Expand Down

0 comments on commit 3857a19

Please sign in to comment.