static/js/display.js
/**
 * Update color map based on selected field and palette.
 * @function updateColorMap
 * @param {Object} mo - main object
 * @todo add feature (treat as number)
 */
Update color map based on selected field and palette.
@function updateColorMap
@param {Object} mo - main object
@todo add feature (treat as number)
Update color map based on selected field and palette . @function updateColorMap @param { Object } mo - main object @todo add feature ( treat as number )
function updateColorMap(mo) {
  const icol = mo.view.color.i;
  if (!icol) return;
  if (mo.cols.types[icol] !== 'cat') return;
  let cats = {};
  const C = mo.data[icol];
  const n = C.length;
  let val;
  for (let i = 0; i < n; i++) {
    val = C[i];
    if (!val) continue;
    cats[val] = (cats[val] || 0) + 1;
  }
  cats = Object.keys(cats).map(key => [key, cats[key]]);
  cats.sort((a, b) => b[1] - a[1]);
  const ncolor = Math.min(mo.view.ncolor, cats.length);
  const palette = PALETTES[mo.view.discpal];
  const m = palette.length;
  const res = {};
  for (let i = 0; i < ncolor; i++) {
    res[cats[i][0]] = palette[i % m];
  }
  mo.view.color.discmap = res;
}
function updateColorMap ( mo ) { const icol = mo . view . color . i ; if ( ! icol ) return ; if ( mo . cols . types [ icol ] !== 'cat' ) return ; let cats = { } ; const C = mo . data [ icol ] ; const n = C . length ; let val ; for ( let i = 0 ; i < n ; i ++ ) { val = C [ i ] ; if ( ! val ) continue ; cats [ val ] = ( cats [ val ] || 0 ) + 1 ; } cats = Object . keys ( cats ) . map ( key => [ key , cats [ key ] ] ) ; cats . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ; const ncolor = Math . min ( mo . view . ncolor , cats . length ) ; const palette = PALETTES [ mo . view . discpal ] ; const m = palette . length ; const res = { } ; for ( let i = 0 ; i < ncolor ; i ++ ) { res [ cats [ i ] [ 0 ] ] = palette [ i % m ] ; } mo . view . color . discmap = res ; }
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)