all files / candela/components/ ParallelCoordinates.js

64.18% Statements 43/67
83.78% Branches 31/37
57.14% Functions 8/14
20.83% Lines 5/24
9 statements, 2 functions, 16 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                                
import VisComponent from '../VisComponent';
import $ from 'jquery';
 
export default class ParallelCoordinates extends VisComponent {
  constructor (el, {dataRoot, fields, width, height}) {
    super(el);
    this.dataRoot = dataRoot;
 
    if (width && height) {
      $(el).attr('width', width);
      $(el).attr('height', height);
    }
 
    let PC = require('./../../external/pc');
 
    this.pc = new PC(this.el, (var1, var2, callback) => {
      this.fetchHistogram(var1, var2).then(callback);
    });
 
    let mouseHandler = action => e => {
      let rect = this.el.getBoundingClientRect();
      let x = e.clientX - rect.left;
      let y = e.clientY - rect.top;
 
      this.pc.mouseHandler({x, y, action});
    };
 
    this.pc.updateAxisList(fields);
 
    $(el).on('mousedown', mouseHandler('mousedown'));
    $(el).on('mousemove', mouseHandler('mousemove'));
    $(el).on('mouseup', mouseHandler('mouseup'));
  }
 
  render (data) {
    this.pc.render();
  }
 
  fetchHistogram (var1, var2) {
    return $.getJSON([this.dataRoot, var1, var2].join('/') + '.json');
  }
}