Skip to content

Commit

Permalink
Allow % values to be used for positions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkiernander committed Sep 4, 2013
1 parent 8e629a5 commit bc6abe6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/methods/_parsePosition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright: 2013 PMSI-AlignAlytics
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
// Source: /src/methods/_parsePosition.js
dimple._parsePosition = function (value, svgScaleValue) {
var returnValue = value;
if (!isNaN(value)) {
returnValue = value;
} else if (value.slice(-1) === "%") {
returnValue = svgScaleValue * (parseFloat(value.slice(0, value.length - 1)) / 100);
} else if (value.slice(-2) === "px") {
returnValue = parseFloat(value.slice(0, value.length - 2));
}
return returnValue;
};
8 changes: 4 additions & 4 deletions src/objects/chart/begin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-svg
this.svg = svg;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-x
this.x = svg[0][0].width.baseVal.value * 0.1;
this.x = svg.node().offsetWidth * 0.1;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-y
this.y = svg[0][0].height.baseVal.value * 0.1;
this.y = svg.node().offsetHeight * 0.1;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-width
this.width = svg[0][0].width.baseVal.value * 0.8;
this.width = svg.node().offsetWidth * 0.8;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-height
this.height = svg[0][0].height.baseVal.value * 0.8;
this.height = svg.node().offsetHeight * 0.8;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-data
this.data = data;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#wiki-noFormats
Expand Down
8 changes: 4 additions & 4 deletions src/objects/legend/begin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-series
this.series = series;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-x
this.x = x;
this.x = dimple._parsePosition(x, this.chart.svg.node().offsetWidth);
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-y
this.y = y;
this.y = dimple._parsePosition(y, this.chart.svg.node().offsetHeight);
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-width
this.width = width;
this.width = dimple._parsePosition(width, this.chart.svg.node().offsetWidth);
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-height
this.height = height;
this.height = dimple._parsePosition(height, this.chart.svg.node().offsetHeight);
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-horizontalAlign
this.horizontalAlign = horizontalAlign;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.legend#wiki-shapes
Expand Down

0 comments on commit bc6abe6

Please sign in to comment.