-
Notifications
You must be signed in to change notification settings - Fork 717
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
Add color customization #71
Conversation
@gpfunk Looks great! Took us a while, can you rebase the branch? Currently switching is straightforward; it simply comes up with the best chart it can with the same data, so it doesn't imply or have provisions for a color (or any) change. It could be argued the axis and pies are color-incompatible, so would need more args to switch. Looks like the best behaviour in the current implementation would be to simply render the new chart with default colors, and the color loss be expected. |
467f4fb
to
e7df406
Compare
@pratu16x7 Just reread your message, I rebased but haven't removed the attempt to reuse the colors passed in when switching charts. Do you want me to do that first? |
@gpfunk Removing it beforehand would save a step while rebasing ;) |
src/scripts/charts/BaseChart.js
Outdated
@@ -76,7 +80,8 @@ export default class BaseChart { | |||
title: this.title, | |||
data: this.raw_chart_args.data, | |||
type: type, | |||
height: this.raw_chart_args.height | |||
height: this.raw_chart_args.height, | |||
colors: this.colors |
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.
On second thought, let's add another constraint dict besides compatible_types
; called color_compatible_types
, and only use this.colors
if it is satisfied. Will be useful for adding new charts in future.
? this.data.labels | ||
: this.data.datasets; | ||
|
||
if(!this.colors || (list && this.colors.length < list.length)) { | ||
this.colors = ['light-blue', 'blue', 'violet', 'red', 'orange', | ||
'yellow', 'green', 'light-green', 'purple', 'magenta']; | ||
} |
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.
You'll probably want to replace these with hex-codes and test stuff out again.
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 you think thats needed? They currently get mapped to the correct hex codes using the color_map field in utils/colors.js, rather than the css. I did this to allow for backwards compatibility for anyone currently using the color names, which also allowed for the hex codes to be kept in one place. Or am I misunderstanding you?
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.
Sure missed that.
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.
However, it looks like there's more calls to get_color()
than necessary. You see, currently it is called at every place where and when the color is actually set (while setting the style). But because the colors are already received beforehand in the constructor, it would be much more efficient to do the conversions there itself. That way we'd have the real colors ready for use whenever needed (without remembering to call get_color()
: There is a case in make_gradient()
below which demonstrates this, where while setting the stop-color
we seemingly forgot a get_color()
call? ;) ).
So in this light, it makes sense to store the defaults in the constructor as hex codes itself in case no colors are passed, while in case they are, going in, using get_color()
for the color for each dataset in case of axis, while doing the same for the colors array for pies.
Just made a radical decision, to pass Now it gets much easier to use |
Explanation About What Code Achieves:
Screenshots/GIFs:
Steps To Test:
TODOs: