kristw closed pull request #5937: Deprecate getColorFromScheme
URL: https://github.com/apache/incubator-superset/pull/5937
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/superset/assets/spec/javascripts/modules/colors_spec.jsx
b/superset/assets/spec/javascripts/modules/colors_spec.jsx
index a91c74f163..d1084f5f9a 100644
--- a/superset/assets/spec/javascripts/modules/colors_spec.jsx
+++ b/superset/assets/spec/javascripts/modules/colors_spec.jsx
@@ -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]);
diff --git a/superset/assets/src/modules/colors.js
b/superset/assets/src/modules/colors.js
index 43025dc85b..0c23d4071f 100644
--- a/superset/assets/src/modules/colors.js
+++ b/superset/assets/src/modules/colors.js
@@ -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';
@@ -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)) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]