mirror of https://github.com/apache/superset.git
refactor(color-schemes): refactor setting of color schemes (#12857)
* refactor(color-schemes): refactor setting of color schemes * refactor: fix TS types
This commit is contained in:
parent
465d986617
commit
5a9bf53246
|
@ -20,7 +20,6 @@ import { setConfig as setHotLoaderConfig } from 'react-hot-loader';
|
||||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { configure } from '@superset-ui/core';
|
import { configure } from '@superset-ui/core';
|
||||||
import ColorScheme from '@superset-ui/core/lib/color/ColorScheme';
|
|
||||||
import setupClient from './setup/setupClient';
|
import setupClient from './setup/setupClient';
|
||||||
import setupColors from './setup/setupColors';
|
import setupColors from './setup/setupColors';
|
||||||
import setupFormatters from './setup/setupFormatters';
|
import setupFormatters from './setup/setupFormatters';
|
||||||
|
@ -51,26 +50,10 @@ if (typeof window !== 'undefined') {
|
||||||
// Setup SupersetClient
|
// Setup SupersetClient
|
||||||
setupClient();
|
setupClient();
|
||||||
|
|
||||||
// Setup color palettes
|
setupColors(
|
||||||
let extraCategoricalColorSchemes: ColorScheme[] = [];
|
bootstrapData?.common?.extra_categorical_color_schemes,
|
||||||
let extraSequentialColorSchemes: ColorScheme[] = [];
|
bootstrapData?.common?.extra_sequential_color_schemes,
|
||||||
|
);
|
||||||
if (
|
|
||||||
bootstrapData.common &&
|
|
||||||
bootstrapData.common.extra_categorical_color_schemes
|
|
||||||
) {
|
|
||||||
extraCategoricalColorSchemes =
|
|
||||||
bootstrapData.common.extra_categorical_color_schemes;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
bootstrapData.common &&
|
|
||||||
bootstrapData.common.extra_sequential_color_schemes
|
|
||||||
) {
|
|
||||||
extraSequentialColorSchemes =
|
|
||||||
bootstrapData.common.extra_sequential_color_schemes;
|
|
||||||
}
|
|
||||||
|
|
||||||
setupColors(extraCategoricalColorSchemes, extraSequentialColorSchemes);
|
|
||||||
|
|
||||||
// Setup number formatters
|
// Setup number formatters
|
||||||
setupFormatters();
|
setupFormatters();
|
||||||
|
|
|
@ -16,28 +16,30 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import airbnb from '@superset-ui/core/esm/color/colorSchemes/categorical/airbnb';
|
import airbnb from '@superset-ui/core/lib/color/colorSchemes/categorical/airbnb';
|
||||||
import categoricalD3 from '@superset-ui/core/esm/color/colorSchemes/categorical/d3';
|
import categoricalD3 from '@superset-ui/core/lib/color/colorSchemes/categorical/d3';
|
||||||
import echarts from '@superset-ui/core/esm/color/colorSchemes/categorical/echarts';
|
import echarts from '@superset-ui/core/lib/color/colorSchemes/categorical/echarts';
|
||||||
import google from '@superset-ui/core/esm/color/colorSchemes/categorical/google';
|
import google from '@superset-ui/core/lib/color/colorSchemes/categorical/google';
|
||||||
import lyft from '@superset-ui/core/esm/color/colorSchemes/categorical/lyft';
|
import lyft from '@superset-ui/core/lib/color/colorSchemes/categorical/lyft';
|
||||||
import preset from '@superset-ui/core/esm/color/colorSchemes/categorical/preset';
|
import preset from '@superset-ui/core/lib/color/colorSchemes/categorical/preset';
|
||||||
import sequentialCommon from '@superset-ui/core/esm/color/colorSchemes/sequential/common';
|
import sequentialCommon from '@superset-ui/core/lib/color/colorSchemes/sequential/common';
|
||||||
import sequentialD3 from '@superset-ui/core/esm/color/colorSchemes/sequential/d3';
|
import sequentialD3 from '@superset-ui/core/lib/color/colorSchemes/sequential/d3';
|
||||||
import {
|
import {
|
||||||
|
CategoricalScheme,
|
||||||
getCategoricalSchemeRegistry,
|
getCategoricalSchemeRegistry,
|
||||||
getSequentialSchemeRegistry,
|
getSequentialSchemeRegistry,
|
||||||
|
SequentialScheme,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import superset from '@superset-ui/core/esm/color/colorSchemes/categorical/superset';
|
import superset from '@superset-ui/core/lib/color/colorSchemes/categorical/superset';
|
||||||
|
|
||||||
export default function setupColors(
|
export default function setupColors(
|
||||||
extraCategoricalColorSchemas,
|
extraCategoricalColorSchemas: CategoricalScheme[] = [],
|
||||||
extraSequentialColorSchemes,
|
extraSequentialColorSchemes: SequentialScheme[] = [],
|
||||||
) {
|
) {
|
||||||
// Register color schemes
|
// Register color schemes
|
||||||
const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
|
const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
|
||||||
|
|
||||||
if (extraCategoricalColorSchemas && extraCategoricalColorSchemas.length > 0) {
|
if (extraCategoricalColorSchemas?.length > 0) {
|
||||||
extraCategoricalColorSchemas.forEach(scheme => {
|
extraCategoricalColorSchemas.forEach(scheme => {
|
||||||
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
|
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
|
||||||
});
|
});
|
||||||
|
@ -54,7 +56,7 @@ export default function setupColors(
|
||||||
|
|
||||||
const sequentialSchemeRegistry = getSequentialSchemeRegistry();
|
const sequentialSchemeRegistry = getSequentialSchemeRegistry();
|
||||||
|
|
||||||
if (extraSequentialColorSchemes && extraSequentialColorSchemes.length > 0) {
|
if (extraSequentialColorSchemes?.length > 0) {
|
||||||
extraSequentialColorSchemes.forEach(scheme => {
|
extraSequentialColorSchemes.forEach(scheme => {
|
||||||
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
|
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
|
||||||
});
|
});
|
Loading…
Reference in New Issue