JSFiddle - React, Tailwind, and code Playground
by ppgab
JavaScript
'use strict';
var palette = (function() {
var proto = Array.prototype;
var slice = function(arr, opt_begin, opt_end) {
return proto.slice.apply(arr, proto.slice.call(arguments, 1));
};
var extend = function(arr, arr2) {
return proto.push.apply(arr, arr2);
};
var function_type = typeof function() {};
var INF = 1000000000; // As far as we're concerned, that's infinity. ;)
/**
* Generate a colour palette from given scheme.
*
* If scheme argument is not a function it is passed to palettes.listSchemes
* function (along with the number argument). This may result in an array
* of more than one available scheme. If that is the case, scheme at
* opt_index position is taken.
*
* This allows using different palettes for different data without having to
* name the schemes specifically, for example:
*
* palette_for_foo = palette('sequential', 10, 0);
* palette_for_bar = palette('sequential', 10, 1);
* palette_for_baz = palette('sequential', 10, 2);
*
* @param {!palette.SchemeType|string|palette.Palette} scheme Scheme to
* generate palette for. Either a function constructed with
* palette.Scheme object, or anything that palette.listSchemes accepts
* as name argument.
* @param {number} number Number of colours to return. If negative, absolute
* value is taken and colours will be returned in reverse order.
* @param {number=} opt_index If scheme is a name of a group or an array and
* results in more than one scheme, index of the scheme to use. The
* index wraps around.
* @param {...*} varargs Additional arguments to pass to palette or colour
* generator (if the chosen scheme uses those).
* @return {Array<string>} Array of abs(number) 'RRGGBB' strings or null if
* no matching scheme was found.
*/
var palette = function(scheme, number, opt_index, varargs) {
number |= 0;
if (number == 0) {
return [];
...