import CategoricalColorScale from './CategoricalColorScale' ; import { ColorsLookup } from './types' ; import getCategoricalSchemeRegistry from './CategoricalSchemeRegistrySingleton' ; import stringifyAndTrim from './stringifyAndTrim' ; export default class CategoricalColorNamespace { name : string ; forcedItems : ColorsLookup ; scales : { [ key ] : CategoricalColorScale ; } ; constructor ( name ) { this . name = name ; this . scales = { } ; this . forcedItems = { } ; } getScale ( schemeId ? ) { const id = schemeId ?? getCategoricalSchemeRegistry ( ) . getDefaultKey ( ) ?? '' ; const scheme = getCategoricalSchemeRegistry ( ) . get ( id ) ; const newScale = new CategoricalColorScale ( scheme ?. colors ?? [ ] , this . forcedItems ) ; return newScale ; } param { * } value param { * } forcedColor setColor ( value , forcedColor ) { this . forcedItems [ stringifyAndTrim ( value ) ] = forcedColor ; return this ; } resetColors ( ) { this . forcedItems = { } ; } } 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 ? , schemeId ? , namespace ? ) { return getNamespace ( namespace ) . getScale ( schemeId ) . getColor ( value ) ; } export function getScale ( scheme ? , namespace ? ) { return getNamespace ( namespace ) . getScale ( scheme ) ; }