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

[Refactor] Extend color scheme management to sequential schemes #6150

Merged
merged 25 commits into from
Oct 22, 2018

Conversation

kristw
Copy link
Contributor

@kristw kristw commented Oct 19, 2018

Motivation

Centralize color management for ease of maintenance and customization. Also good for future migration to an independent npm package in superset-ui-core.

  • Color scheme metadata are scattered. The human-readable labels are defined in controls.jsx. The colors are in separate file.
  • Categorical color management has been improved in Improve categorical color management #5815 , but sequential color scheme remains a single giant file with no easy way to add/remove schemes.

Changes

  • Create data structure ColorScheme and children CategoricalScheme and SequentialScheme to hold colors array, and its metadata (name, label, description, isDiverging) in one place. Convert the arrays of colors in colorSchemes directory and sequential.js to use these new data structures.

  • Leverage Registry class that was introduced with the chart plugin system. ColorSchemeManager is renamed to ColorSchemeRegistry and extends from Registry.

  • Add new function getMap, getMapAsPromise, values(), valuesAsPromise() and clear to Registry with new unit tests.

  • Create two children singleton classes CategoricalSchemeManager and SequentialSchemeManager to manage categorical and sequential scheme, respectively.

  • Update usage and corresponding unit tests throughout the app.

  • Extract color setup from common.js into setupColors.js

  • Move color-related modules under src/modules/colors directory and unit tests under spec/modules/colors.

Test plan

  • New unit tests are added. Existing unit tests are updated.
  • Verify color picker controls locally that it works like before.
  • Verify visualizations locally that colors are the same as before.

@williaster @conglei @graceguo-supercat @michellethomas

@codecov-io
Copy link

codecov-io commented Oct 19, 2018

Codecov Report

Merging #6150 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6150   +/-   ##
=======================================
  Coverage   76.91%   76.91%           
=======================================
  Files          47       47           
  Lines        9362     9362           
=======================================
  Hits         7201     7201           
  Misses       2161     2161

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a71e6eb...fe17b1f. Read the comment docs.

@kristw kristw closed this Oct 19, 2018
@kristw kristw reopened this Oct 19, 2018
Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

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

lgtm with one question about variable naming in the Registry world.

@@ -25,7 +25,7 @@ import { nonEmpty } from '../../validators';
import vizTypes from '../../visTypes';

import { t } from '../../../locales';
import { getScheme } from '../../../modules/ColorSchemeManager';
import getCategoricalSchemeRegistry from '../../../modules/colors/CategoricalSchemeRegistrySingleton';
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think this (and analogous calls in other files) should be ClassCase since it's an instance and you still call .get() on it?

i.e., CategoricalSchemeRegistry.get()...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently all registries exports the getInstance function as default.

export default getInstance;

usage as

import getXXX from 'XXXSingleton';

I will have to modify the export to

export default {
  get: getInstance
};

and imports to

import { get } from 'XXXSingleton';

to make calls become XXX.get()

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, sorry I was thinking about this a litle differently. I think it makes sense as is 👍

@williaster williaster merged commit b9257b2 into apache:master Oct 22, 2018
@kristw kristw deleted the kristw-scheme branch October 23, 2018 16:45
michellethomas pushed a commit to michellethomas/panoramix that referenced this pull request Oct 24, 2018
…he#6150)

* refactor color scheme

* Update data structure

* Update color scheme files

* wip

* convert all sequential schemes

* Update how color schemes are managed. Extend it for sequential schemes

* extract color setup into separate file

* Update imports

* update imports

* Add new functions to Registry

* Update ColorSchemeManager to extends Registry and update unit tests

* Add test for Registry

* Rename ColorSchemeManager to ColorSchemeRegistry

* Fix unit tests

* Update API

* Fix imports

* Add label field

* Fix reference to colors

* update SequentialScheme contructor

* Fix controls

* rename manager to registry

* Split sequential schemes into multiple files

* update sequential color labels

* add values and valuesAsPromise()

* use .values()

(cherry picked from commit b9257b2)
bipinsoniguavus pushed a commit to ThalesGroup/incubator-superset that referenced this pull request Dec 26, 2018
…he#6150)

* refactor color scheme

* Update data structure

* Update color scheme files

* wip

* convert all sequential schemes

* Update how color schemes are managed. Extend it for sequential schemes

* extract color setup into separate file

* Update imports

* update imports

* Add new functions to Registry

* Update ColorSchemeManager to extends Registry and update unit tests

* Add test for Registry

* Rename ColorSchemeManager to ColorSchemeRegistry

* Fix unit tests

* Update API

* Fix imports

* Add label field

* Fix reference to colors

* update SequentialScheme contructor

* Fix controls

* rename manager to registry

* Split sequential schemes into multiple files

* update sequential color labels

* add values and valuesAsPromise()

* use .values()
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants