Skip to content

Commit

Permalink
Rename ColorScheme field 'name' to 'id' (#35)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename ColorScheme field 'name' to 'id'
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 26, 2021
1 parent 1edfdcf commit 4e39bf7
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export default class CategoricalColorNamespace {
this.forcedItems = {};
}

getScale(schemeName) {
const name = schemeName || getCategoricalSchemeRegistry().getDefaultKey();
const scale = this.scales[name];
getScale(schemeId) {
const id = schemeId || getCategoricalSchemeRegistry().getDefaultKey();
const scale = this.scales[id];
if (scale) {
return scale;
}
const newScale = new CategoricalColorScale(
getCategoricalSchemeRegistry().get(name).colors,
getCategoricalSchemeRegistry().get(id).colors,
this.forcedItems,
);
this.scales[name] = newScale;
this.scales[id] = newScale;

return newScale;
}
Expand Down Expand Up @@ -52,9 +52,9 @@ export function getNamespace(name = DEFAULT_NAMESPACE) {
return newInstance;
}

export function getColor(value, scheme, namespace) {
export function getColor(value, schemeId, namespace) {
return getNamespace(namespace)
.getScale(scheme)
.getScale(schemeId)
.getColor(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { isRequired } from '@superset-ui/core';

export default class ColorScheme {
constructor({
name = isRequired('name'),
label,
colors = isRequired('colors'),
description = '',
}) {
this.name = name;
this.label = label || name;
constructor({ colors = isRequired('colors'), description = '', id = isRequired('id'), label }) {
this.id = id;
this.label = label || id;
this.colors = colors;
this.description = description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CategoricalScheme from '../../CategoricalScheme';

const schemes = [
{
name: 'bnbColors',
id: 'bnbColors',
colors: [
'#ff5a5f', // rausch
'#7b0051', // hackb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CategoricalScheme from '../../CategoricalScheme';

const schemes = [
{
name: 'd3Category10',
id: 'd3Category10',
colors: [
'#1f77b4',
'#ff7f0e',
Expand All @@ -19,7 +19,7 @@ const schemes = [
],
},
{
name: 'd3Category20',
id: 'd3Category20',
colors: [
'#1f77b4',
'#aec7e8',
Expand All @@ -44,7 +44,7 @@ const schemes = [
],
},
{
name: 'd3Category20b',
id: 'd3Category20b',
colors: [
'#393b79',
'#5254a3',
Expand All @@ -69,7 +69,7 @@ const schemes = [
],
},
{
name: 'd3Category20c',
id: 'd3Category20c',
colors: [
'#3182bd',
'#6baed6',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CategoricalScheme from '../../CategoricalScheme';

const schemes = [
{
name: 'googleCategory10c',
id: 'googleCategory10c',
colors: [
'#3366cc',
'#dc3912',
Expand All @@ -19,7 +19,7 @@ const schemes = [
],
},
{
name: 'googleCategory20c',
id: 'googleCategory20c',
colors: [
'#3366cc',
'#dc3912',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CategoricalScheme from '../../CategoricalScheme';

const schemes = [
{
name: 'lyftColors',
id: 'lyftColors',
colors: [
'#EA0B8C',
'#6C838E',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,61 @@ import SequentialScheme from '../../SequentialScheme';

const schemes = [
{
name: 'blue_white_yellow',
id: 'blue_white_yellow',
label: 'blue/white/yellow',
colors: ['#00d1c1', 'white', '#ffb400'],
},
{
name: 'fire',
id: 'fire',
colors: ['white', 'yellow', 'red', 'black'],
},
{
name: 'white_black',
id: 'white_black',
label: 'white/black',
colors: ['white', 'black'],
},
{
name: 'black_white',
id: 'black_white',
label: 'black/white',
colors: ['black', 'white'],
},
{
name: 'dark_blue',
id: 'dark_blue',
label: 'dark blues',
colors: ['#EBF5F8', '#6BB1CC', '#357E9B', '#1B4150', '#092935'],
},
{
name: 'pink_grey',
id: 'pink_grey',
label: 'pink/grey',
isDiverging: true,
colors: ['#E70B81', '#FAFAFA', '#666666'],
},
{
name: 'greens',
id: 'greens',
colors: ['#ffffcc', '#78c679', '#006837'],
},
{
name: 'purples',
id: 'purples',
colors: ['#f2f0f7', '#9e9ac8', '#54278f'],
},
{
name: 'oranges',
id: 'oranges',
colors: ['#fef0d9', '#fc8d59', '#b30000'],
},
{
name: 'red_yellow_blue',
id: 'red_yellow_blue',
label: 'red/yellow/blue',
isDiverging: true,
colors: ['#d7191c', '#fdae61', '#ffffbf', '#abd9e9', '#2c7bb6'],
},
{
name: 'brown_white_green',
id: 'brown_white_green',
label: 'brown/white/green',
isDiverging: true,
colors: ['#a6611a', '#dfc27d', '#f5f5f5', '#80cdc1', '#018571'],
},
{
name: 'purple_white_green',
id: 'purple_white_green',
label: 'purple/white/green',
isDiverging: true,
colors: ['#7b3294', '#c2a5cf', '#f7f7f7', '#a6dba0', '#008837'],
Expand Down
Loading

0 comments on commit 4e39bf7

Please sign in to comment.