Browse Source

export models and add callbacks

merge-requests/20/merge
vargburz 3 years ago
parent
commit
d2bf2fa258
  1. 9
      src/index.ts
  2. 18
      src/models/options.ts
  3. 13
      src/models/series.ts
  4. 2
      src/types.ts

9
src/index.ts

@ -1,7 +1,7 @@
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; import VueChartwerkPodMixin from './VueChartwerkPodMixin';
import { PodState } from './models/state';
import { Grid } from './components/grid'; import { Grid } from './components/grid';
import { PodState } from './models/state';
import { CoreSeries } from './models/series'; import { CoreSeries } from './models/series';
import { CoreOptions } from './models/options'; import { CoreOptions } from './models/options';
@ -9,7 +9,7 @@ import styles from './css/style.css';
import { import {
Margin, Margin,
CoreSerie, Serie,
Options, Options,
TimeFormat, TimeFormat,
BrushOrientation, BrushOrientation,
@ -38,7 +38,7 @@ const DEFAULT_TICK_COUNT = 4;
const DEFAULT_TICK_SIZE = 2; const DEFAULT_TICK_SIZE = 2;
const MILISECONDS_IN_MINUTE = 60 * 1000; const MILISECONDS_IN_MINUTE = 60 * 1000;
abstract class ChartwerkPod<T extends CoreSerie, O extends Options> { abstract class ChartwerkPod<T extends Serie, O extends Options> {
protected coreSeries: CoreSeries<T>; protected coreSeries: CoreSeries<T>;
protected coreOptions: CoreOptions<O>; protected coreOptions: CoreOptions<O>;
@ -888,7 +888,8 @@ abstract class ChartwerkPod<T extends CoreSerie, O extends Options> {
export { export {
ChartwerkPod, VueChartwerkPodMixin, ChartwerkPod, VueChartwerkPodMixin,
Margin, CoreSerie, Options, TimeFormat, BrushOrientation, PanOrientation, PodState, CoreSeries, CoreOptions,
Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation,
AxesOptions, AxisOption, AxesOptions, AxisOption,
AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent,
palette palette

18
src/models/options.ts

@ -207,4 +207,22 @@ export class CoreOptions<O extends Options> {
this._options.eventsCallbacks.zoomOut(centers); 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();
}
}
} }

13
src/models/series.ts

@ -1,4 +1,4 @@
import { CoreSerie, yAxisOrientation } from '../types'; import { Serie, yAxisOrientation } from '../types';
import { palette } from '../colors'; import { palette } from '../colors';
import lodashDefaultsDeep from 'lodash/defaultsDeep'; import lodashDefaultsDeep from 'lodash/defaultsDeep';
@ -22,9 +22,9 @@ const SERIE_DEFAULTS = {
color: undefined, color: undefined,
}; };
export class CoreSeries<T extends CoreSerie> { export class CoreSeries<T extends Serie> {
_series: Array<T> = []; _series: Array<T> = [];
_defaults: CoreSerie = SERIE_DEFAULTS; _coreDefaults: Serie = SERIE_DEFAULTS;
constructor(series: T[]) { constructor(series: T[]) {
this.setSeries(series); this.setSeries(series);
@ -48,13 +48,18 @@ export class CoreSeries<T extends CoreSerie> {
} }
protected fillDefaults(serie: T, idx: number): T { protected fillDefaults(serie: T, idx: number): T {
let defaults = lodashCloneDeep(this._defaults); let defaults = lodashCloneDeep(this.defaults);
defaults.color = palette[idx % palette.length]; defaults.color = palette[idx % palette.length];
defaults.idx = idx; defaults.idx = idx;
lodashDefaultsDeep(serie, defaults); lodashDefaultsDeep(serie, defaults);
return serie; return serie;
} }
// this getter can be overrited in Pod
protected get defaults(): Serie {
return this._coreDefaults;
}
get isSeriesAvailable(): boolean { get isSeriesAvailable(): boolean {
return this.visibleSeries.length > 0; return this.visibleSeries.length > 0;
} }

2
src/types.ts

@ -4,7 +4,7 @@ export type Margin = { top: number, right: number, bottom: number, left: number
export type Timestamp = number; export type Timestamp = number;
// TODO: Pods can render not only "time" series // TODO: Pods can render not only "time" series
export type CoreSerie = { export type Serie = {
target: string, target: string,
datapoints: [Timestamp, number][], datapoints: [Timestamp, number][],
idx?: number, idx?: number,

Loading…
Cancel
Save