-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BrushY: A dummy vertical Brush for scaling/panning the YAxis #4036
Open
kerguler
wants to merge
8
commits into
recharts:master
Choose a base branch
from
kerguler:dummy-brushy
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+823
−32
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1a5a649
Recharts for VEClim
kerguler ac8fc8b
Create BrushY.spec.tsx
kerguler da111b6
Update BrushY.spec.tsx
kerguler 4aea549
to-do: initial props
kerguler db7ee13
fixing start/end indices
kerguler 41c04dc
endIndex fix
kerguler 6b148de
minor
kerguler de42859
requested changes
kerguler File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Component, useState } from 'react'; | ||
import { LineChart, Line, Brush, BrushY, XAxis, YAxis } from 'recharts'; | ||
|
||
const data = [ | ||
{ day: '1', value: 10 }, | ||
{ day: '2', value: 20 }, | ||
{ day: '3', value: 10 }, | ||
{ day: '4', value: 30 }, | ||
{ day: '5', value: 50 }, | ||
{ day: '6', value: 10 }, | ||
{ day: '7', value: 30 }, | ||
{ day: '8', value: 20 }, | ||
{ day: '9', value: 10 }, | ||
{ day: '10', value: 70 }, | ||
{ day: '11', value: 40 }, | ||
{ day: '12', value: 20 }, | ||
{ day: '13', value: 10 }, | ||
{ day: '14', value: 10 }, | ||
]; | ||
|
||
function BrushYDemo() { | ||
const displayName = 'BrushYDemo'; | ||
|
||
const bSteps = 100; | ||
const range = { min: 0, max: 100 }; | ||
data.forEach(d => { | ||
if (d.value < range.min) range.min = d.value; | ||
if (d.value > range.max) range.max = d.value; | ||
}); | ||
const scl = (range.max - range.min) / bSteps; | ||
const [dom, setDom] = useState({ min: 0, max: 100 }); | ||
|
||
function handleBrushChange(e: any) { | ||
setDom({ | ||
min: range.min + (bSteps - e.endIndex) * scl, | ||
max: range.max - (e.startIndex - 0) * scl, | ||
}); | ||
} | ||
|
||
return ( | ||
<LineChart width={400} height={300} data={data}> | ||
<XAxis type="number" dataKey="day" /> | ||
<YAxis type="number" dataKey="value" domain={[dom.min, dom.max]} allowDataOverflow /> | ||
<Brush dataKey="day" x={20} y={0} width={380} height={20} /> | ||
<BrushY x={0} y={20} width={20} height={280} onChange={handleBrushChange} /> | ||
<Line type="monotone" dataKey="value" /> | ||
</LineChart> | ||
); | ||
} | ||
|
||
export default BrushYDemo; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
We don't really use the demo project anymore, can you add this code to the storybook instead?
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.
Of course, as soon as I figure out how to do it :)
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.
Should be similar code luckily! You can add this to the Brush examples: storybook - Examples - Cartesian - Brush
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.
I'll add it as a new component as I couldn't figure out how to incorporate changes in the Brush component and have it rendered twice. I trust that the planned refactoring will enable this. Until then...