src/PlotMarkers.ts

   1/**

   2 * ## PlotMarkers

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

   4 * as {@link Series.Series.plot 'markers'}. 

   5 * The `cols` name array starts with 

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

   7 * 

   8 * 

   9 * script.js'>

  10 * let series = {

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

  12 *    rows:[

  13 *      [-1, 0.2],

  14 *      [0.2, 0.7],

  15 *      [0.4, -0.2],

  16 *      [0.6, 0],

  17 *      [0.8, 0.5],

  18 *      [1, 0.7]

  19 * ]};

  20 * 

  21 * m.mount(root, { 

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

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

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

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

  26 *      }})

  27 * });

  28 *

  29 * 

  30 * 

  31 */

  32

  33/** */

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

  35export type Vnode = typeof m.Vnode;

  36import { Data }     from 'hsdatab';

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

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

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

  40

  41export class PlotMarkers extends Plot { 

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

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

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

  45        const l = series.l? data.colNumber(series.l) : undefined;

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

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

  48        return [

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

  50            (l===undefined)? undefined :

  51                this.drawLabel(clipID, data.getData(), x, y, l, scales, series)

  52        ];

  53    }

  54}

  55