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
angles option for polar chart #6472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,15 +131,17 @@ module.exports = DatasetController.extend({ | |
var starts = me._starts = []; | ||
var angles = me._angles = []; | ||
var arcs = meta.data; | ||
var i, ilen, angle; | ||
var i, ilen, angle, convertedAngles; | ||
var optionsAngles = me.chart.options.angles || []; | ||
|
||
me._updateRadius(); | ||
|
||
meta.count = me.countVisibleElements(); | ||
convertedAngles = me._convertAngles(optionsAngles); | ||
|
||
for (i = 0, ilen = dataset.data.length; i < ilen; i++) { | ||
starts[i] = start; | ||
angle = me._computeAngle(i); | ||
angle = me._computeAngle(i, convertedAngles[i]); | ||
angles[i] = angle; | ||
start += angle; | ||
} | ||
|
@@ -251,15 +253,9 @@ module.exports = DatasetController.extend({ | |
/** | ||
* @private | ||
*/ | ||
_computeAngle: function(index) { | ||
_computeAngle: function(index, angle) { | ||
var me = this; | ||
var count = this.getMeta().count; | ||
var dataset = me.getDataset(); | ||
var meta = me.getMeta(); | ||
|
||
if (isNaN(dataset.data[index]) || meta.data[index].hidden) { | ||
return 0; | ||
} | ||
|
||
// Scriptable options | ||
var context = { | ||
|
@@ -271,7 +267,46 @@ module.exports = DatasetController.extend({ | |
|
||
return resolve([ | ||
me.chart.options.elements.arc.angle, | ||
(2 * Math.PI) / count | ||
angle | ||
], context, index); | ||
}, | ||
|
||
/** | ||
* if no angles options, circumference = 2*PI and each arc will be (2*PI)/arcCount | ||
* if angles options, circumference = sum(angles) | ||
* if angles.length < arcCount => undefined angles will be set to (2*PI)/arcCount, | ||
* defined angles will be recompute to fill circumference-sum(undefinedAngles) stay proportional to original values | ||
* if angles.length > arcCount => circumference remains the same and existing angles will be recompute to stay proportional to original values | ||
* @private | ||
*/ | ||
_convertAngles: function(angles) { | ||
var me = this; | ||
var dataset = me.getDataset(); | ||
var meta = me.getMeta(); | ||
var angle, ratio; | ||
var initialCircumference = 0; | ||
var convertedAngles = []; | ||
var circumference = angles.length ? angles.reduce(function(a, b) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the sum of the angles is > 2*pi? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return a + b; | ||
}) : Math.PI * 2; | ||
var defaultAngle = circumference / dataset.data.length; | ||
|
||
meta.data.forEach(function(element, index) { | ||
if (isNaN(dataset.data[index]) || element.hidden) { | ||
angle = 0; | ||
} else if (index >= angles.length) { | ||
angle = defaultAngle; | ||
} else { | ||
angle = angles[index]; | ||
} | ||
initialCircumference += angle; | ||
convertedAngles.push(angle); | ||
}); | ||
ratio = circumference / initialCircumference; | ||
|
||
return convertedAngles.map(function(item) { | ||
return item * ratio; | ||
}); | ||
} | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
serie
is a word. It also doesn't match the usual terminology. We have datasets which contain data pointsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups sorry, you're right, this is actualy the French word.
I suggest to put
[]
as default value and explain the behavior more in details in the description column with the following :polar circumference = 2 * PI
and each arc will be(2 * PI) / (visible datasets count)
.polar circumference = sum(options.angles)
.options.angles.length < (visible datasets count)
(2 * PI) / (visible datasets count)
.(polar circumference) - sum(undefined angles)
).options.angles.length > (visite datasets count)
What do you think ?