all files / src/components/ ParallelCoordinates.js

66.67% Statements 42/63
88.57% Branches 31/35
53.33% Functions 8/15
18.18% Lines 4/22
8 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 45 46                                                                                      
import VisualizationComponent from '../core/VisualizationComponent';
import $ from 'jquery';
 
export default class ParallelCoordinates extends VisualizationComponent {
  constructor (el, dataRoot, 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});
    };
 
    $(el).on('mousedown', mouseHandler('mousedown'));
    $(el).on('mousemove', mouseHandler('mousemove'));
    $(el).on('mouseup', mouseHandler('mouseup'));
  }
 
  render (data) {
    this.pc.render();
  }
 
  data (data) {
    this.pc.updateAxisList(data);
  }
 
  fetchHistogram (var1, var2) {
    return $.getJSON([this.dataRoot, var1, var2].join('/') + '.json');
  }
}