-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding disable, disablePan, disableZoom, clamp and zoomAchors.
- Loading branch information
1 parent
1e32380
commit e18cf89
Showing
16 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...es/stories/src/showcase/Intro.stories.mdx → ...es/stories/src/features/Intro.stories.mdx
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
23 changes: 23 additions & 0 deletions
23
packages/stories/src/features/interaction/index.stories.tsx
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,23 @@ | ||
import * as React from "react"; | ||
import { ChartCanvas } from "react-financial-charts"; | ||
import { lastVisibleItemBasedZoomAnchor, mouseBasedZoomAnchor, rightDomainBasedZoomAnchor } from "react-financial-charts/lib/utils/zoomBehavior"; | ||
import Interaction from "./interaction"; | ||
|
||
export default { | ||
title: "Features|Interaction", | ||
component: ChartCanvas, | ||
}; | ||
|
||
export const clamp = () => <Interaction clamp />; | ||
|
||
export const disable = () => <Interaction disableInteraction />; | ||
|
||
export const disablePan = () => <Interaction disablePan />; | ||
|
||
export const disableZoom = () => <Interaction disableZoom />; | ||
|
||
export const zoomAnchorToMouse = () => <Interaction zoomAnchor={mouseBasedZoomAnchor} />; | ||
|
||
export const zoomAnchorToLastVisible = () => <Interaction zoomAnchor={lastVisibleItemBasedZoomAnchor} />; | ||
|
||
export const zoomAnchorToBounds = () => <Interaction zoomAnchor={rightDomainBasedZoomAnchor} />; |
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,87 @@ | ||
import * as React from "react"; | ||
import { Chart, ChartCanvas } from "react-financial-charts"; | ||
import { XAxis, YAxis } from "react-financial-charts/lib/axes"; | ||
import { discontinuousTimeScaleProviderBuilder } from "react-financial-charts/lib/scale"; | ||
import { CandlestickSeries } from "react-financial-charts/lib/series"; | ||
import { withDeviceRatio } from "react-financial-charts/lib/utils"; | ||
import { IOHLCData, withOHLCData, withSize } from "../../data"; | ||
|
||
interface ChartProps { | ||
readonly clamp?: boolean; | ||
readonly data: IOHLCData[]; | ||
readonly disableInteraction?: boolean; | ||
readonly disablePan?: boolean; | ||
readonly disableZoom?: boolean; | ||
readonly height: number; | ||
readonly ratio: number; | ||
readonly width: number; | ||
readonly zoomAnchor?: any; | ||
} | ||
|
||
class Interaction extends React.Component<ChartProps> { | ||
|
||
private readonly margin = { left: 0, right: 40, top: 0, bottom: 24 }; | ||
private readonly xScaleProvider = discontinuousTimeScaleProviderBuilder() | ||
.inputDateAccessor((d: IOHLCData) => d.date); | ||
|
||
public render() { | ||
|
||
const { | ||
clamp, | ||
data: initialData, | ||
disablePan = false, | ||
disableZoom = false, | ||
disableInteraction, | ||
height, | ||
ratio, | ||
width, | ||
zoomAnchor, | ||
} = this.props; | ||
|
||
const { margin, xScaleProvider } = this; | ||
|
||
const { | ||
data, | ||
xScale, | ||
xAccessor, | ||
displayXAccessor, | ||
} = xScaleProvider(initialData); | ||
|
||
const start = xAccessor(data[data.length - 1]); | ||
const end = xAccessor(data[Math.max(0, data.length - 100)]); | ||
const xExtents = [start, end]; | ||
|
||
return ( | ||
<ChartCanvas | ||
clamp={clamp} | ||
height={height} | ||
ratio={ratio} | ||
width={width} | ||
margin={margin} | ||
data={data} | ||
disableInteraction={disableInteraction} | ||
displayXAccessor={displayXAccessor} | ||
panEvent={!disablePan} | ||
seriesName="Data" | ||
xScale={xScale} | ||
xAccessor={xAccessor} | ||
xExtents={xExtents} | ||
zoomEvent={!disableZoom} | ||
zoomAnchor={zoomAnchor}> | ||
<Chart | ||
id={1} | ||
yExtents={this.yExtents}> | ||
<CandlestickSeries /> | ||
<XAxis ticks={6} /> | ||
<YAxis ticks={5} /> | ||
</Chart> | ||
</ChartCanvas> | ||
); | ||
} | ||
|
||
private readonly yExtents = (data: IOHLCData) => { | ||
return [data.high, data.low]; | ||
} | ||
} | ||
|
||
export default withOHLCData()(withSize()(withDeviceRatio()(Interaction))); |
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
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
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