Browse Source

optional events in options

merge-requests/3/head
Alexey Velikiy 3 years ago
parent
commit
7f31c98f36
  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