Browse Source

optional events in options

merge-requests/3/head
Alexey Velikiy 3 years ago
parent
commit
7f31c98f36
  1. 1
      .gitignore
  2. 4
      src/index.ts
  3. 22
      src/types.ts

1
.gitignore vendored

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

4
src/index.ts

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

22
src/types.ts

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

Loading…
Cancel
Save