static/js/control.js
/**
 * Update color map based on selected field and palette.
 * @function updateColorMap
 * @param {Object} mo - master object
 * @todo add feature (treat as number)
 */
Update color map based on selected field and palette.
@function updateColorMap
@param {Object} mo - master object
@todo add feature (treat as number)
Update color map based on selected field and palette . @function updateColorMap @param { Object } mo - master object @todo add feature ( treat as number )
function updateColorMap(mo) {
  var icol = mo.view.color.i;
  if (!icol) return;
  if (mo.data.types[icol] !== 'category') return;
  mo.view.color.discmap = {};
  var cats = {};
  for (var i = 0; i < mo.data.df.length; i++) {
    var val = mo.data.df[i][icol];
    if (val === undefined || val === null) continue;
    cats[val[0]] = (cats[val[0]] || 0) + 1;
  }
  cats = Object.keys(cats).map(function (key) { return [key, cats[key]]; });
  cats.sort(function (a, b) { return b[1] - a[1]; });
  var ncolor = Math.min(mo.view.ncolor, cats.length);
  var palette = PALETTES[mo.view.discpal];
  var m = palette.length;
  for (var i = 0; i < ncolor; i++) {
    mo.view.color.discmap[cats[i][0]] = palette[i % m];
  }
}
function updateColorMap ( mo ) { var icol = mo . view . color . i ; if ( ! icol ) return ; if ( mo . data . types [ icol ] !== 'category' ) return ; mo . view . color . discmap = { } ; var cats = { } ; for ( var i = 0 ; i < mo . data . df . length ; i ++ ) { var val = mo . data . df [ i ] [ icol ] ; if ( val === undefined || val === null ) continue ; cats [ val [ 0 ] ] = ( cats [ val [ 0 ] ] || 0 ) + 1 ; } cats = Object . keys ( cats ) . map ( function ( key ) { return [ key , cats [ key ] ] ; } ) ; cats . sort ( function ( a , b ) { return b [ 1 ] - a [ 1 ] ; } ) ; var ncolor = Math . min ( mo . view . ncolor , cats . length ) ; var palette = PALETTES [ mo . view . discpal ] ; var m = palette . length ; for ( var i = 0 ; i < ncolor ; i ++ ) { mo . view . color . discmap [ cats [ i ] [ 0 ] ] = palette [ i % m ] ; } }
Update color map based on selected field and palette.
Update color map based on selected field and palette .
// get categories and their frequencies // convert object to array of key: value pairs // sort by frequency from high to low // number of colors to show // obtain colors from palette (allow repeats if palette is shorter)