All files / src/utils ColorScheme.js

100% Statements 4/4
100% Branches 2/2
100% Functions 3/3
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                  6x               12x       12090x                       24x    
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
import schemes from '../colorschemes';
const schemesMgr = new schemes();
 
/**
 * Simple color scheme abstraction over msa-colorschemes. To be extended.
 */
class ColorScheme {
 
  constructor(colorScheme) {
    this.scheme = schemesMgr.getScheme(colorScheme);
  }
 
  getColor(element) {
    return this.scheme.getColor(element);
  }
 
}
export default ColorScheme;
export {ColorScheme};
 
/**
 * Checks whether the `obj` is a color scheme.
 * Everything that looks like a color scheme is very likely one.
 */
export function isColorScheme(obj) {
  return obj && typeof obj.getColor === "function";
}