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.
Some more props corrected. Added ATR, Force Index and Elder Ray stories.
- Loading branch information
1 parent
c23b676
commit 4942299
Showing
14 changed files
with
367 additions
and
42 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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 { atr } from "react-financial-charts/lib/indicator"; | ||
import { discontinuousTimeScaleProviderBuilder } from "react-financial-charts/lib/scale"; | ||
import { LineSeries } from "react-financial-charts/lib/series"; | ||
import { SingleValueTooltip } from "react-financial-charts/lib/tooltip"; | ||
import { withDeviceRatio } from "react-financial-charts/lib/utils"; | ||
import { IOHLCData, withOHLCData, withSize } from "../../data"; | ||
|
||
interface ChartProps { | ||
readonly data: IOHLCData[]; | ||
readonly height: number; | ||
readonly width: number; | ||
readonly ratio: number; | ||
} | ||
|
||
class ATRIndicator 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 { | ||
data: initialData, | ||
height, | ||
ratio, | ||
width, | ||
} = this.props; | ||
|
||
const atr14 = atr() | ||
// @ts-ignore | ||
.options({ windowSize: 14 }) | ||
.merge((d: any, c: any) => { d.atr14 = c; }) | ||
.accessor((d: any) => d.atr14); | ||
|
||
const calculatedData = atr14(initialData); | ||
|
||
const { margin, xScaleProvider } = this; | ||
|
||
const { | ||
data, | ||
xScale, | ||
xAccessor, | ||
displayXAccessor, | ||
} = xScaleProvider(calculatedData); | ||
|
||
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={atr14.accessor()}> | ||
<XAxis ticks={6} /> | ||
<YAxis ticks={2} /> | ||
|
||
<LineSeries yAccessor={atr14.accessor()} stroke={atr14.stroke()} /> | ||
|
||
<SingleValueTooltip | ||
yAccessor={atr14.accessor()} | ||
yLabel={`ATR (${atr14.options().windowSize})`} | ||
yDisplayFormat={format(".2f")} | ||
labelFill={atr14.stroke()} | ||
origin={[8, 16]} /> | ||
</Chart> | ||
</ChartCanvas> | ||
); | ||
} | ||
} | ||
|
||
export default withOHLCData()(withSize()(withDeviceRatio()(ATRIndicator))); |
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,13 @@ | ||
import * as React from "react"; | ||
import { atr } from "react-financial-charts/lib/indicator"; | ||
import ATRIndicator from "./atrIndicator"; | ||
|
||
export default { | ||
title: "Visualization|Indicator/ATR", | ||
component: atr, | ||
parameters: { | ||
componentSubtitle: "Average True Range (ATR) is an indicator that measures volatility.", | ||
}, | ||
}; | ||
|
||
export const basic = () => <ATRIndicator />; |
87 changes: 87 additions & 0 deletions
87
packages/stories/src/indicators/elderRay/elderRayIndicator.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,87 @@ | ||
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 { change, elderRay } from "react-financial-charts/lib/indicator"; | ||
import { discontinuousTimeScaleProviderBuilder } from "react-financial-charts/lib/scale"; | ||
import { | ||
ElderRaySeries, | ||
} from "react-financial-charts/lib/series"; | ||
import { | ||
SingleValueTooltip, | ||
} from "react-financial-charts/lib/tooltip"; | ||
import { withDeviceRatio } from "react-financial-charts/lib/utils"; | ||
import { IOHLCData, withOHLCData, withSize } from "../../data"; | ||
|
||
interface ChartProps { | ||
readonly data: IOHLCData[]; | ||
readonly height: number; | ||
readonly width: number; | ||
readonly ratio: number; | ||
} | ||
|
||
class ElderRayIndicator extends React.Component<ChartProps> { | ||
|
||
private readonly margin = { left: 0, right: 48, top: 8, bottom: 24 }; | ||
private readonly xScaleProvider = discontinuousTimeScaleProviderBuilder() | ||
.inputDateAccessor((d: IOHLCData) => d.date); | ||
|
||
public render() { | ||
|
||
const { | ||
data: initialData, | ||
height, | ||
ratio, | ||
width, | ||
} = this.props; | ||
|
||
const elder: any = elderRay(); | ||
const changeCalculator = change(); | ||
|
||
const calculatedData = changeCalculator(elder(initialData)); | ||
|
||
const { margin, xScaleProvider } = this; | ||
|
||
const { | ||
data, | ||
xScale, | ||
xAccessor, | ||
displayXAccessor, | ||
} = xScaleProvider(calculatedData); | ||
|
||
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={[0, elder.accessor()]}> | ||
<XAxis ticks={6} /> | ||
<YAxis ticks={4} tickFormat={format(".2f")} /> | ||
|
||
<ElderRaySeries yAccessor={elder.accessor()} /> | ||
|
||
<SingleValueTooltip | ||
yAccessor={elder.accessor()} | ||
yLabel="Elder Ray" | ||
yDisplayFormat={(d) => `${format(".2f")(d.bullPower)}, ${format(".2f")(d.bearPower)}`} | ||
origin={[8, 8]} /> | ||
</Chart> | ||
</ChartCanvas> | ||
); | ||
} | ||
} | ||
|
||
export default withOHLCData()(withSize()(withDeviceRatio()(ElderRayIndicator))); |
16 changes: 16 additions & 0 deletions
16
packages/stories/src/indicators/elderRay/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,16 @@ | ||
import * as React from "react"; | ||
import { forceIndex } from "react-financial-charts/lib/indicator"; | ||
import ElderRayIndicator from "./elderRayIndicator"; | ||
|
||
export default { | ||
title: "Visualization|Indicator/Elder Ray", | ||
component: forceIndex, | ||
parameters: { | ||
componentSubtitle: `This indicator consists of three separate indicators | ||
known as "bull power" and "bear power", which are derived from a 13-period | ||
exponential moving average (EMA). The three indicator help traders determine | ||
the trend direction and isolate spots to enter and exit trades.`, | ||
}, | ||
}; | ||
|
||
export const basic = () => <ElderRayIndicator />; |
Oops, something went wrong.