Skip to content

Commit

Permalink
fix: JS exception: Cannot read property "dispatch" of undefined (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored and zhaoyongjie committed Nov 26, 2021
1 parent 64c7937 commit e3da248
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.log
*.map
*.min.js
.*.swp

babel.config.js
build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,16 @@ function nvd3Vis(element, props) {
}

if (canShowBrush && onBrushEnd !== NOOP) {
chart.focus.dispatch.on('brush', event => {
const timeRange = stringifyTimeRange(event.extent);
if (timeRange) {
event.brush.on('brushend', () => {
onBrushEnd(timeRange);
});
}
});
if (chart.focus) {
chart.focus.dispatch.on('brush', event => {
const timeRange = stringifyTimeRange(event.extent);
if (timeRange) {
event.brush.on('brushend', () => {
onBrushEnd(timeRange);
});
}
});
}
}

if (chart.xAxis && chart.xAxis.staggerLabels) {
Expand Down Expand Up @@ -970,22 +972,24 @@ function nvd3Vis(element, props) {
}

// update annotation positions on brush event
chart.focus.dispatch.on('onBrush.event-annotation', () => {
annotations
.selectAll('line')
.data(records)
.attr({
x1: d => xScale(new Date(d[e.timeColumn])),
y1: 0,
x2: d => xScale(new Date(d[e.timeColumn])),
y2: annotationHeight,
opacity: d => {
const x = xScale(new Date(d[e.timeColumn]));

return x > 0 && x < chartWidth ? 1 : 0;
},
});
});
if (chart.focus) {
chart.focus.dispatch.on('onBrush.event-annotation', () => {
annotations
.selectAll('line')
.data(records)
.attr({
x1: d => xScale(new Date(d[e.timeColumn])),
y1: 0,
x2: d => xScale(new Date(d[e.timeColumn])),
y2: annotationHeight,
opacity: d => {
const x = xScale(new Date(d[e.timeColumn]));

return x > 0 && x < chartWidth ? 1 : 0;
},
});
});
}
});

// Interval annotations
Expand Down Expand Up @@ -1059,20 +1063,22 @@ function nvd3Vis(element, props) {
}

// update annotation positions on brush event
chart.focus.dispatch.on('onBrush.interval-annotation', () => {
annotations
.selectAll('rect')
.data(records)
.attr({
x: d => xScale(new Date(d[e.timeColumn])),
width: d => {
const x1 = xScale(new Date(d[e.timeColumn]));
const x2 = xScale(new Date(d[e.intervalEndColumn]));

return x2 - x1;
},
});
});
if (chart.focus) {
chart.focus.dispatch.on('onBrush.interval-annotation', () => {
annotations
.selectAll('rect')
.data(records)
.attr({
x: d => xScale(new Date(d[e.timeColumn])),
width: d => {
const x1 = xScale(new Date(d[e.timeColumn]));
const x2 = xScale(new Date(d[e.intervalEndColumn]));

return x2 - x1;
},
});
});
}
});
}

Expand Down

0 comments on commit e3da248

Please sign in to comment.