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

fix: process color scheme configs correctly #17786

Merged
merged 1 commit into from
Jan 4, 2022
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
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