Browse Source

Merge branch 'optional-events-callbacks-#1' into 'main'

optional events in options

Closes #1

See merge request chartwerk/core!3
merge-requests/5/merge
Alexander Velikiy 3 years ago
parent
commit
d0b1b7ee6d
  1. 1
      .gitignore
  2. 8
      src/index.ts
  3. 22
      src/types.ts

1
.gitignore vendored

@ -1 +1,2 @@
node_modules
.vscode

8
src/index.ts

@ -540,7 +540,9 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
.attr('height', 15)
.html(`<form><input type=checkbox ${isChecked? 'checked' : ''} /></form>`)
.on('click', () => {
this.options.eventsCallbacks.onLegendClick(idx);
if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.onLegendClick !== undefined) {
this.options.eventsCallbacks.onLegendClick(idx);
}
});
legendRow.append('text')
@ -551,7 +553,9 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
.style('fill', this.getSerieColor(idx))
.text(this.series[idx].target)
.on('click', () => {
this.options.eventsCallbacks.onLegendLabelClick(idx);
if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.onLegendLabelClick !== undefined) {
this.options.eventsCallbacks.onLegendLabelClick(idx);
}
});
}
}

22
src/types.ts

@ -13,17 +13,17 @@ export type Options = {
margin?: Margin;
confidence?: number;
eventsCallbacks?: {
zoomIn: (range: AxisRange[]) => void,
panning: (event: { ranges: AxisRange[], d3Event: any }) => void,
panningEnd: (range: AxisRange[]) => void,
zoomOut: (centers: {x: number, y: number}) => void,
mouseMove: (evt: any) => void,
mouseOut: () => void,
onLegendClick: (idx: number) => void,
onLegendLabelClick: (idx: number) => void,
contextMenu: (evt: any) => void, // the same name as in d3.events
sharedCrosshairMove: (event: any) => void,
renderEnd: () => void,
zoomIn?: (range: AxisRange[]) => void,
panning?: (event: { ranges: AxisRange[], d3Event: any }) => void,
panningEnd?: (range: AxisRange[]) => void,
zoomOut?: (centers: {x: number, y: number}) => void,
mouseMove?: (evt: any) => void,
mouseOut?: () => void,
onLegendClick?: (idx: number) => void,
onLegendLabelClick?: (idx: number) => void,
contextMenu?: (evt: any) => void, // the same name as in d3.events
sharedCrosshairMove?: (event: any) => void,
renderEnd?: () => void,
};
axis?: {
x?: AxisOption,

Loading…
Cancel
Save