Skip to content
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
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions demo/component/BrushYDemo.tsx
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() {
Copy link
Member

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?

Copy link
Author

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 :)

Copy link
Member

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

Copy link
Author

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...

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;
2 changes: 2 additions & 0 deletions demo/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PolarGrid from './PolarGrid';
import PolarRadiusAxis from './PolarRadiusAxis';
import PolarAngleAxis from './PolarAngleAxis';
import Brush from './BrushDemo';
import BrushY from './BrushYDemo';
import Text from './TextDemo';

import Curve from './Curve';
Expand Down Expand Up @@ -56,6 +57,7 @@ export default {

cartesian: {
Brush,
BrushY,
CartesianAxis,
CartesianGrid,
},
Expand Down
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.