static/js/control.js
/**
 * Let user draw polygon to select a region of data points.
 * @function polygonSelect
 * @param {Object} mo - master object
 */
Let user draw polygon to select a region of data points.
@function polygonSelect
@param {Object} mo - master object
Let user draw polygon to select a region of data points . @function polygonSelect @param { Object } mo - master object
function polygonSelect(mo) {
  var data = mo.data;
  var view = mo.view;
  var stat = mo.stat;
  var rena = mo.rena;
  var oray = mo.oray;
  var btn = document.getElementById('polygon-btn');
  var title = btn.title;
  btn.title = btn.getAttribute('data-title');
  btn.setAttribute('data-title', title);
  btn.classList.toggle('pressed');
  if (!stat.drawing) {
    stat.polygon = [];
    stat.drawing = true;
  }
  else {
    oray.getContext('2d').clearRect(0, 0, oray.width, oray.height);
    var indices = [];
    var hasMask = (Object.keys(mo.mask).length > 0);
    for (var i = 0; i < data.df.length; i++) {
      if (hasMask && i in mo.mask) continue;
      var datum = data.df[i];
      var x = ((scaleNum(datum[view.x.i], view.x.scale) - view.x.min) /
        (view.x.max - view.x.min) - 0.5) * rena.width;
      var y = ((view.y.max - scaleNum(datum[view.y.i], view.y.scale)) /
        (view.y.max - view.y.min) - 0.5) * rena.height;
      if (pnpoly(x, y, stat.polygon)) indices.push(i);
    }
    stat.polygon = [];
    stat.drawing = false;
    if (indices.length > 0) {
      treatSelection(indices, stat.selmode, stat.masking, mo);
    }
  }
}
function polygonSelect ( mo ) { var data = mo . data ; var view = mo . view ; var stat = mo . stat ; var rena = mo . rena ; var oray = mo . oray ; var btn = document . getElementById ( 'polygon-btn' ) ; var title = btn . title ; btn . title = btn . getAttribute ( 'data-title' ) ; btn . setAttribute ( 'data-title' , title ) ; btn . classList . toggle ( 'pressed' ) ; if ( ! stat . drawing ) { stat . polygon = [ ] ; stat . drawing = true ; } else { oray . getContext ( '2d' ) . clearRect ( 0 , 0 , oray . width , oray . height ) ; var indices = [ ] ; var hasMask = ( Object . keys ( mo . mask ) . length > 0 ) ; for ( var i = 0 ; i < data . df . length ; i ++ ) { if ( hasMask && i in mo . mask ) continue ; var datum = data . df [ i ] ; var x = ( ( scaleNum ( datum [ view . x . i ] , view . x . scale ) - view . x . min ) / ( view . x . max - view . x . min ) - 0.5 ) * rena . width ; var y = ( ( view . y . max - scaleNum ( datum [ view . y . i ] , view . y . scale ) ) / ( view . y . max - view . y . min ) - 0.5 ) * rena . height ; if ( pnpoly ( x , y , stat . polygon ) ) indices . push ( i ) ; } stat . polygon = [ ] ; stat . drawing = false ; if ( indices . length > 0 ) { treatSelection ( indices , stat . selmode , stat . masking , mo ) ; } } }
Let user draw polygon to select a region of data points.
Let user draw polygon to select a region of data points .
// change button appearance // start drawing // finish drawing // treat selection