Generate color stops array for use with match expression in mapbox template
498923
def generate_vector_color_map(self):
        """"""
        vector_stops = []

        # if join data specified as filename or URL, parse JSON to list of Python dicts
        if type(self.data) == str:
            self.data = geojson_to_dict_list(self.data)

        # loop through features in self.data to create join-data map
        for row in self.data:
            
            # map color to JSON feature using color_property
            color = color_map(row[self.color_property], self.color_stops, self.color_default)

            # link to vector feature using data_join_property (from JSON object)
            vector_stops.append([row[self.data_join_property], color])

        return vector_stops
214029
function (ui, context) {
					var active = color.active;
					if (context != colorMap && active.val() == null) return;
					var xy = ui.val('all');
					switch (settings.color.mode) {
					case 'h':
						active.val('sv', {
							s: xy.x,
							v: 100 - xy.y
						}, context);
						break;
					case 's':
					case 'a':
						active.val('hv', {
							h: xy.x,
							v: 100 - xy.y
						}, context);
						break;
					case 'v':
						active.val('hs', {
							h: xy.x,
							s: 100 - xy.y
						}, context);
						break;
					case 'r':
						active.val('gb', {
							g: 255 - xy.y,
							b: xy.x
						}, context);
						break;
					case 'g':
						active.val('rb', {
							r: 255 - xy.y,
							b: xy.x
						}, context);
						break;
					case 'b':
						active.val('rg', {
							r: xy.x,
							g: 255 - xy.y
						}, context);
						break;
					}
				}
601622
function validateFormatColor(obj) {
	return COLORS.indexOf(obj) !== -1 || obj.match(colorsReHex3) || obj.match(colorsReHex6)
		|| obj.match(colorsReRgbNum) || obj.match(colorsReRgbPerc);
}
545339
function _generateInterpolatedColor() {
  const randIndicies = _getNextColorPair();
  const fraction = Math.random();
  const interpolatedColor = [];

  for (let i = 0; i < 4; i++) {
    interpolatedColor.push(
      Math.floor(
        fraction * distinctColors[randIndicies[0]][i] +
          (1.0 - fraction) * distinctColors[randIndicies[1]][i]
      )
    );
  }

  return interpolatedColor;
}
958538
function (colorMode) {
					var active = color.active, // local copies for YUI compressor
						clientPath = images.clientPath,
						hex = active.val('hex'),
						rgbMap,
						rgbBar;
					settings.color.mode = colorMode;
					switch (colorMode) {
					case 'h':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, 0);
							setAlpha.call($this, colorMapL1, 100);
							setImgLoc.call($this, colorMapL2, 260);
							setAlpha.call($this, colorMapL2, 100);
							setBG.call($this, colorBarDiv, 'transparent');
							setImgLoc.call($this, colorBarL1, 0);
							setAlpha.call($this, colorBarL1, 100);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL3, 260);
							setAlpha.call($this, colorBarL3, 100);
							setImgLoc.call($this, colorBarL4, 260);
							setAlpha.call($this, colorBarL4, 100);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 100,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 360
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('s'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 360 - active.val('h'), colorBar);
						break;
					case 's':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, -260);
							setImgLoc.call($this, colorMapL2, -520);
							setImgLoc.call($this, colorBarL1, -260);
							setImgLoc.call($this, colorBarL2, -520);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 100
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 100 - active.val('s'), colorBar);
						break;
					case 'v':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, '000000');
							setImgLoc.call($this, colorMapL1, -780);
							setImgLoc.call($this, colorMapL2, 260);
							setBG.call($this, colorBarDiv, hex);
							setImgLoc.call($this, colorBarL1, -520);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 100
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('s')
						}, colorMap);
						colorBar.val('y', 100 - active.val('v'), colorBar);
						break;
					case 'r':
						rgbMap = -1040;
						rgbBar = -780;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('b'),
							y: 255 - active.val('g')
						}, colorMap);
						colorBar.val('y', 255 - active.val('r'), colorBar);
						break;
					case 'g':
						rgbMap = -1560;
						rgbBar = -1820;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('b'),
							y: 255 - active.val('r')
						}, colorMap);
						colorBar.val('y', 255 - active.val('g'), colorBar);
						break;
					case 'b':
						rgbMap = -2080;
						rgbBar = -2860;
						colorMap.range('all', {
							minX: 0,
							maxX: 255,
							minY: 0,
							maxY: 255
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('r'),
							y: 255 - active.val('g')
						}, colorMap);
						colorBar.val('y', 255 - active.val('b'), colorBar);
						break;
					case 'a':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setImgLoc.call($this, colorMapL1, -260);
							setImgLoc.call($this, colorMapL2, -520);
							setImgLoc.call($this, colorBarL1, 260);
							setImgLoc.call($this, colorBarL2, 260);
							setAlpha.call($this, colorBarL2, 100);
							setImgLoc.call($this, colorBarL6, 0);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						colorMap.range('all', {
							minX: 0,
							maxX: 360,
							minY: 0,
							maxY: 100
						});
						colorBar.range('rangeY', {
							minY: 0,
							maxY: 255
						});
						if (active.val('ahex') == null) break;
						colorMap.val('xy', {
							x: active.val('h'),
							y: 100 - active.val('v')
						}, colorMap);
						colorBar.val('y', 255 - active.val('a'), colorBar);
						break;
					default:
						throw ('Invalid Mode');
						break;
					}
					switch (colorMode) {
					case 'h':
						break;
					case 's':
					case 'v':
					case 'a':
						setTimeout(function () {
							setAlpha.call($this, colorMapL1, 100);
							setAlpha.call($this, colorBarL1, 100);
							setImgLoc.call($this, colorBarL3, 260);
							setAlpha.call($this, colorBarL3, 100);
							setImgLoc.call($this, colorBarL4, 260);
							setAlpha.call($this, colorBarL4, 100);
						}, 0);
						break;
					case 'r':
					case 'g':
					case 'b':
						setTimeout(function () {
							setBG.call($this, colorMapDiv, 'transparent');
							setBG.call($this, colorBarDiv, 'transparent');
							setAlpha.call($this, colorBarL1, 100);
							setAlpha.call($this, colorMapL1, 100);
							setImgLoc.call($this, colorMapL1, rgbMap);
							setImgLoc.call($this, colorMapL2, rgbMap - 260);
							setImgLoc.call($this, colorBarL1, rgbBar - 780);
							setImgLoc.call($this, colorBarL2, rgbBar - 520);
							setImgLoc.call($this, colorBarL3, rgbBar);
							setImgLoc.call($this, colorBarL4, rgbBar - 260);
							setImgLoc.call($this, colorBarL6, 260);
							setAlpha.call($this, colorBarL6, 100);
						}, 0);
						break;
					}
					if (active.val('ahex') == null) return;
					activeColorChanged.call($this, active);
				}
821263
function colorRangeBox(selection, label) {
  selection
      .classed('form-row', true)
      .classed('form-group', true)
      .classed('align-items-center', true);
  selection.append('div')
      .classed('col-form-label', true)
      .classed('col-form-label-sm', true)
      .text(label);

  const minBox = selection.append('div');
  minBox.append('label').text('min');
  minBox.append('input').classed('min', true);

  const midBox = selection.append('div');
  midBox.append('label').text('mid');
  midBox.append('input').classed('mid', true);

  const maxBox = selection.append('div');
  maxBox.append('label').text('max');
  maxBox.append('input').classed('max', true);

  selection.on('change', () => {
    // avoid update by mousemove on the colorpicker
    d3.event.stopPropagation();
  });

  selection.selectAll('div')
      .classed('form-group', true)
      .classed('col-3', true)
      .classed('mb-0', true);

  selection.selectAll('label')
      .classed('col-form-label', true)
      .classed('col-form-label-sm', true)
      .classed('py-0', true);

  selection.selectAll('input')
      .classed('form-control', true)
      .classed('form-control-sm', true)
      .attr('type', 'color');
}
1357741
def generate_vector_numeric_map(self, numeric_property):
        """"""
        vector_stops = []
        
        function_type = getattr(self, '{}_function_type'.format(numeric_property))
        lookup_property = getattr(self, '{}_property'.format(numeric_property))
        numeric_stops = getattr(self, '{}_stops'.format(numeric_property))
        default = getattr(self, '{}_default'.format(numeric_property))

        if function_type == 'match':
            match_width = numeric_stops

        # if join data specified as filename or URL, parse JSON to list of Python dicts
        if type(self.data) == str:
            self.data = geojson_to_dict_list(self.data)

        for row in self.data:

            # map value to JSON feature using the numeric property
            value = numeric_map(row[lookup_property], numeric_stops, default)
            
            # link to vector feature using data_join_property (from JSON object)
            vector_stops.append([row[self.data_join_property], value])

        return vector_stops
718009
def colors_from_params(match, params)
      case params
      when Hash then colors_from_hash(match, params)
      when Symbol then color_from_symbol(match, params)
      end
    end
590921
function () {
                /* Color hooks registration: Colors are defaulted to white -- as opposed to black -- since colors that are
                   currently set to "transparent" default to their respective template below when color-animated,
                   and white is typically a closer match to transparent than black is. An exception is made for text ("color"),
                   which is almost always set closer to black than white. */
                for (var i = 0; i < CSS.Lists.colors.length; i++) {
                    var rgbComponents = (CSS.Lists.colors[i] === "color") ? "0 0 0 1" : "255 255 255 1";
                    CSS.Hooks.templates[CSS.Lists.colors[i]] = [ "Red Green Blue Alpha", rgbComponents ];
                }

                var rootProperty,
                    hookTemplate,
                    hookNames;

                /* In IE, color values inside compound-value properties are positioned at the end the value instead of at the beginning.
                   Thus, we re-arrange the templates accordingly. */
                if (IE) {
                    for (rootProperty in CSS.Hooks.templates) {
                        hookTemplate = CSS.Hooks.templates[rootProperty];
                        hookNames = hookTemplate[0].split(" ");

                        var defaultValues = hookTemplate[1].match(CSS.RegEx.valueSplit);

                        if (hookNames[0] === "Color") {
                            /* Reposition both the hook's name and its default value to the end of their respective strings. */
                            hookNames.push(hookNames.shift());
                            defaultValues.push(defaultValues.shift());

                            /* Replace the existing template for the hook's root property. */
                            CSS.Hooks.templates[rootProperty] = [ hookNames.join(" "), defaultValues.join(" ") ];
                        }
                    }
                }

                /* Hook registration. */
                for (rootProperty in CSS.Hooks.templates) {
                    hookTemplate = CSS.Hooks.templates[rootProperty];
                    hookNames = hookTemplate[0].split(" ");

                    for (var i in hookNames) {
                        var fullHookName = rootProperty + hookNames[i],
                            hookPosition = i;

                        /* For each hook, register its full name (e.g. textShadowBlur) with its root property (e.g. textShadow)
                           and the hook's position in its template's default value string. */
                        CSS.Hooks.registered[fullHookName] = [ rootProperty, hookPosition ];
                    }
                }
            }
1361070
function rangeToPattern(start, stop, options) {
  if (start === stop) {
    return { pattern: start, count: [], digits: 0 };
  }

  let zipped = zip(start, stop);
  let digits = zipped.length;
  let pattern = '';
  let count = 0;

  for (let i = 0; i < digits; i++) {
    let [startDigit, stopDigit] = zipped[i];

    if (startDigit === stopDigit) {
      pattern += startDigit;

    } else if (startDigit !== '0' || stopDigit !== '9') {
      pattern += toCharacterClass(startDigit, stopDigit, options);

    } else {
      count++;
    }
  }

  if (count) {
    pattern += options.shorthand === true ? '\\d' : '[0-9]';
  }

  return { pattern, count: [count], digits };
}
839950
function colorBox(selection, label) {
  selection
      .classed('form-row', true)
      .classed('align-items-center', true)
      .on('change', () => {
        // avoid update by mousemove on the colorpicker
        d3.event.stopPropagation();
      });
  selection.append('div')
      .classed('form-group', true)
      .classed('col-form-label', true)
      .classed('col-form-label-sm', true)
      .classed('col-4', true)
      .classed('mb-1', true)
      .text(label);
  selection.append('div')
      .classed('form-group', true)
      .classed('col-form-label', true)
      .classed('col-form-label-sm', true)
      .classed('col-4', true)
      .classed('mb-1', true)
    .append('input')
      .classed('form-control', true)
      .classed('form-control-sm', true)
      .attr('type', 'color');
}
74210
function formatArray(formatStr, args) {
    if (!formatStr) {
        return formatStr;
    }
    if (!args) {
        args = [];
    }
    return formatStr.replace(/{(\d+)(\:)?([^}]*)}/g, function (match, index, formatSeparator, formatExpr) {
        var resultValue = args[index];
        if (resultValue === undefined) {
            return match;
        }
        var funcDepth = 0;
        while (typeof resultValue === "function") {
            resultValue = resultValue(index, args, match, formatExpr, funcDepth++);
        }
        if (formatSeparator === ':') {
            // use format providers
            for (var i = 0; i < _formatProviders.length; i++) {
                var fp = _formatProviders[i];
                var fpCtx = new FormatProviderContext(formatExpr, resultValue);
                var fpResult;
                try {
                    fpResult = fp(fpCtx);
                }
                catch (e) {
                    continue;
                }
                if (fpCtx.handled) {
                    // handled: first wins
                    resultValue = fpResult;
                    break;
                }
            }
        }
        if (resultValue !== undefined) {
            return resultValue;
        }
        // not defined => return whole match string
        return match;
    });
}
1145303
function generateLegend(legendHelper) {
  var legendProps;
  if (
    !defined(legendHelper.tableColumn) ||
    !defined(legendHelper.tableColumn.values)
  ) {
    // If no table column is active, color it as if it were an ENUM with the maximum available colors.
    if (legendHelper.regionProvider) {
      legendHelper._binColors = buildEnumBinColors(
        legendHelper,
        legendHelper.regionProvider.regions,
        "top",
        undefined
      );
      legendProps = buildEnumLegendProps(
        legendHelper,
        legendHelper.regionProvider.regions
      );
    } else {
      legendProps = defined(legendHelper.name)
        ? {
            items: [
              {
                title: legendHelper.name,
                color: convertColorArrayToCssString(
                  legendHelper._noColumnColorArray
                )
              }
            ]
          }
        : undefined;
    }
  } else if (legendHelper.tableColumn.isEnum) {
    var tableColumnStyle = legendHelper.tableColumnStyle;
    var uniqueValues = legendHelper.tableColumn.uniqueValues;
    legendHelper._binColors = buildEnumBinColors(
      legendHelper,
      uniqueValues,
      tableColumnStyle.colorBinMethod,
      tableColumnStyle.colorBins
    );
    legendProps = buildEnumLegendProps(legendHelper, uniqueValues);
  } else {
    var colorMap = defaultValue(
      legendHelper.tableColumnStyle.colorMap,
      defaultScalarColorMap
    );
    var colorBins = defaultValue(
      legendHelper.tableColumnStyle.colorBins,
      defaultNumberOfColorBins
    );

    legendHelper._colorGradient = buildColorGradient(colorMap);
    legendHelper._binColors = buildBinColors(legendHelper, colorBins);
    legendProps = buildLegendProps(legendHelper, colorMap);
  }
  if (defined(legendProps)) {
    legendHelper._legend = new Legend(legendProps);
  } else {
    legendHelper._legend = null; // use null so that we know it tried and failed, so don't try again.
  }
}
750256
function(kmlColor) {
        var color = null;
        if (kmlColor) {
            var matches = kmlColor.match(this.regExes.kmlColor);
            if (matches) {
                color = {
                    color: '#' + matches[4] + matches[3] + matches[2],
                    opacity: parseInt(matches[1], 16) / 255
                };
            }
        }
        return color;
    }
857706
function make_color(aggregates, all, leaf_only) {
    let colorRange;
    if (aggregates.length >= 2) {
        colorRange = [Infinity, -Infinity];
        for (let series of all) {
            let colorvals = series["data"];
            for (let i = 1; i < colorvals.length; ++i) {
                if ((leaf_only && colorvals[i].leaf) || !leaf_only) {
                    colorRange[0] = Math.min(colorRange[0], colorvals[i].colorValue);
                    colorRange[1] = Math.max(colorRange[1], colorvals[i].colorValue);
                }
            }
            if (colorRange[0] * colorRange[1] < 0) {
                let cmax = Math.max(Math.abs(colorRange[0]), Math.abs(colorRange[1]));
                colorRange = [-cmax, cmax];
            }
        }
    }
    return colorRange;
}
1089053
function colorSyntaxExtension(editor) {
  const {colorSyntax = {}} = editor.options;
  const {preset, useCustomSyntax = false} = colorSyntax;

  editor.eventManager.listen('convertorAfterMarkdownToHtmlConverted', html => {
    let replacement;

    if (!useCustomSyntax) {
      replacement = html;
    } else {
      replacement
                = html.replace(colorSyntaxRx, (matched, p1, p2) => makeHTMLColorSyntaxAndTextRange(p2, p1).result);
    }

    return replacement;
  });

  editor.eventManager.listen('convertorAfterHtmlToMarkdownConverted', markdown => {
    const findRx = useCustomSyntax ? colorHtmlCompleteRx : colorHtmlRx;

    return markdown.replace(findRx, (founded, color, text) => {
      let replacement;

      if (color.match(decimalColorRx)) {
        color = changeDecColorsToHex(color);
      }

      if (!useCustomSyntax) {
        replacement = founded.replace(/ ?class="colour" ?/g, ' ').replace(decimalColorRx, color);
      } else {
        replacement = makeCustomColorSyntaxAndTextRange(text, color).result;
      }

      return replacement;
    });
  });

  if (!editor.isViewer() && editor.getUI().name === 'default') {
    editor.addCommand('markdown', {
      name: 'color',
      exec(mde, color) {
        const cm = mde.getEditor();
        const rangeFrom = cm.getCursor('from');
        const rangeTo = cm.getCursor('to');
        let replacedText;
        let replacedFrom;

        if (!color) {
          return;
        }

        if (!useCustomSyntax) {
          ({result: replacedText, from: replacedFrom}
                        = makeHTMLColorSyntaxAndTextRange(cm.getSelection(), color));
          cm.replaceSelection(replacedText);
        } else {
          ({result: replacedText, from: replacedFrom}
                        = makeCustomColorSyntaxAndTextRange(cm.getSelection(), color));
          cm.replaceSelection(replacedText);
        }

        cm.setSelection({
          line: rangeFrom.line,
          ch: rangeFrom.ch + replacedFrom
        }, {
          line: rangeTo.line,
          ch: rangeFrom.line === rangeTo.line ? rangeTo.ch + replacedFrom : rangeTo.ch
        });

        mde.focus();
      }
    });

    editor.addCommand('wysiwyg', {
      name: 'color',
      exec(wwe, color) {
        if (!color) {
          return;
        }

        const sq = wwe.getEditor();
        const tableSelectionManager = wwe.componentManager.getManager('tableSelection');
        if (sq.hasFormat('table') && tableSelectionManager.getSelectedCells().length) {
          tableSelectionManager.styleToSelectedCells(styleColor, color);

          const range = sq.getSelection();
          range.collapse(true);
          sq.setSelection(range);
        } else {
          styleColor(sq, color);
        }
      }
    });

    initUI(editor, preset);
  }
}
473055
function _generateLineMap (res, file) {
    if (res.errors && res.errors.length) {
        return;
    }
    var syntaxTree = res.syntaxTree, templates = [];
    // identify the templates in the syntax tree
    for (var i = 0; i < syntaxTree.length; i++) {
        if (syntaxTree[i].type === 'template') {
            templates.push(syntaxTree[i]);
        }
    }

    var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC
    var lineMap = [], pos = HEADER_SZ, template;
    var pos1 = -1; // position of the next template start
    var pos2 = -1; // position of the next template end
    var tplIdx = -1; // position of the current template

    for (var i = 0; i < (file.split(/\n/g).length + 1); i++) {
        if (i === 0 || i === pos2) {
            // end of current template: let's determine next pos1 and pos2
            tplIdx = (i === 0) ? 0 : tplIdx + 1;
            if (tplIdx < templates.length) {
                // there is another template
                template = templates[tplIdx];
                pos1 = template.startLine;
                pos2 = Math.max(template.endLine, pos1);
            } else {
                // last template has been found
                tplIdx = pos1 = pos2 = -1;
            }
            if (i === 0) {
                lineMap[0] = 0;
            }
            i++;
        }
        if (i === pos1) {
            for (var j = pos1; j < (pos2 + 1); j++) {
                // all lines are set to the template start
                lineMap[i] = pos;
                i++;
            }
            pos += nbrOfLinesInCompiledTemplate;
            i -= 2; // to enter the i===pos2 clause at next step
        } else {
            lineMap[i] = pos;
            pos++;
        }
    }
    return lineMap;
}