mirror of
https://github.com/apache/superset.git
synced 2026-05-01 05:54:26 +00:00
Compare commits
6 Commits
fix/check-
...
pr-39226
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6218b3efd | ||
|
|
d8f2fb7e6e | ||
|
|
3bf629f12c | ||
|
|
e9dc58e757 | ||
|
|
77aa873915 | ||
|
|
70251482d2 |
@@ -58,6 +58,10 @@
|
||||
"types": "./lib/components/index.d.ts",
|
||||
"default": "./lib/components/index.js"
|
||||
},
|
||||
"./colors": {
|
||||
"types": "./lib/colors/index.d.ts",
|
||||
"default": "./lib/colors/index.js"
|
||||
},
|
||||
"./utils": {
|
||||
"types": "./lib/utils/index.d.ts",
|
||||
"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 components from './components';
|
||||
export * as utils from './utils';
|
||||
export * as colors from './colors';
|
||||
|
||||
@@ -24,6 +24,12 @@ import {
|
||||
CategoricalD3,
|
||||
CategoricalGoogle,
|
||||
CategoricalLyft,
|
||||
CategoricalModernSunset,
|
||||
CategoricalColorsOfRainbow,
|
||||
CategoricalBlueToGreen,
|
||||
CategoricalRedToYellow,
|
||||
CategoricalWavesOfBlue,
|
||||
CategoricalPresetSuperset,
|
||||
SequentialCommon,
|
||||
SequentialD3,
|
||||
CategoricalScheme,
|
||||
@@ -41,22 +47,59 @@ describe('Color Schemes', () => {
|
||||
CategoricalLyft,
|
||||
CategoricalSuperset,
|
||||
CategoricalPreset,
|
||||
CategoricalModernSunset,
|
||||
CategoricalColorsOfRainbow,
|
||||
CategoricalBlueToGreen,
|
||||
CategoricalRedToYellow,
|
||||
CategoricalWavesOfBlue,
|
||||
CategoricalPresetSuperset,
|
||||
].forEach(group => {
|
||||
expect(group).toBeInstanceOf(Array);
|
||||
expect(group.length).toBeGreaterThan(0);
|
||||
group.forEach(scheme =>
|
||||
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', () => {
|
||||
test('returns an array of SequentialScheme', () => {
|
||||
[SequentialCommon, SequentialD3].forEach(group => {
|
||||
expect(group).toBeInstanceOf(Array);
|
||||
expect(group.length).toBeGreaterThan(0);
|
||||
group.forEach(scheme =>
|
||||
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\./,
|
||||
/\/demo\//,
|
||||
/\/examples\//,
|
||||
/\/color\/colorSchemes\//,
|
||||
/\/color\/colorSchemes\//, // @superset-ui/core palette scheme definitions legitimately contain colors
|
||||
/\/cypress\//,
|
||||
/\/cypress-base\//,
|
||||
/\/esm\//,
|
||||
|
||||
@@ -19,7 +19,12 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
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 {
|
||||
authentication,
|
||||
core,
|
||||
@@ -45,6 +50,11 @@ declare global {
|
||||
menus: typeof menus;
|
||||
sqlLab: typeof sqlLab;
|
||||
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
|
||||
const registry =
|
||||
getCategoricalSchemeRegistry() as CategoricalSchemeRegistryLike | null;
|
||||
window.superset = {
|
||||
...supersetCore,
|
||||
authentication,
|
||||
@@ -78,6 +90,15 @@ const ExtensionsStartup: React.FC<{ children?: React.ReactNode }> = ({
|
||||
menus,
|
||||
sqlLab,
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user