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

Deprecate getColorFromScheme #5937

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 1 addition & 41 deletions superset/assets/spec/javascripts/modules/colors_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
import { expect } from 'chai';
import { getColorFromScheme, hexToRGB } from '../../../src/modules/colors';
import { getInstance } from '../../../src/modules/ColorSchemeManager';
import airbnb from '../../../src/modules/colorSchemes/airbnb';
import categoricalSchemes from '../../../src/modules/colorSchemes/categorical';
import { hexToRGB } from '../../../src/modules/colors';

describe('colors', () => {
before(() => {
// Register color schemes
getInstance()
.registerScheme('bnbColors', airbnb.bnbColors)
.registerMultipleSchemes(categoricalSchemes)
.setDefaultSchemeName('bnbColors');
});
it('default to bnbColors', () => {
const color1 = getColorFromScheme('CA');
expect(airbnb.bnbColors).to.include(color1);
});
it('getColorFromScheme series with same scheme should have the same color', () => {
const color1 = getColorFromScheme('CA', 'bnbColors');
const color2 = getColorFromScheme('CA', 'googleCategory20c');
const color3 = getColorFromScheme('CA', 'bnbColors');
const color4 = getColorFromScheme('NY', 'bnbColors');

expect(color1).to.equal(color3);
expect(color1).to.not.equal(color2);
expect(color1).to.not.equal(color4);
});
it('getColorFromScheme forcing colors persists through calls', () => {
expect(getColorFromScheme('boys', 'bnbColors', 'blue')).to.equal('blue');
expect(getColorFromScheme('boys', 'bnbColors')).to.equal('blue');
expect(getColorFromScheme('boys', 'googleCategory20c')).to.not.equal('blue');

expect(getColorFromScheme('girls', 'bnbColors', 'pink')).to.equal('pink');
expect(getColorFromScheme('girls', 'bnbColors')).to.equal('pink');
expect(getColorFromScheme('girls', 'googleCategory20c')).to.not.equal('pink');
});
it('getColorFromScheme is not case sensitive', () => {
const c1 = getColorFromScheme('girls', 'bnbColors');
const c2 = getColorFromScheme('Girls', 'bnbColors');
const c3 = getColorFromScheme('GIRLS', 'bnbColors');
expect(c1).to.equal(c2);
expect(c3).to.equal(c2);
});
it('hexToRGB converts properly', () => {
expect(hexToRGB('#FFFFFF')).to.have.same.members([255, 255, 255, 255]);
expect(hexToRGB('#000000')).to.have.same.members([0, 0, 0, 255]);
Expand Down
21 changes: 0 additions & 21 deletions superset/assets/src/modules/colors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import d3 from 'd3';
import { getScale } from './CategoricalColorNamespace';
import sequentialSchemes from './colorSchemes/sequential';
import airbnb from './colorSchemes/airbnb';
import lyft from './colorSchemes/lyft';
Expand All @@ -19,26 +18,6 @@ export function hexToRGB(hex, alpha = 255) {
return [r, g, b, alpha];
}

/**
* Get a color from a scheme specific palette (scheme)
* The function cycles through the palette while memoizing labels
* association to colors. If the function is called twice with the
* same string, it will return the same color.
*
* @param {string} s - The label for which we want to get a color
* @param {string} scheme - The palette name, or "scheme"
* @param {string} forcedColor - A color that the caller wants to
forcibly associate to a label.
*/
export function getColorFromScheme(value, schemeName, forcedColor) {
const scale = getScale(schemeName);
if (forcedColor) {
scale.setColor(value, forcedColor);
return forcedColor;
}
return scale.getColor(value);
}

export const colorScalerFactory = function (colors, data, accessor, extents, outputRGBA = false) {
// Returns a linear scaler our of an array of color
if (!Array.isArray(colors)) {
Expand Down