Source: src/main/javascript/oracle/oj/ojdvt-base/ColorAttributeGroups.js

Oracle® JavaScript Extension Toolkit (JET)
1.1.2

E65298-01

/**
 * Creates a color attribute group handler that will generate color attribute values.
 * @param {Object} [matchRules] A map of key value pairs for categories and the 
 * matching attribute value e.g. {"soda" : "#336699", "water" : "#CC3300", "iced tea" : "#F7C808"}.
 * Attribute values listed in the matchRules object will be reserved only for the 
 * matching categories when getAttributeValue is called.  Note that not all colors
 * in the default color ramp will meet minimum contrast requirements for text.
 * @export
 * @constructor
 * @extends {oj.AttributeGroupHandler}
 */
oj.ColorAttributeGroupHandler = function(matchRules) {
  // Create the array of colors for this instance.
  this._attributeValues = [];
  
  if ($(document.body).hasClass('oj-hicontrast'))  {
    // High Contrast: CSS colors get overridden to all white or all black. Use the default colors instead.
    this._attributeValues = oj.ColorAttributeGroupHandler._DEFAULT_COLORS.slice();
  } 
  else {
    // Process the colors from the skin if not done already.
    if(!oj.ColorAttributeGroupHandler._colors) {
      oj.ColorAttributeGroupHandler._colors = [];
    
      // Process the colors from the CSS.
      var attrGpsDiv = $(document.createElement("div"));
      attrGpsDiv.attr("style", "display:none;");
      attrGpsDiv.attr("id", "attrGps");
      $(document.body).append(attrGpsDiv);
      for (var i = 0; i < oj.ColorAttributeGroupHandler._STYLE_CLASSES.length; i++) {
        var childDiv = $(document.createElement("div"));
        childDiv.addClass(oj.ColorAttributeGroupHandler._STYLE_CLASSES[i]);
        attrGpsDiv.append(childDiv);
        var color = childDiv.css('color');
        if (color)
          oj.ColorAttributeGroupHandler._colors.push(color);
      }
      attrGpsDiv.remove();
    }
    
    // Clone and use the processed colors.
    if (oj.ColorAttributeGroupHandler._colors.length > 0)
      this._attributeValues = oj.ColorAttributeGroupHandler._colors.slice();
    else
      this._attributeValues = oj.ColorAttributeGroupHandler._DEFAULT_COLORS.slice();
  }
  
  this.Init(matchRules);
}

oj.Object.createSubclass(oj.ColorAttributeGroupHandler, oj.AttributeGroupHandler, "oj.ColorAttributeGroupHandler");

/** @private */
oj.ColorAttributeGroupHandler._DEFAULT_COLORS = ['#267db3', '#68c182', '#fad55c',
                                                '#ed6647', '#8561c8', '#6ddbdb', 
                                                '#ffb54d', '#e371b2', '#47bdef', 
                                                '#a2bf39', '#a75dba', '#f7f37b'];

/** @private */
oj.ColorAttributeGroupHandler._STYLE_CLASSES = ['oj-dvt-category1',
  'oj-dvt-category2', 'oj-dvt-category3', 'oj-dvt-category4',
  'oj-dvt-category5', 'oj-dvt-category6', 'oj-dvt-category7',
  'oj-dvt-category8', 'oj-dvt-category9', 'oj-dvt-category10',
  'oj-dvt-category11', 'oj-dvt-category12'];

/** @private */
oj.ColorAttributeGroupHandler._colors = null;  
  
//** @inheritdoc */
oj.ColorAttributeGroupHandler.prototype.getValueRamp = function() {
  return this._attributeValues.slice();
}