Skip to content

Commit

Permalink
fix: set to default full range when same selection of brush
Browse files Browse the repository at this point in the history
  • Loading branch information
JennChao authored and JenniferChao-tc committed Jun 19, 2020
1 parent 823deed commit 15d4ddf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/core/src/components/axes/brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Brush extends Component {

if (mainXScaleType === ScaleTypes.TIME) {
// Get all date values provided in data
// TODO - Could be re-used through the model
// @todo - Could be re-used through the model
let allDates = [];
displayData.forEach((data) => {
allDates = allDates.concat(Number(data.date));
Expand Down Expand Up @@ -86,28 +86,35 @@ export class Brush extends Component {

const brushed = () => {
let selection = event.selection;
if (selection !== null) {
// update zoombar handle position
// select(svg).call(updateBrushHandle, selection);

if (selection !== null) {
// get current zoomDomain
zoomDomain = this.model.get("zoomDomain");
// create xScale based on current zoomDomain
const xScale = scaleTime()
.range([axesLeftMargin, width])
.domain(zoomDomain);

const newDomain = [
let newDomain = [
xScale.invert(selection[0]),
xScale.invert(selection[1])
];

// check if slected start time and end time are the same
if(newDomain[0].valueOf() === newDomain[1].valueOf()) {
// same as d3 behavior and zoombar behavior: set to default full range
newDomain = extent(stackDataArray, (d: any) => d.date);
}

// only if the brush event comes from mouseup event
if (event.sourceEvent != null) {
// only if zoomDomain needs update
if (zoomDomain[0] !== newDomain[0] || zoomDomain[1] !== newDomain[1]) {
if (
zoomDomain[0].valueOf() !== newDomain[0].valueOf() ||
zoomDomain[1].valueOf() !== newDomain[1].valueOf()
) {
this.model.set(
{ zoomDomain: newDomain, zoomDomainForZoomBar: newDomain },
{ zoomDomain: newDomain },
{ animate: false }
);
}
Expand Down

0 comments on commit 15d4ddf

Please sign in to comment.