Browse Source

fix core

pull/2/head
vargburz 3 years ago
parent
commit
b314ff21ef
  1. 6
      src/index.ts
  2. 10
      src/models/options.ts
  3. 10
      src/models/series.ts

6
src/index.ts

@ -2,8 +2,8 @@ import VueChartwerkPodMixin from './VueChartwerkPodMixin';
import { Grid } from './components/grid'; import { Grid } from './components/grid';
import { PodState } from './models/state'; import { PodState } from './models/state';
import { CoreSeries } from './models/series'; import { CoreSeries, CORE_SERIE_DEFAULTS } from './models/series';
import { CoreOptions } from './models/options'; import { CoreOptions, CORE_DEFAULT_OPTIONS } from './models/options';
import styles from './css/style.css'; import styles from './css/style.css';
@ -888,7 +888,7 @@ abstract class ChartwerkPod<T extends Serie, O extends Options> {
export { export {
ChartwerkPod, VueChartwerkPodMixin, ChartwerkPod, VueChartwerkPodMixin,
PodState, CoreSeries, CoreOptions, PodState, CoreSeries, CoreOptions, CORE_SERIE_DEFAULTS, CORE_DEFAULT_OPTIONS,
Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation, Margin, Serie, Options, TimeFormat, BrushOrientation, PanOrientation,
AxesOptions, AxisOption, AxesOptions, AxisOption,
AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent,

10
src/models/options.ts

@ -52,7 +52,7 @@ const DEFAULT_CROSSHAIR_OPTIONS = {
const DEFAULT_MARGIN: Margin = { top: 30, right: 20, bottom: 20, left: 30 }; const DEFAULT_MARGIN: Margin = { top: 30, right: 20, bottom: 20, left: 30 };
const DEFAULT_OPTIONS: Options = { export const CORE_DEFAULT_OPTIONS: Options = {
zoomEvents: { zoomEvents: {
mouse: { mouse: {
zoom: { zoom: {
@ -99,7 +99,7 @@ const DEFAULT_OPTIONS: Options = {
export class CoreOptions<O extends Options> { export class CoreOptions<O extends Options> {
_options: O; _options: O;
_coreDefaults: Options = DEFAULT_OPTIONS; protected podDefaults?: Partial<O>;
constructor(options: O) { constructor(options: O) {
this.setOptions(options); this.setOptions(options);
@ -110,12 +110,12 @@ export class CoreOptions<O extends Options> {
} }
protected setOptions(options: O): void { protected setOptions(options: O): void {
this._options = lodashDefaultsDeep(lodashCloneDeep(options), this.defaults); this._options = lodashDefaultsDeep(lodashCloneDeep(options), this.getDefaults());
} }
// this getter can be overrited in Pod // this getter can be overrited in Pod
protected get defaults(): Options { protected getDefaults(): Partial<O> {
return this._coreDefaults; return lodashDefaultsDeep(this.podDefaults, CORE_DEFAULT_OPTIONS);
} }
get allOptions(): O { get allOptions(): O {

10
src/models/series.ts

@ -13,7 +13,7 @@ import lodashIsNil from 'lodash/isNil';
import lodashIncludes from 'lodash/includes'; import lodashIncludes from 'lodash/includes';
const SERIE_DEFAULTS = { export const CORE_SERIE_DEFAULTS = {
alias: '', alias: '',
target: '', target: '',
visible: true, visible: true,
@ -27,7 +27,7 @@ const SERIE_DEFAULTS = {
export class CoreSeries<T extends Serie> { export class CoreSeries<T extends Serie> {
_series: Array<T> = []; _series: Array<T> = [];
_coreDefaults: Serie = SERIE_DEFAULTS; protected podDefaults?: Partial<T>;
constructor(series: T[]) { constructor(series: T[]) {
this.setSeries(series); this.setSeries(series);
@ -51,7 +51,7 @@ export class CoreSeries<T extends Serie> {
} }
protected fillDefaults(serie: T, idx: number): T { protected fillDefaults(serie: T, idx: number): T {
let defaults = lodashCloneDeep(this.defaults); let defaults = lodashCloneDeep(this.getDefaults());
defaults.color = palette[idx % palette.length]; defaults.color = palette[idx % palette.length];
defaults.idx = idx; defaults.idx = idx;
lodashDefaultsDeep(serie, defaults); lodashDefaultsDeep(serie, defaults);
@ -59,8 +59,8 @@ export class CoreSeries<T extends Serie> {
} }
// this getter can be overrited in Pod // this getter can be overrited in Pod
protected get defaults(): Serie { protected getDefaults(): Partial<T> {
return this._coreDefaults; return lodashDefaultsDeep(this.podDefaults, CORE_SERIE_DEFAULTS);
} }
private _isSerieEmpty(serie: T): boolean { private _isSerieEmpty(serie: T): boolean {

Loading…
Cancel
Save