all files / src/components/ VCharts.js

74.24% Statements 49/66
89.19% Branches 33/37
69.23% Functions 9/13
26.32% Lines 5/19
13 statements, 3 functions, 18 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                
import VisualizationComponent from '../core/VisualizationComponent';
import vcharts from '../external/vcharts/src';
 
export default class LineChart extends VisualizationComponent {
  constructor (el, data) {
    super(el);
 
    let values = data.map((x) => x[1]);
 
    let minY = Math.min(...values);
    if (minY === -Infinity) {
      minY = 0;
    }
    this.minY = minY;
 
    let maxY = Math.max(...values);
    if (maxY === Infinity) {
      maxY = 0;
    }
 
    maxY += (maxY - minY) * 0.20;
    this.maxY = maxY;
 
    this.data(data);
  }
 
  data (data) {
    this.chart = vcharts.chart('xy', {
      el: this.el,
      series: [
        {
          name: 'series1',
          values: data,
          x: '0',
          y: '1',
          color: 'darkslategray',
          line: true,
          point: true
        }
      ],
      xAxis: {
        title: 'X',
        type: 'time'
      },
      yAxis: {
        title: 'Y',
        zoom: false,
        pan: false,
        domain: [this.minY, this.maxY]
      },
      padding: {
        top: 100,
        bottom: 100,
        left: 100,
        right: 100
      }
    });
  }
 
  render () {
    this.chart.update();
    this.emit('render');
  }
}
 
export default LineChart;