-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add initial files * update references * fix lint issues * Define top-level exports * disable linting for color schemes * update test * update travis * update travis * revert travis * install once * update clear() * update core index test * update color index test * update travis * try build before test * update unit tes * override beemo config * remove test command * update ignore path * use new build config
- Loading branch information
1 parent
a10e176
commit 2490be7
Showing
26 changed files
with
1,477 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Changelog | ||
|
||
### 0.3.0 | ||
|
||
- Rename former `@superset-ui/core` to `@superset-ui/connection`. | ||
- Add new `@superset-ui/core` with data structures and utilities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...frontend/temporary_superset_ui/superset-ui/packages/superset-ui-color/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## @superset-ui/color | ||
|
||
[![Version](https://img.shields.io/npm/v/@superset-ui/color.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/color.svg?style=flat) | ||
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fsuperset-ui-color&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/superset-ui-color) | ||
|
||
Description | ||
|
||
#### Example usage | ||
|
||
```js | ||
import { xxx } from '@superset-ui/color'; | ||
``` | ||
|
||
#### API | ||
|
||
`fn(args)` | ||
|
||
- Do something | ||
|
||
### Development | ||
|
||
`@data-ui/build-config` is used to manage the build configuration for this package including babel | ||
builds, jest testing, eslint, and prettier. |
31 changes: 31 additions & 0 deletions
31
superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-color/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@superset-ui/color", | ||
"version": "0.0.0", | ||
"description": "Superset UI color", | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"esm", | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/apache-superset/superset-ui.git" | ||
}, | ||
"keywords": [ | ||
"superset" | ||
], | ||
"author": "Superset", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/apache-superset/superset-ui/issues" | ||
}, | ||
"homepage": "https://github.com/apache-superset/superset-ui#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@superset-ui/core": "^0.3.0" | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...orary_superset_ui/superset-ui/packages/superset-ui-color/src/CategoricalColorNamespace.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import CategoricalColorScale from './CategoricalColorScale'; | ||
import getCategoricalSchemeRegistry from './CategoricalSchemeRegistrySingleton'; | ||
|
||
export default class CategoricalColorNamespace { | ||
constructor(name) { | ||
this.name = name; | ||
this.scales = {}; | ||
this.forcedItems = {}; | ||
} | ||
|
||
getScale(schemeName) { | ||
const name = schemeName || getCategoricalSchemeRegistry().getDefaultSchemeName(); | ||
const scale = this.scales[name]; | ||
if (scale) { | ||
return scale; | ||
} | ||
const newScale = new CategoricalColorScale( | ||
getCategoricalSchemeRegistry().get(name).colors, | ||
this.forcedItems, | ||
); | ||
this.scales[name] = newScale; | ||
|
||
return newScale; | ||
} | ||
|
||
/** | ||
* Enforce specific color for given value | ||
* This will apply across all color scales | ||
* in this namespace. | ||
* @param {*} value value | ||
* @param {*} forcedColor color | ||
*/ | ||
setColor(value, forcedColor) { | ||
this.forcedItems[value] = forcedColor; | ||
|
||
return this; | ||
} | ||
} | ||
|
||
const namespaces = {}; | ||
export const DEFAULT_NAMESPACE = 'GLOBAL'; | ||
|
||
export function getNamespace(name = DEFAULT_NAMESPACE) { | ||
const instance = namespaces[name]; | ||
if (instance) { | ||
return instance; | ||
} | ||
const newInstance = new CategoricalColorNamespace(name); | ||
namespaces[name] = newInstance; | ||
|
||
return newInstance; | ||
} | ||
|
||
export function getColor(value, scheme, namespace) { | ||
return getNamespace(namespace) | ||
.getScale(scheme) | ||
.getColor(value); | ||
} | ||
|
||
export function getScale(scheme, namespace) { | ||
return getNamespace(namespace).getScale(scheme); | ||
} |
62 changes: 62 additions & 0 deletions
62
...temporary_superset_ui/superset-ui/packages/superset-ui-color/src/CategoricalColorScale.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export function cleanValue(value) { | ||
// for superset series that should have the same color | ||
return String(value) | ||
.trim() | ||
.toLowerCase(); | ||
} | ||
|
||
export default class CategoricalColorScale { | ||
/** | ||
* Constructor | ||
* @param {*} colors an array of colors | ||
* @param {*} parentForcedColors optional parameter that comes from parent | ||
* (usually CategoricalColorNamespace) and supersede this.forcedColors | ||
*/ | ||
constructor(colors, parentForcedColors) { | ||
this.colors = colors; | ||
this.parentForcedColors = parentForcedColors; | ||
this.forcedColors = {}; | ||
this.seen = {}; | ||
this.fn = value => this.getColor(value); | ||
} | ||
|
||
getColor(value) { | ||
const cleanedValue = cleanValue(value); | ||
|
||
const parentColor = this.parentForcedColors && this.parentForcedColors[cleanedValue]; | ||
if (parentColor) { | ||
return parentColor; | ||
} | ||
|
||
const forcedColor = this.forcedColors[cleanedValue]; | ||
if (forcedColor) { | ||
return forcedColor; | ||
} | ||
|
||
const seenColor = this.seen[cleanedValue]; | ||
const { length } = this.colors; | ||
if (seenColor !== undefined) { | ||
return this.colors[seenColor % length]; | ||
} | ||
|
||
const index = Object.keys(this.seen).length; | ||
this.seen[cleanedValue] = index; | ||
|
||
return this.colors[index % length]; | ||
} | ||
|
||
/** | ||
* Enforce specific color for given value | ||
* @param {*} value value | ||
* @param {*} forcedColor forcedColor | ||
*/ | ||
setColor(value, forcedColor) { | ||
this.forcedColors[value] = forcedColor; | ||
|
||
return this; | ||
} | ||
|
||
toFunction() { | ||
return this.fn; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...end/temporary_superset_ui/superset-ui/packages/superset-ui-color/src/CategoricalScheme.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ColorScheme from './ColorScheme'; | ||
|
||
export default class CategoricalScheme extends ColorScheme {} |
8 changes: 8 additions & 0 deletions
8
...erset_ui/superset-ui/packages/superset-ui-color/src/CategoricalSchemeRegistrySingleton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { makeSingleton } from '@superset-ui/core'; | ||
import ColorSchemeRegistry from './ColorSchemeRegistry'; | ||
|
||
class CategoricalSchemeRegistry extends ColorSchemeRegistry {} | ||
|
||
const getInstance = makeSingleton(CategoricalSchemeRegistry); | ||
|
||
export default getInstance; |
15 changes: 15 additions & 0 deletions
15
...-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-color/src/ColorScheme.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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; | ||
this.colors = colors; | ||
this.description = description; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...d/temporary_superset_ui/superset-ui/packages/superset-ui-color/src/ColorSchemeRegistry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Registry } from '@superset-ui/core'; | ||
|
||
class ColorSchemeRegistry extends Registry { | ||
clear() { | ||
super.clear(); | ||
this.defaultSchemeName = undefined; | ||
|
||
return this; | ||
} | ||
|
||
getDefaultSchemeName() { | ||
return this.defaultSchemeName; | ||
} | ||
|
||
setDefaultSchemeName(schemeName) { | ||
this.defaultSchemeName = schemeName; | ||
|
||
return this; | ||
} | ||
|
||
get(schemeName) { | ||
return super.get(schemeName || this.defaultSchemeName); | ||
} | ||
|
||
registerValue(schemeName, colors) { | ||
super.registerValue(schemeName, colors); | ||
// If there is no default, set as default | ||
if (!this.defaultSchemeName) { | ||
this.defaultSchemeName = schemeName; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
registerLoader(schemeName, loader) { | ||
super.registerLoader(schemeName, loader); | ||
// If there is no default, set as default | ||
if (!this.defaultSchemeName) { | ||
this.defaultSchemeName = schemeName; | ||
} | ||
|
||
return this; | ||
} | ||
} | ||
|
||
export default ColorSchemeRegistry; |
9 changes: 9 additions & 0 deletions
9
...tend/temporary_superset_ui/superset-ui/packages/superset-ui-color/src/SequentialScheme.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import ColorScheme from './ColorScheme'; | ||
|
||
export default class SequentialScheme extends ColorScheme { | ||
constructor(input) { | ||
super(input); | ||
const { isDiverging = false } = input; | ||
this.isDiverging = isDiverging; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...perset_ui/superset-ui/packages/superset-ui-color/src/SequentialSchemeRegistrySingleton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { makeSingleton } from '@superset-ui/core'; | ||
import ColorSchemeRegistry from './ColorSchemeRegistry'; | ||
|
||
class SequentialSchemeRegistry extends ColorSchemeRegistry {} | ||
|
||
const getInstance = makeSingleton(SequentialSchemeRegistry); | ||
|
||
export default getInstance; |
34 changes: 34 additions & 0 deletions
34
...superset_ui/superset-ui/packages/superset-ui-color/src/colorSchemes/categorical/airbnb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable sort-keys */ | ||
|
||
import CategoricalScheme from '../../CategoricalScheme'; | ||
|
||
const schemes = [ | ||
{ | ||
name: 'bnbColors', | ||
colors: [ | ||
'#ff5a5f', // rausch | ||
'#7b0051', // hackb | ||
'#007A87', // kazan | ||
'#00d1c1', // babu | ||
'#8ce071', // lima | ||
'#ffb400', // beach | ||
'#b4a76c', // barol | ||
'#ff8083', | ||
'#cc0086', | ||
'#00a1b3', | ||
'#00ffeb', | ||
'#bbedab', | ||
'#ffd266', | ||
'#cbc29a', | ||
'#ff3339', | ||
'#ff1ab1', | ||
'#005c66', | ||
'#00b3a5', | ||
'#55d12e', | ||
'#b37e00', | ||
'#988b4e', | ||
], | ||
}, | ||
].map(s => new CategoricalScheme(s)); | ||
|
||
export default schemes; |
Oops, something went wrong.