forked from react-financial/react-financial-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(charts): arrowWidth was being ignored
Setting arrowWidth now actually draws an arrow. Closes react-financial#75
- Loading branch information
1 parent
4c5a0e1
commit dce50aa
Showing
6 changed files
with
133 additions
and
22 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
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,80 @@ | ||
import { format } from "d3-format"; | ||
import * as React from "react"; | ||
import { Chart, ChartCanvas } from "react-financial-charts"; | ||
import { XAxis, YAxis } from "react-financial-charts/lib/axes"; | ||
import { MouseCoordinateY } from "react-financial-charts/lib/coordinates"; | ||
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 arrowWidth?: number; | ||
readonly data: IOHLCData[]; | ||
readonly height: number; | ||
readonly ratio: number; | ||
readonly width: number; | ||
} | ||
|
||
class Coordinates extends React.Component<ChartProps> { | ||
|
||
private readonly margin = { left: 0, right: 48, top: 0, bottom: 24 }; | ||
private readonly xScaleProvider = discontinuousTimeScaleProviderBuilder() | ||
.inputDateAccessor((d: IOHLCData) => d.date); | ||
private readonly pricesDisplayFormat = format(".2f"); | ||
|
||
public render() { | ||
|
||
const { | ||
arrowWidth, | ||
data: initialData, | ||
height, | ||
ratio, | ||
width, | ||
} = 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 | ||
height={height} | ||
ratio={ratio} | ||
width={width} | ||
margin={margin} | ||
data={data} | ||
displayXAccessor={displayXAccessor} | ||
seriesName="Data" | ||
xScale={xScale} | ||
xAccessor={xAccessor} | ||
xExtents={xExtents}> | ||
<Chart | ||
id={1} | ||
yExtents={this.yExtents}> | ||
<CandlestickSeries /> | ||
<MouseCoordinateY | ||
arrowWidth={arrowWidth} | ||
displayFormat={this.pricesDisplayFormat} /> | ||
<XAxis ticks={6} /> | ||
<YAxis ticks={5} /> | ||
</Chart> | ||
</ChartCanvas> | ||
); | ||
} | ||
|
||
private readonly yExtents = (data: IOHLCData) => { | ||
return [data.high, data.low]; | ||
} | ||
} | ||
|
||
export default withOHLCData()(withSize()(withDeviceRatio()(Coordinates))); |
12 changes: 12 additions & 0 deletions
12
packages/stories/src/features/coordinates/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,12 @@ | ||
import * as React from "react"; | ||
import { MouseCoordinateY } from "react-financial-charts/lib/coordinates"; | ||
import Coordinates from "./coordinates"; | ||
|
||
export default { | ||
component: MouseCoordinateY, | ||
title: "Features|Coordinates", | ||
}; | ||
|
||
export const edge = () => <Coordinates />; | ||
|
||
export const arrows = () => <Coordinates arrowWidth={10} />; |