Skip to content

Commit

Permalink
fix: process color scheme configs correctly (apache#17786)
Browse files Browse the repository at this point in the history
(cherry picked from commit de3d397)
  • Loading branch information
suddjian authored and rosemarie-chiu committed Jan 11, 2022
1 parent aa247ee commit 6e7dbe2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import * as CategoricalColorNamespace from './CategoricalColorNamespace';
export { CategoricalColorNamespace };
export { default as CategoricalColorScale } from './CategoricalColorScale';
export { default as CategoricalScheme } from './CategoricalScheme';
export * from './CategoricalScheme';
export { default as getCategoricalSchemeRegistry } from './CategoricalSchemeRegistrySingleton';
export { default as ColorScheme } from './ColorScheme';
export * from './ColorScheme';
export { default as getSequentialSchemeRegistry } from './SequentialSchemeRegistrySingleton';
export { default as SequentialScheme } from './SequentialScheme';
export * from './SequentialScheme';
export { default as ColorSchemeRegistry } from './ColorSchemeRegistry';
export * from './colorSchemes';
export * from './utils';
Expand Down
19 changes: 14 additions & 5 deletions superset-frontend/src/setup/setupColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
import {
CategoricalScheme,
ColorScheme,
ColorSchemeConfig,
getCategoricalSchemeRegistry,
getSequentialSchemeRegistry,
SequentialScheme,
SequentialSchemeConfig,
CategoricalAirbnb,
CategoricalD3,
CategoricalEcharts,
Expand All @@ -33,9 +36,9 @@ import {
ColorSchemeRegistry,
} from '@superset-ui/core';

function registerColorSchemes(
registry: ColorSchemeRegistry<unknown>,
colorSchemes: (CategoricalScheme | SequentialScheme)[],
function registerColorSchemes<T extends ColorScheme>(
registry: ColorSchemeRegistry<T>,
colorSchemes: T[],
standardDefaultKey: string,
) {
colorSchemes.forEach(scheme => {
Expand All @@ -48,9 +51,15 @@ function registerColorSchemes(
}

export default function setupColors(
extraCategoricalColorSchemes: CategoricalScheme[] = [],
extraSequentialColorSchemes: SequentialScheme[] = [],
extraCategoricalColorSchemeConfigs: ColorSchemeConfig[] = [],
extraSequentialColorSchemeConfigs: SequentialSchemeConfig[] = [],
) {
const extraCategoricalColorSchemes = extraCategoricalColorSchemeConfigs.map(
config => new CategoricalScheme(config),
);
const extraSequentialColorSchemes = extraSequentialColorSchemeConfigs.map(
config => new SequentialScheme(config),
);
registerColorSchemes(
// @ts-ignore
getCategoricalSchemeRegistry(),
Expand Down

0 comments on commit 6e7dbe2

Please sign in to comment.