mirror of
https://github.com/apache/superset.git
synced 2026-07-04 05:45:32 +00:00
Compare commits
6 Commits
chore/ci/s
...
pr-39226
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6218b3efd | ||
|
|
d8f2fb7e6e | ||
|
|
3bf629f12c | ||
|
|
e9dc58e757 | ||
|
|
77aa873915 | ||
|
|
70251482d2 |
@@ -58,6 +58,10 @@
|
|||||||
"types": "./lib/components/index.d.ts",
|
"types": "./lib/components/index.d.ts",
|
||||||
"default": "./lib/components/index.js"
|
"default": "./lib/components/index.js"
|
||||||
},
|
},
|
||||||
|
"./colors": {
|
||||||
|
"types": "./lib/colors/index.d.ts",
|
||||||
|
"default": "./lib/colors/index.js"
|
||||||
|
},
|
||||||
"./utils": {
|
"./utils": {
|
||||||
"types": "./lib/utils/index.d.ts",
|
"types": "./lib/utils/index.d.ts",
|
||||||
"default": "./lib/utils/index.js"
|
"default": "./lib/utils/index.js"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ColorSchemeGroup } from '@apache-superset/core/colors';
|
||||||
|
|
||||||
|
// ─── ColorSchemeGroup enum ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
test('ColorSchemeGroup has the expected string values', () => {
|
||||||
|
expect(ColorSchemeGroup.Custom).toBe('custom');
|
||||||
|
expect(ColorSchemeGroup.Featured).toBe('featured');
|
||||||
|
expect(ColorSchemeGroup.Other).toBe('other');
|
||||||
|
});
|
||||||
51
superset-frontend/packages/superset-core/src/colors/index.ts
Normal file
51
superset-frontend/packages/superset-core/src/colors/index.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Types & enums for color scheme configuration — usable by extensions and host alike
|
||||||
|
export type { ColorSchemeConfig, SequentialSchemeConfig } from './types';
|
||||||
|
export { ColorSchemeGroup } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal interface for the categorical color scheme registry.
|
||||||
|
* Mirrors the public surface of @superset-ui/core's ColorSchemeRegistry.
|
||||||
|
*/
|
||||||
|
export interface CategoricalScheme {
|
||||||
|
id: string;
|
||||||
|
label?: string;
|
||||||
|
colors: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CategoricalSchemeRegistryLike {
|
||||||
|
keys(): string[];
|
||||||
|
get(name: string): CategoricalScheme | null | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an alphabetically sorted list of all registered categorical color
|
||||||
|
* scheme names. The host app (ExtensionsStartup) provides the implementation
|
||||||
|
* via window.superset.colors.
|
||||||
|
*/
|
||||||
|
export declare function getCategoricalSchemeNames(): string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the color array for a named scheme, or null if not found.
|
||||||
|
* The host app (ExtensionsStartup) provides the implementation
|
||||||
|
* via window.superset.colors.
|
||||||
|
*/
|
||||||
|
export declare function getSchemeColors(schemeName: string): string[] | null;
|
||||||
46
superset-frontend/packages/superset-core/src/colors/types.ts
Normal file
46
superset-frontend/packages/superset-core/src/colors/types.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grouping/tier for a color scheme — controls how it appears in the
|
||||||
|
* scheme picker UI (e.g. Featured palettes are shown first).
|
||||||
|
*
|
||||||
|
* Mirrors @superset-ui/core's ColorSchemeGroup; kept here so
|
||||||
|
* palette configs have no dependency on @superset-ui/core.
|
||||||
|
*/
|
||||||
|
export enum ColorSchemeGroup {
|
||||||
|
Custom = 'custom',
|
||||||
|
Featured = 'featured',
|
||||||
|
Other = 'other',
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plain configuration object for a categorical color scheme. */
|
||||||
|
export interface ColorSchemeConfig {
|
||||||
|
id: string;
|
||||||
|
label?: string;
|
||||||
|
colors: string[];
|
||||||
|
description?: string;
|
||||||
|
isDefault?: boolean;
|
||||||
|
group?: ColorSchemeGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extension of ColorSchemeConfig for sequential / diverging schemes. */
|
||||||
|
export interface SequentialSchemeConfig extends ColorSchemeConfig {
|
||||||
|
isDiverging?: boolean;
|
||||||
|
}
|
||||||
@@ -29,3 +29,4 @@ export * as theme from './theme';
|
|||||||
export * as translation from './translation';
|
export * as translation from './translation';
|
||||||
export * as components from './components';
|
export * as components from './components';
|
||||||
export * as utils from './utils';
|
export * as utils from './utils';
|
||||||
|
export * as colors from './colors';
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ import {
|
|||||||
CategoricalD3,
|
CategoricalD3,
|
||||||
CategoricalGoogle,
|
CategoricalGoogle,
|
||||||
CategoricalLyft,
|
CategoricalLyft,
|
||||||
|
CategoricalModernSunset,
|
||||||
|
CategoricalColorsOfRainbow,
|
||||||
|
CategoricalBlueToGreen,
|
||||||
|
CategoricalRedToYellow,
|
||||||
|
CategoricalWavesOfBlue,
|
||||||
|
CategoricalPresetSuperset,
|
||||||
SequentialCommon,
|
SequentialCommon,
|
||||||
SequentialD3,
|
SequentialD3,
|
||||||
CategoricalScheme,
|
CategoricalScheme,
|
||||||
@@ -41,22 +47,59 @@ describe('Color Schemes', () => {
|
|||||||
CategoricalLyft,
|
CategoricalLyft,
|
||||||
CategoricalSuperset,
|
CategoricalSuperset,
|
||||||
CategoricalPreset,
|
CategoricalPreset,
|
||||||
|
CategoricalModernSunset,
|
||||||
|
CategoricalColorsOfRainbow,
|
||||||
|
CategoricalBlueToGreen,
|
||||||
|
CategoricalRedToYellow,
|
||||||
|
CategoricalWavesOfBlue,
|
||||||
|
CategoricalPresetSuperset,
|
||||||
].forEach(group => {
|
].forEach(group => {
|
||||||
expect(group).toBeInstanceOf(Array);
|
expect(group).toBeInstanceOf(Array);
|
||||||
|
expect(group.length).toBeGreaterThan(0);
|
||||||
group.forEach(scheme =>
|
group.forEach(scheme =>
|
||||||
expect(scheme).toBeInstanceOf(CategoricalScheme),
|
expect(scheme).toBeInstanceOf(CategoricalScheme),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('each scheme has a non-empty id and at least one color', () => {
|
||||||
|
[
|
||||||
|
...CategoricalAirbnb,
|
||||||
|
...CategoricalD3,
|
||||||
|
...CategoricalEcharts,
|
||||||
|
...CategoricalGoogle,
|
||||||
|
...CategoricalLyft,
|
||||||
|
...CategoricalPreset,
|
||||||
|
...CategoricalSuperset,
|
||||||
|
...CategoricalPresetSuperset,
|
||||||
|
...CategoricalModernSunset,
|
||||||
|
...CategoricalColorsOfRainbow,
|
||||||
|
...CategoricalBlueToGreen,
|
||||||
|
...CategoricalRedToYellow,
|
||||||
|
...CategoricalWavesOfBlue,
|
||||||
|
].forEach(scheme => {
|
||||||
|
expect(scheme.id).toBeTruthy();
|
||||||
|
expect(scheme.colors.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sequential', () => {
|
describe('sequential', () => {
|
||||||
test('returns an array of SequentialScheme', () => {
|
test('returns an array of SequentialScheme', () => {
|
||||||
[SequentialCommon, SequentialD3].forEach(group => {
|
[SequentialCommon, SequentialD3].forEach(group => {
|
||||||
expect(group).toBeInstanceOf(Array);
|
expect(group).toBeInstanceOf(Array);
|
||||||
|
expect(group.length).toBeGreaterThan(0);
|
||||||
group.forEach(scheme =>
|
group.forEach(scheme =>
|
||||||
expect(scheme).toBeInstanceOf(SequentialScheme),
|
expect(scheme).toBeInstanceOf(SequentialScheme),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('each scheme has a non-empty id and at least two colors', () => {
|
||||||
|
[...SequentialCommon, ...SequentialD3].forEach(scheme => {
|
||||||
|
expect(scheme.id).toBeTruthy();
|
||||||
|
expect(scheme.colors.length).toBeGreaterThanOrEqual(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ function main() {
|
|||||||
/\.stories\./,
|
/\.stories\./,
|
||||||
/\/demo\//,
|
/\/demo\//,
|
||||||
/\/examples\//,
|
/\/examples\//,
|
||||||
/\/color\/colorSchemes\//,
|
/\/color\/colorSchemes\//, // @superset-ui/core palette scheme definitions legitimately contain colors
|
||||||
/\/cypress\//,
|
/\/cypress\//,
|
||||||
/\/cypress-base\//,
|
/\/cypress-base\//,
|
||||||
/\/esm\//,
|
/\/esm\//,
|
||||||
|
|||||||
@@ -19,7 +19,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
import * as supersetCore from '@apache-superset/core';
|
import * as supersetCore from '@apache-superset/core';
|
||||||
import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
|
import {
|
||||||
|
FeatureFlag,
|
||||||
|
isFeatureEnabled,
|
||||||
|
getCategoricalSchemeRegistry,
|
||||||
|
} from '@superset-ui/core';
|
||||||
|
import type { CategoricalSchemeRegistryLike } from '@apache-superset/core/colors';
|
||||||
import {
|
import {
|
||||||
authentication,
|
authentication,
|
||||||
core,
|
core,
|
||||||
@@ -45,6 +50,11 @@ declare global {
|
|||||||
menus: typeof menus;
|
menus: typeof menus;
|
||||||
sqlLab: typeof sqlLab;
|
sqlLab: typeof sqlLab;
|
||||||
views: typeof views;
|
views: typeof views;
|
||||||
|
colors: {
|
||||||
|
ColorSchemeGroup: typeof supersetCore.colors.ColorSchemeGroup;
|
||||||
|
getCategoricalSchemeNames(): string[];
|
||||||
|
getSchemeColors(schemeName: string): string[] | null;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,6 +78,8 @@ const ExtensionsStartup: React.FC<{ children?: React.ReactNode }> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Provide the implementations for @apache-superset/core
|
// Provide the implementations for @apache-superset/core
|
||||||
|
const registry =
|
||||||
|
getCategoricalSchemeRegistry() as CategoricalSchemeRegistryLike | null;
|
||||||
window.superset = {
|
window.superset = {
|
||||||
...supersetCore,
|
...supersetCore,
|
||||||
authentication,
|
authentication,
|
||||||
@@ -78,6 +90,15 @@ const ExtensionsStartup: React.FC<{ children?: React.ReactNode }> = ({
|
|||||||
menus,
|
menus,
|
||||||
sqlLab,
|
sqlLab,
|
||||||
views,
|
views,
|
||||||
|
colors: {
|
||||||
|
ColorSchemeGroup: supersetCore.colors.ColorSchemeGroup,
|
||||||
|
getCategoricalSchemeNames(): string[] {
|
||||||
|
return (registry?.keys() ?? []).sort();
|
||||||
|
},
|
||||||
|
getSchemeColors(schemeName: string): string[] | null {
|
||||||
|
return registry?.get(schemeName)?.colors ?? null;
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user