Browse Source

rename EventsCallbacs to Events

rename-eventCallbacs-to-events-#26-2
glitch4347 8 months ago
parent
commit
c05d989347
  1. 30
      src/VueChartwerkPodMixin.ts
  2. 3
      src/index.ts
  3. 61
      src/models/options.ts

30
src/VueChartwerkPodMixin.ts

@ -50,41 +50,45 @@ export default {
this.render(); this.render();
}, },
appendEvents() { appendEvents() {
if(this.options.eventsCallbacks === undefined) { if(this.options.events === undefined) {
this.options.eventsCallbacks = {} if(this.options.eventsCallbacks !== undefined) {
this.options.events = this.options.eventsCallbacks
} else {
this.options.events = {};
}
} }
if(has(this.$listeners, 'zoomIn')) { if(has(this.$listeners, 'zoomIn')) {
this.options.eventsCallbacks.zoomIn = this.zoomIn.bind(this); this.options.events.zoomIn = this.zoomIn.bind(this);
} }
if(has(this.$listeners, 'zoomOut')) { if(has(this.$listeners, 'zoomOut')) {
this.options.eventsCallbacks.zoomOut = this.zoomOut.bind(this); this.options.events.zoomOut = this.zoomOut.bind(this);
} }
if(has(this.$listeners, 'mouseMove')) { if(has(this.$listeners, 'mouseMove')) {
this.options.eventsCallbacks.mouseMove = this.mouseMove.bind(this); this.options.events.mouseMove = this.mouseMove.bind(this);
} }
if(has(this.$listeners, 'mouseOut')) { if(has(this.$listeners, 'mouseOut')) {
this.options.eventsCallbacks.mouseOut = this.mouseOut.bind(this); this.options.events.mouseOut = this.mouseOut.bind(this);
} }
if(has(this.$listeners, 'onLegendClick')) { if(has(this.$listeners, 'onLegendClick')) {
this.options.eventsCallbacks.onLegendClick = this.onLegendClick.bind(this); this.options.events.onLegendClick = this.onLegendClick.bind(this);
} }
if(has(this.$listeners, 'panningEnd')) { if(has(this.$listeners, 'panningEnd')) {
this.options.eventsCallbacks.panningEnd = this.panningEnd.bind(this); this.options.events.panningEnd = this.panningEnd.bind(this);
} }
if(has(this.$listeners, 'panning')) { if(has(this.$listeners, 'panning')) {
this.options.eventsCallbacks.panning = this.panning.bind(this); this.options.events.panning = this.panning.bind(this);
} }
if(has(this.$listeners, 'contextMenu')) { if(has(this.$listeners, 'contextMenu')) {
this.options.eventsCallbacks.contextMenu = this.contextMenu.bind(this); this.options.events.contextMenu = this.contextMenu.bind(this);
} }
if(has(this.$listeners, 'sharedCrosshairMove')) { if(has(this.$listeners, 'sharedCrosshairMove')) {
this.options.eventsCallbacks.sharedCrosshairMove = this.sharedCrosshairMove.bind(this); this.options.events.sharedCrosshairMove = this.sharedCrosshairMove.bind(this);
} }
if(has(this.$listeners, 'renderStart')) { if(has(this.$listeners, 'renderStart')) {
this.options.eventsCallbacks.renderStart = this.renderStart.bind(this); this.options.events.renderStart = this.renderStart.bind(this);
} }
if(has(this.$listeners, 'renderEnd')) { if(has(this.$listeners, 'renderEnd')) {
this.options.eventsCallbacks.renderEnd = this.renderEnd.bind(this); this.options.events.renderEnd = this.renderEnd.bind(this);
} }
}, },
zoomIn(range) { zoomIn(range) {

3
src/index.ts

@ -34,9 +34,8 @@ import * as d3 from 'd3';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
const DEFAULT_TICK_SIZE = 2; const DEFAULT_TICK_SIZE = 2;
const MILISECONDS_IN_MINUTE = 60 * 1000;
abstract class ChartwerkPod<T extends Serie, O extends Options> { abstract class ChartwerkPod<T extends Serie, O extends Options> {

61
src/models/options.ts

@ -90,7 +90,6 @@ export const CORE_DEFAULT_OPTIONS: Options = {
crosshair: DEFAULT_CROSSHAIR_OPTIONS, crosshair: DEFAULT_CROSSHAIR_OPTIONS,
renderLegend: true, renderLegend: true,
margin: DEFAULT_MARGIN, margin: DEFAULT_MARGIN,
eventsCallbacks: {},
} }
export class CoreOptions<O extends Options> { export class CoreOptions<O extends Options> {
@ -106,6 +105,14 @@ export class CoreOptions<O extends Options> {
protected setOptions(options: O): void { protected setOptions(options: O): void {
this._options = lodashDefaultsDeep(lodashCloneDeep(options), this.getDefaults()); this._options = lodashDefaultsDeep(lodashCloneDeep(options), this.getDefaults());
if(this._options.eventsCallbacks !== undefined) {
if(this._options.events !== undefined) {
throw new Error('events and eventsCallbacks are mutually exclusive');
}
this._options.events = this._options.eventsCallbacks;
}
// also bakward compatibility for clients who use "eventsCallbacks" instead of "events"
this._options.eventsCallbacks = this._options.events;
} }
// this getter can be overrited in Pod // this getter can be overrited in Pod
@ -160,80 +167,80 @@ export class CoreOptions<O extends Options> {
// event callbacks // event callbacks
callbackRenderStart(): void { callbackRenderStart(): void {
if(has(this._options.eventsCallbacks, 'renderStart')) { if(has(this._options.events, 'renderStart')) {
this._options.eventsCallbacks.renderStart(); this._options.events.renderStart();
} }
} }
callbackRenderEnd(): void { callbackRenderEnd(): void {
if(has(this._options.eventsCallbacks, 'renderEnd')) { if(has(this._options.events, 'renderEnd')) {
this._options.eventsCallbacks.renderEnd(); this._options.events.renderEnd();
} }
} }
callbackComponentRenderEnd(part: RenderComponent): void { callbackComponentRenderEnd(part: RenderComponent): void {
if(has(this._options.eventsCallbacks, 'componentRenderEnd')) { if(has(this._options.events, 'componentRenderEnd')) {
this._options.eventsCallbacks.componentRenderEnd(part); this._options.events.componentRenderEnd(part);
} }
} }
callbackLegendClick(idx: number): void { callbackLegendClick(idx: number): void {
if(has(this._options.eventsCallbacks, 'onLegendClick')) { if(has(this._options.events, 'onLegendClick')) {
this._options.eventsCallbacks.onLegendClick(idx); this._options.events.onLegendClick(idx);
} }
} }
callbackLegendLabelClick(idx: number): void { callbackLegendLabelClick(idx: number): void {
if(has(this._options.eventsCallbacks, 'onLegendLabelClick')) { if(has(this._options.events, 'onLegendLabelClick')) {
this._options.eventsCallbacks.onLegendLabelClick(idx); this._options.events.onLegendLabelClick(idx);
} }
} }
callbackPanning(event: { ranges: AxisRange[], d3Event: any }): void { callbackPanning(event: { ranges: AxisRange[], d3Event: any }): void {
if(has(this._options.eventsCallbacks, 'panning')) { if(has(this._options.events, 'panning')) {
this._options.eventsCallbacks.panning(event); this._options.events.panning(event);
} }
} }
callbackPanningEnd(ranges: AxisRange[]): void { callbackPanningEnd(ranges: AxisRange[]): void {
if(has(this._options.eventsCallbacks, 'panningEnd')) { if(has(this._options.events, 'panningEnd')) {
this._options.eventsCallbacks.panningEnd(ranges); this._options.events.panningEnd(ranges);
} }
} }
callbackZoomIn(ranges: AxisRange[]): void { callbackZoomIn(ranges: AxisRange[]): void {
if(has(this._options.eventsCallbacks, 'zoomIn')) { if(has(this._options.events, 'zoomIn')) {
this._options.eventsCallbacks.zoomIn(ranges); this._options.events.zoomIn(ranges);
} }
} }
callbackZoomOut(centers: { x: number, y: number }): void { callbackZoomOut(centers: { x: number, y: number }): void {
if(has(this._options.eventsCallbacks, 'zoomOut')) { if(has(this._options.events, 'zoomOut')) {
this._options.eventsCallbacks.zoomOut(centers); this._options.events.zoomOut(centers);
} }
} }
callbackSharedCrosshairMove(event: { datapoints, eventX, eventY }): void { callbackSharedCrosshairMove(event: { datapoints, eventX, eventY }): void {
if(has(this._options.eventsCallbacks, 'sharedCrosshairMove')) { if(has(this._options.events, 'sharedCrosshairMove')) {
this._options.eventsCallbacks.sharedCrosshairMove(event); this._options.events.sharedCrosshairMove(event);
} }
} }
callbackMouseMove(event): void { callbackMouseMove(event): void {
if(has(this._options.eventsCallbacks, 'mouseMove')) { if(has(this._options.events, 'mouseMove')) {
this._options.eventsCallbacks.mouseMove(event); this._options.events.mouseMove(event);
} }
} }
callbackMouseOut(): void { callbackMouseOut(): void {
if(has(this._options.eventsCallbacks, 'mouseOut')) { if(has(this._options.events, 'mouseOut')) {
this._options.eventsCallbacks.mouseOut(); this._options.events.mouseOut();
} }
} }
callbackMouseClick(event): void { callbackMouseClick(event): void {
if(has(this._options.eventsCallbacks, 'mouseClick')) { if(has(this._options.events, 'mouseClick')) {
this._options.eventsCallbacks.mouseClick(event); this._options.events.mouseClick(event);
} }
} }
} }

Loading…
Cancel
Save