Skip to content

Commit dde9f9c

Browse files
author
Robert Paskowitz
committed
Adds a property, autoRotateLabel, and parameter to the axis constructor, which allows disabling the auto-rotation of axis labels.
This is done to allow manual rotation to arbitrary angles without having to worry about if the label may be auto rotated by dimple. Default behavior is to maintain backwards compatibility and continue rotating.
1 parent 990dce0 commit dde9f9c

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/objects/axis/begin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
33
// Source: /src/objects/axis/begin.js
44
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis
5-
dimple.axis = function (chart, position, categoryFields, measure, timeField) {
5+
dimple.axis = function (chart, position, categoryFields, measure, timeField, autoRotateLabel) {
66

77
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-chart
88
this.chart = chart;
@@ -56,6 +56,8 @@
5656
this.fontSize = "10px";
5757
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-fontFamily
5858
this.fontFamily = "sans-serif";
59+
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-autoRotateLabel
60+
this.autoRotateLabel = (autoRotateLabel === null || autoRotateLabel === undefined ? true : autoRotateLabel);
5961

6062
// If this is a composite axis, store links to all slaves
6163
this._slaves = [];

src/objects/chart/methods/draw.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
});
284284
}
285285
// Rotate labels, this can only be done once the formats are set
286-
if (axis.measure === null || axis.measure === undefined) {
286+
if (axis.autoRotateLabel && (axis.measure === null || axis.measure === undefined)) {
287287
if (axis === firstX) {
288288
// If the gaps are narrower than the widest label display all labels horizontally
289289
widest = 0;
@@ -332,6 +332,11 @@
332332
.attr("transform", "");
333333
}
334334
}
335+
} else {
336+
rotated = false;
337+
axis.shapes.selectAll("text")
338+
.style("text-anchor", "middle")
339+
.attr("transform", "");
335340
}
336341
if (axis.titleShape !== null && axis.titleShape !== undefined) {
337342
axis.titleShape.remove();

0 commit comments

Comments
 (0)