This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Zoom and Brush container fixes #475
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*eslint-disable no-magic-numbers */ | ||
import React from "react"; | ||
import { | ||
VictoryChart, VictoryLine, VictoryGroup, VictoryZoomContainer | ||
} from "../../src/index"; | ||
|
||
const edata = [ | ||
{ x: 1, y: -3 }, | ||
{ x: 2, y: 5 }, | ||
{ x: 3, y: 3 }, | ||
{ x: 4, y: 0 }, | ||
{ x: 5, y: -2 }, | ||
{ x: 6, y: -2 }, | ||
{ x: 7, y: 5 } | ||
]; | ||
|
||
class App extends React.Component { | ||
constructor() { | ||
super(); | ||
this.state = { data: edata.slice(3) }; | ||
} | ||
|
||
|
||
handleDomainChange(domain) { | ||
this.setState({ selectedDomain: domain }); | ||
} | ||
changeDataSet(data) { | ||
this.setState({ | ||
data, | ||
selectedDomain: { x: [data[0].x, data[data.length - 1].x] } | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{ width: 300 }}> | ||
<button onClick={() => this.changeDataSet(edata.slice(3))}>Part</button> | ||
<button onClick={() => this.changeDataSet(edata)}>All</button> | ||
<VictoryChart | ||
containerComponent={ | ||
<VictoryZoomContainer | ||
dimension="x" | ||
onDomainChange={this.handleDomainChange.bind(this)} | ||
zoomDomain={this.state.selectedDomain} | ||
/> | ||
} | ||
style={{ parent: { cursor: "pointer" } }} | ||
> | ||
<VictoryGroup | ||
|
||
data={this.state.data} | ||
> | ||
<VictoryLine/> | ||
</VictoryGroup> | ||
</VictoryChart> | ||
<p> | ||
currentDomain (domain), | ||
domain, | ||
cachedZoomDomain | ||
</p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 1000] }]*/ | ||
import { Selection, Collection } from "victory-core"; | ||
import { throttle, isFunction, defaults } from "lodash"; | ||
import { throttle, isFunction, defaults, isEqual } from "lodash"; | ||
import { attachId } from "../../helpers/event-handlers.js"; | ||
|
||
const Helpers = { | ||
|
@@ -128,26 +128,32 @@ const Helpers = { | |
return undefined; | ||
}, | ||
|
||
getLastDomain(targetProps, originalDomain) { | ||
const { zoomDomain, cachedZoomDomain, currentDomain, domain } = targetProps; | ||
if (zoomDomain && !isEqual(zoomDomain, cachedZoomDomain)) { | ||
return defaults( | ||
{}, zoomDomain, domain | ||
); | ||
} | ||
return defaults( | ||
{}, currentDomain || zoomDomain || originalDomain, domain | ||
); | ||
}, | ||
|
||
getDomain(props) { | ||
const { originalDomain, domain, scale } = props; | ||
const scaleDomain = { x: scale.x.domain(), y: scale.y.domain() }; | ||
return defaults({}, originalDomain, domain, scaleDomain); | ||
}, | ||
|
||
onMouseDown(evt, targetProps) { | ||
onMouseDown(evt) { | ||
evt.preventDefault(); | ||
const { domain, zoomDomain } = targetProps; | ||
const originalDomain = this.getDomain(targetProps); | ||
const currentDomain = defaults( | ||
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain | ||
); | ||
const { x, y } = Selection.getSVGEventCoordinates(evt); | ||
return [{ | ||
target: "parent", | ||
mutation: () => { | ||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no reason why onMouseDown needs to squash values for the various |
||
startX: x, startY: y, domain: currentDomain, cachedZoomDomain: zoomDomain, | ||
originalDomain, currentDomain, panning: true, | ||
startX: x, startY: y, panning: true, | ||
parentControlledProps: ["domain"] | ||
}; | ||
} | ||
|
@@ -174,12 +180,10 @@ const Helpers = { | |
|
||
onMouseMove(evt, targetProps, eventKey, ctx) { // eslint-disable-line max-params | ||
if (targetProps.panning) { | ||
const { scale, startX, startY, onDomainChange, dimension, domain, zoomDomain } = targetProps; | ||
const { scale, startX, startY, onDomainChange, dimension, zoomDomain } = targetProps; | ||
const { x, y } = Selection.getSVGEventCoordinates(evt); | ||
const originalDomain = this.getDomain(targetProps); | ||
const lastDomain = defaults( | ||
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain | ||
); | ||
const lastDomain = this.getLastDomain(targetProps, originalDomain); | ||
const dx = (startX - x) / this.getDomainScale(lastDomain, scale, "x"); | ||
const dy = (y - startY) / this.getDomainScale(lastDomain, scale, "y"); | ||
const currentDomain = { | ||
|
@@ -208,11 +212,9 @@ const Helpers = { | |
if (!targetProps.allowZoom) { | ||
return {}; | ||
} | ||
const { onDomainChange, dimension, domain, zoomDomain } = targetProps; | ||
const { onDomainChange, dimension, zoomDomain } = targetProps; | ||
const originalDomain = this.getDomain(targetProps); | ||
const lastDomain = defaults( | ||
{}, targetProps.currentDomain || zoomDomain || originalDomain, domain | ||
); | ||
const lastDomain = this.getLastDomain(targetProps, originalDomain); | ||
const { x, y } = lastDomain; | ||
const currentDomain = { | ||
x: dimension === "y" ? lastDomain.x : this.scale(x, evt, targetProps, "x"), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A demo to work through bug reproductions. Intensionally not shown on the demo table of contents