-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Better number -> string callback for the radial linear scale #3281
Conversation
@simonbrunel I'm not sure what the best way to handle this is. Right now, the radial linear config has a copy of the exact same function as the linear scale config. It would almost be nice if we wrote this using ES6 imports because then the config could go off and live in another file and be imported in 2 places but ultimately exist only once in the build. That's probably for later though |
I'm not sure neither but it's similar to controller.doughnut.js and controler.polarArea.js. Found these ones some time ago (when trying to make Code Climate happier) and I was thinking to move it in For your case, a solution could be to move that code in
and in
Then we can add more tick generation methods, maybe :) It could be also in Just draft ideas though, not sure that the best way to solve that. |
Conflicts: src/scales/scale.radialLinear.js
@simonbrunel I moved the common stuff into |
@@ -47,7 +47,7 @@ module.exports = function(Chart) { | |||
labelOffset: 0, | |||
// We pass through arrays to be rendered as multiline labels, we convert Others to strings here. | |||
callback: function(value) { | |||
return helpers.isArray(value) ? value : '' + value; | |||
return Chart.Ticks.formatters.values(value); |
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 think we can save some bits and a function call: callback: Chart.Ticks.formatters.values
} | ||
|
||
return tickString; | ||
return Chart.Ticks.formatters.linear(tickValue, index, ticks); |
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.
Same here: callback: Chart.Ticks.formatters.linear
return value.toExponential(); | ||
} | ||
return ''; | ||
return Chart.Ticks.formatters.logarithmic(value, index, arr); |
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.
callback: Chart.Ticks.formatters.logarithmic
backdropPaddingX: 2, | ||
|
||
callback: function(tickValue, index, ticks) { | ||
return Chart.Ticks.formatters.linear(tickValue, index, ticks); |
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.
Same
It looks really great 👍 Just a few minor optimizations but I like how it helps to refactor code. Doing this for generators seems a good idea. |
Great, I'll make the changes and move the generators in as well |
I've moved the linear and logarithmic generators into |
@simonbrunel do you think we need to move any more stuff into the |
constructor: function() { | ||
// These two properties kept for backwards compatibility | ||
var me = this; | ||
Object.defineProperty(me, 'min', { |
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.
do we really need to keep these properties?
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 know that the zoom plugin uses them. I don't know if anything else does
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.
What the reason to move min
and max
into a new dataRange
object?
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.
mostly so that I was able to only pass the dataRange
to the generator rather than passing the entire scale object
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.
hum, so it could break plugins that modify min and max?
Would not it be simpler to keep min/max (no dataRange) and create the object when calling the generator:
var ticks = me.ticks = Chart.Ticks.generators.linear(numericGeneratorOptions, {
min: me.min,
max: me.max
});
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.
that would also work. I can refactor this to use that if you prefer
…#3281) Also create a new Chart.Ticks namespace to host common tick generators and formatters.
Fixes #2602
Image Before Change
Image After Change