src/PlotLine.ts

   1/**

   2 * ## PlotLine

   3 * Plots data as a line by configuring the series' `type` 

   4 * as {@link Series.Series.plot 'line'}. The `cols` name array starts with 

   5 * the x-value column, followed by the y-column.

   6 * 

   7 * 

   8 * script.js'>

   9 * let series = {

  10 *    colNames:['time', 'volume'],

  11 *    rows:[

  12 *      [-1, 0.2],

  13 *      [0.2, 0.7],

  14 *      [0.4, -0.2],

  15 *      [0.6, 0],

  16 *      [0.8, 0.5],

  17 *      [1, 0.7]

  18 * ]};

  19 * 

  20 * m.mount(root, { 

  21 *      view:() => m(hsgraph.Graph, {cfgFn: cfg => {

  22 *          cfg.chart.title.text          = 'Simple Example';

  23 *          cfg.series.data   = [series];

  24 *          cfg.series.series = [{ x:'time', y:'volume' }];

  25 *      }})

  26 * });

  27 *

  28 * 

  29 * 

  30 */

  31

  32/** */

  33export const m = require("mithril");

  34export type Vnode = typeof m.Vnode;

  35import { Data }     from 'hsdatab';

  36import { XYScale }  from './AxesTypes';

  37import { Plot }     from './Plot';

  38import { SeriesDef }from './Series';

  39

  40export class PlotLine extends Plot { 

  41    plot(data:Data, series:SeriesDef, scales:XYScale, i:number, clipID:string): Vnode[] {

  42        const x = data.colNumber(series.x);

  43        const y = data.colNumber(series.y);

  44        if (x===undefined) { return m('.error',''); }

  45        if (y===undefined) { return m('.error',''); }

  46        return [

  47            this.drawLine(clipID, data.getData(), x, y, scales, series.style, series.y),

  48            this.drawMarker(clipID, data.getData(), x, y, scales, series.style, series.y)

  49        ];

  50    }

  51}

  52