Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse scale on radar / polar area #1436

Merged
merged 1 commit into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion samples/polar-area.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ <h3>Legend</h3>
]
},
options: {
responsive: true
responsive: true,
scale: {
beginAtZero: true,
reverse: false
}
}
};

Expand Down
6 changes: 6 additions & 0 deletions samples/radar.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ <h3>Legend</h3>
pointHighlightStroke: "rgba(151,187,205,1)",
data: [null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
}]
},
options: {
scale: {
beginAtZero: true,
reverse: false
}
}
};

Expand Down
1 change: 1 addition & 0 deletions samples/scatter-multi-axis.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: "right",
reverse: true,
id: "y-axis-2",

// grid line settings
Expand Down
18 changes: 13 additions & 5 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},

// scale numbers
reverse: false,
beginAtZero: true,

// label settings
Expand Down Expand Up @@ -94,6 +95,8 @@

helpers.each(this.data.datasets, function(dataset) {
helpers.each(dataset.data, function(value, index) {
if (value === null) return;

if (this.min === null) {
this.min = value;
} else if (value < this.min) {
Expand Down Expand Up @@ -327,9 +330,14 @@
return index * angleMultiplier - (Math.PI / 2);
},
getDistanceFromCenterForValue: function(value) {
if (value === null) return 0; // null always in center
// Take into account half font size + the yPadding of the top value
var scalingFactor = this.drawingArea / (this.max - this.min);
return (value - this.min) * scalingFactor;
if (this.options.reverse) {
return (this.max - value) * scalingFactor;
} else {
return (value - this.min) * scalingFactor;
}
},
getPointPosition: function(index, distanceFromCenter) {
var thisAngle = this.getIndexAngle(index);
Expand All @@ -345,8 +353,8 @@
if (this.options.display) {
var ctx = this.ctx;
helpers.each(this.yLabels, function(label, index) {
// Don't draw a centre value
if (index > 0) {
// Don't draw a centre value (if it is minimum)
if (index > 0 || this.options.reverse) {
var yCenterOffset = this.getDistanceFromCenterForValue(this.ticks[index]);
var yHeight = this.yCenter - yCenterOffset;

Expand Down Expand Up @@ -405,15 +413,15 @@

for (var i = this.getValueCount() - 1; i >= 0; i--) {
if (this.options.angleLines.show) {
var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.max));
var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max));
ctx.beginPath();
ctx.moveTo(this.xCenter, this.yCenter);
ctx.lineTo(outerPosition.x, outerPosition.y);
ctx.stroke();
ctx.closePath();
}
// Extra 3px out for some label spacing
var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.max) + 5);
var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max) + 5);
ctx.font = helpers.fontString(this.options.pointLabels.fontSize, this.options.pointLabels.fontStyle, this.options.pointLabels.fontFamily);
ctx.fillStyle = this.options.pointLabels.fontColor;

Expand Down