getDataAtEvent.class.ts 2.18 KB
Newer Older
1
2
import { BaseChart } from '../';
import { EventHandler } from '../types/eventHandler.interface';
3
4
5
import { makeList } from '../utility/makeList.method';
import { GistBehavior } from './gistBehavior.class';
import { LimiterType } from "../types/limiterType.type";
6
import { DataPoint } from '../classes/datapoint.class';
7
8


9
export type supportedEventType = 'dblclick' | 'click' | 'mousedown' | 'mousemove' | 'mouseout' | 'mouseover' | 'mouseup';
10
11
12
13
14
15
16
/**
 * Adds a mouse event to a gist chart that will fire when the given event name fires and will call a function with data at the point given
 *
 * @export
 * @class GetDataAtMouseEvent
 */
export class GetDataAtMouseEvent extends GistBehavior {
17
18
19
20
21
22
23
24
    /**
     *Creates an instance of GetDataAtMouseEvent.
     * @param {(supportedEventType | supportedEventType[])} 'dblclick' | 'click' | 'mousedown' | 'mousemove' | 'mouseout' | 'mouseover' | 'mouseup'
     * @param {(EventHandler | EventHandler[])} eventHandlers Define what to do when the event happens
     * @param {number} [throttleTime=250]  How often this event can happen
     * @param {LimiterType} [limiter='throttle'] 'throttle' will ensure the event will wait throttleTime, before firing again. 'debounce' will wait throttletime without a repeat event to fire.
     * @memberof GetDataAtMouseEvent
     */
25
26
27
    constructor(
        eventNames: supportedEventType | supportedEventType[],
        eventHandlers: EventHandler | EventHandler[],
28
        throttleTime: number = 250,
29
        limiter: LimiterType = 'throttle' ) {
30
        super( eventNames, eventHandlers, throttleTime, limiter );
31
32
33
34
    }

    _activate(): void {
        const me = this;
35
        let reportList: Array<{ dpl: DataPoint[], chart: BaseChart }> ;
36

37
38
39
40
41
42
43
44
45
46
47
        me.eventHandlers.forEach( ( eh ) => {
            reportList = [];
            makeList( eh.chart )
                .filter( chart => chart !== undefined && chart.isActive )
                .forEach( chart => {
                    reportList.push( {
                        dpl: chart._implementation.getDataAtCoord( me.currentX, me.currentY ),
                        chart: chart
                    } );
                } );
            eh.onEvent( reportList, me.currentEvent );
48
49
50
        } );
    }
}