<commit_before>var AutoStyler = require('./auto-styler');
var _ = require('underscore');
var CategoryAutoStyler = AutoStyler.extend({
  getStyle: function () {
    var preservedWidth = this.getPreservedWidth();
    var style = '';
    var defColor = this.colors.getColorByCategory('Other');
    var stylesByGeometry = this.STYLE_TEMPLATE;
    var geometryType = this.layer.getGeometryType();
    if (geometryType) {
      var ramp = this._generateCategoryRamp(geometryType);
      style = stylesByGeometry[geometryType]
        .replace('{{ramp}}', ramp)
        .replace('{{layername}}', '#layer{');
    } else {
      for (var symbol in stylesByGeometry) {
        style += stylesByGeometry[symbol]
          .replace('{{layername}}', this._getLayerHeader(symbol))
          .replace('{{ramp}}', this._generateCategoryRamp(symbol));
      }
    }
    style = style.replace(/{{defaultColor}}/g, defColor);
    if (!_.isEmpty(preservedWidth)) {
      style = style.replace('{{markerWidth}}', preservedWidth);
    } else {
      style = style.replace('{{markerWidth}}', 7);
    }
    return style;
  },

  _generateCategoryRamp: function (sym) {
    var cats = this.dataviewModel.get('allCategoryNames');
    var geomMap = { polygon: 'polygon-fill', marker: 'marker-fill', line: 'line-color' };
    var ramp = cats.map(function (c, i) {
      var color = this.colors.getColorByCategory(c);
      return '[' + this.dataviewModel.get('column') + '=\'' + cats[i] + '\']{\n' + geomMap[sym] + ': ' + color + ';\n}';
    }.bind(this)).join('\n');
    return ramp;<commit_msg>replaces particular styles in category instead of replacing the whole thing<commit_after>var AutoStyler = require('./auto-styler');
var _ = require('underscore');
var CategoryAutoStyler = AutoStyler.extend({
  getStyle: function () {
    var style = this.layer.get('meta').cartocss;
    ['marker-fill', 'polygon-fill', 'line-color'].forEach(function (item) {
      style = style.replace(new RegExp('\\' + 's' + item + ':.*?;', 'g'), this._generateCategoryRamp(item));
    }.bind(this));
    return style;
  },

  _generateCategoryRamp: function (sym) {
    var ramp;
    var cats = this.dataviewModel.get('allCategoryNames');
    ramp = 'marker-fill: ' + this.colors.getColorByCategory('OTHER') + ';';
    ramp += cats.map(function (c, i) {
      var color = this.colors.getColorByCategory(c);
      return '[' + this.dataviewModel.get('column') + '=\'' + cats[i] + '\']{\n' + sym + ': ' + color + ';\n}';
    }.bind(this)).join('\n');
    return ramp;
{'fraction_non_alphanumeric': 0.18333333333333332, 'fraction_numerical': 0.0003968253968253968, 'mean_word_length': 3.5670289855072466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6065707', 'n_tokens_mistral': 814, 'n_tokens_neox': 793, 'n_words': 157}