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

Remove schemeCategory20c #1409

Closed
wants to merge 4 commits into from
Closed

Remove schemeCategory20c #1409

wants to merge 4 commits into from

Conversation

kum-deepak
Copy link
Collaborator

This PR contains following:

  • Concept of dc.config, which will be a single instance object. It currently holds one setting and one variable. Please see if you are ok with the concept.
  • For backward compatibility, following needs to be added before creating charts:
    dc.config.useV2CompatColorScheme(true);
  • Concept of standard colors in specs. This will help us in minimizing breakage when making global changes in color palette.
  • A special matcher for color which covers more cases than a reg ex.
  • Enabled back index.html generation in specs folder, this allows to run test cases interactively by going to http://localhost:8888/spec/ - useful for interactive debugging.

Charts work but they do look different :)

@kum-deepak
Copy link
Collaborator Author

If you like the concept of dc.config, it can be used for more things. One immediate usage may be to keep the default ordinal colors (which currently lie in color mixin).

Copy link
Contributor

@gordonwoodhull gordonwoodhull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really clean implementation, and overall this helps clarify a lot of things.

I'll be interested to hear if you think it should be defaulted to the new colors, or if that was a miscommunication. Open to any ideas here.

The other big question is if we should offer a permanent way to set the default colors - might be helpful.

The config object and the matcher are great infrastructure improvements.

'#e41a1c', '#377eb8', '#4daf4a',
'#984ea3', '#ff7f00', '#ffff33',
'#a65628', '#f781bf', '#999999'
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy d3.schemeSet1 here? It's not going to change in d3 and if it did, it would still break all our tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I like the idea of defaultColors in config, once we move there, we can use that to match, this variable would not be needed at all.

src/config.js Outdated
dc.config = (function () {
var _config = {};

var _useV2CompatColorScheme = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should default to true and issue the warning. This way people get backward compatibility by default, to ease their transition into the new world, but they are also informed that it's going away.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

src/config.js Outdated

/**
* Set this flag to use DCv2's color scheme (d3.schemeCategory20c).
* Please note this color scheme has been deprecated by D3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been removed in d3v5.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will change!

src/config.js Outdated
* Set this flag to use DCv2's color scheme (d3.schemeCategory20c).
* Please note this color scheme has been deprecated by D3
* (https://github.com/d3/d3/blob/master/CHANGES.md#changes-in-d3-50) as well as DC.
* @method useV2CompatColorScheme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an example of what you should do if you want to keep the old colors and not get the warning. Namely, you'd copy _schemeCategory20c and apply it to each chart.

Alternately, since we are adding a level of indirection here, we could rename compatColors to defaultColors and make it settable and permanent, so that users could automatically have the same color set for all charts. That might be a good idea if it turns out that schemeSet1 was the wrong choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we allow setting defaultColors, we need to add in the API docs. In addition we may create an example to show how to use their color scheme.

@@ -48,7 +50,8 @@ describe('dc.colorMixin', function () {
});

it('default', function () {
expect(colorTest(chart, domain, test)).toMatchColors(['#9ecae1','#3182bd','#c6dbef','#6baed6','#e6550d','#3182bd']);
expect(colorTest(chart, domain, test)).toMatchColors([standardColors[2], standardColors[0],
standardColors[3], standardColors[1], standardColors[4], standardColors[0]]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is really opaque - is there any way to make it clear what it proves? I can't figure it out, it's not numerical or alphabetical order is it?

(We have this problem in a lot of our tests, and it's unfortunate because it means people will "fix the tests" instead of understanding why they failed.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have realized what it does, I will refactor it is a way that it does not seem so opaque :)

expect(colorTest(chart, domain)).toMatchColors(['#3182bd','#6baed6','#9ecae1','#c6dbef','#e6550d']);
expect(colorTest(chart, domain))
.toMatchColors([standardColors[0], standardColors[1],
standardColors[2], standardColors[3], standardColors[4]]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardColors.slice(0, 5)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

@kum-deepak
Copy link
Collaborator Author

I will make one more iteration and then we can have one more round of discussion. I want to get it right :)

@kum-deepak
Copy link
Collaborator Author

Moved to concept of dc.config.defaultColors. Refactored few test cases for readability and resilience. Added additional notes for opaque-ish test cases.

If we are happy with the approach, I will add the warning message.

For one time warning messages, I want to create one helper method in dc.logger, which will ensure one message is shown only once.

@gordonwoodhull
Copy link
Contributor

Huh, until now I thought we need the flag as well as defaultColors.

We do need to warn when defaultColors is not set, but maybe it's sufficient to test that it is not _schemeCategory20c - is that what you are thinking?

@kum-deepak
Copy link
Collaborator Author

Yes, that indeed was my thinking - this led me to the need of warnOnce (in dc.logger). Simplifies the code :)

@kum-deepak
Copy link
Collaborator Author

Took a stab at adding to Change log as well. :) English is my 3rd language, so you will need to review these text as well.

@gordonwoodhull
Copy link
Contributor

Sure, I don't mind doing copy editing. It's really helpful if you put something there so it doesn't get lost.

@kum-deepak
Copy link
Collaborator Author

Completed my current round of work on this one.

@gordonwoodhull
Copy link
Contributor

Merged in 3.0 alpha 10

@kum-deepak kum-deepak deleted the color-palette branch April 28, 2018 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants