From d2bf2fa258da8fc530246e0a4d775f49bd864cf4 Mon Sep 17 00:00:00 2001 From: vargburz Date: Tue, 24 May 2022 14:25:05 +0300 Subject: [PATCH] export models and add callbacks --- src/index.ts | 9 +++++---- src/models/options.ts | 18 ++++++++++++++++++ src/models/series.ts | 13 +++++++++---- src/types.ts | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4cbfa32..5d91ea1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import VueChartwerkPodMixin from './VueChartwerkPodMixin'; -import { PodState } from './models/state'; import { Grid } from './components/grid'; +import { PodState } from './models/state'; import { CoreSeries } from './models/series'; import { CoreOptions } from './models/options'; @@ -9,7 +9,7 @@ import styles from './css/style.css'; import { Margin, - CoreSerie, + Serie, Options, TimeFormat, BrushOrientation, @@ -38,7 +38,7 @@ const DEFAULT_TICK_COUNT = 4; const DEFAULT_TICK_SIZE = 2; const MILISECONDS_IN_MINUTE = 60 * 1000; -abstract class ChartwerkPod { +abstract class ChartwerkPod { protected coreSeries: CoreSeries; protected coreOptions: CoreOptions; @@ -888,7 +888,8 @@ abstract class ChartwerkPod { export { ChartwerkPod, VueChartwerkPodMixin, - Margin, CoreSerie, Options, TimeFormat, BrushOrientation, PanOrientation, + PodState, CoreSeries, CoreOptions, + Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation, AxesOptions, AxisOption, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent, palette diff --git a/src/models/options.ts b/src/models/options.ts index 6627586..dd974d7 100644 --- a/src/models/options.ts +++ b/src/models/options.ts @@ -207,4 +207,22 @@ export class CoreOptions { this._options.eventsCallbacks.zoomOut(centers); } } + + callbackSharedCrosshairMove(event: { datapoints, eventX, eventY }): void { + if(has(this._options.eventsCallbacks, 'sharedCrosshairMove')) { + this._options.eventsCallbacks.sharedCrosshairMove(event); + } + } + + callbackMouseMove(event): void { + if(has(this._options.eventsCallbacks, 'mouseMove')) { + this._options.eventsCallbacks.mouseMove(event); + } + } + + callbackMouseOut(): void { + if(has(this._options.eventsCallbacks, 'mouseOut')) { + this._options.eventsCallbacks.mouseOut(); + } + } } diff --git a/src/models/series.ts b/src/models/series.ts index 95a6b02..16ca69b 100644 --- a/src/models/series.ts +++ b/src/models/series.ts @@ -1,4 +1,4 @@ -import { CoreSerie, yAxisOrientation } from '../types'; +import { Serie, yAxisOrientation } from '../types'; import { palette } from '../colors'; import lodashDefaultsDeep from 'lodash/defaultsDeep'; @@ -22,9 +22,9 @@ const SERIE_DEFAULTS = { color: undefined, }; -export class CoreSeries { +export class CoreSeries { _series: Array = []; - _defaults: CoreSerie = SERIE_DEFAULTS; + _coreDefaults: Serie = SERIE_DEFAULTS; constructor(series: T[]) { this.setSeries(series); @@ -48,13 +48,18 @@ export class CoreSeries { } protected fillDefaults(serie: T, idx: number): T { - let defaults = lodashCloneDeep(this._defaults); + let defaults = lodashCloneDeep(this.defaults); defaults.color = palette[idx % palette.length]; defaults.idx = idx; lodashDefaultsDeep(serie, defaults); return serie; } + // this getter can be overrited in Pod + protected get defaults(): Serie { + return this._coreDefaults; + } + get isSeriesAvailable(): boolean { return this.visibleSeries.length > 0; } diff --git a/src/types.ts b/src/types.ts index e156fb8..11dfbac 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,7 +4,7 @@ export type Margin = { top: number, right: number, bottom: number, left: number export type Timestamp = number; // TODO: Pods can render not only "time" series -export type CoreSerie = { +export type Serie = { target: string, datapoints: [Timestamp, number][], idx?: number,