Skip to content

Commit

Permalink
docs: adding intraday example
Browse files Browse the repository at this point in the history
Adding example loading intraday data.
  • Loading branch information
markmcdowell committed Dec 16, 2019
1 parent 1fca524 commit e687fb7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 7 additions & 1 deletion packages/stories/src/data/withOHLCData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ const parseDate = timeParse("%Y-%m-%d");

const parseData = () => {
return (d: any) => {
d.date = parseDate(d.date)!;

let date = parseDate(d.date);
if (date === null) {
date = new Date(Number(d.date));
}

d.date = new Date(date);
d.open = +d.open;
d.high = +d.high;
d.low = +d.low;
Expand Down
6 changes: 4 additions & 2 deletions packages/stories/src/features/FullCanvas.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from "react";
import StockChart from "./stockChart";
import StockChart, { IntradayStockChart } from "./stockChart";

export default {
component: StockChart,
title: "Features|Full Screen",
};

export const demo = () => <StockChart />;
export const daily = () => <StockChart />;

export const intraDay = () => <IntradayStockChart dateTimeFormat="%H:%M" />;
11 changes: 7 additions & 4 deletions packages/stories/src/features/stockChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IOHLCData, withOHLCData, withSize } from "../data";
interface StockChartProps {
readonly data: IOHLCData[];
readonly height: number;
readonly dateTimeFormat?: string;
readonly width: number;
readonly ratio: number;
}
Expand All @@ -24,14 +25,14 @@ class StockChart extends React.Component<StockChartProps> {

private readonly margin = { left: 0, right: 48, top: 0, bottom: 24 };
private readonly pricesDisplayFormat = format(".2f");
private readonly timeDisplayFormat = timeFormat("%d %b");
private readonly xScaleProvider = discontinuousTimeScaleProviderBuilder()
.inputDateAccessor((d: IOHLCData) => d.date);

public render() {

const {
data: initialData,
dateTimeFormat = "%d %b",
height,
ratio,
width,
Expand Down Expand Up @@ -75,6 +76,8 @@ class StockChart extends React.Component<StockChartProps> {
const barChartOrigin = (_: number, h: number) => [0, h - barChartHeight - elderRayHeight];
const chartHeight = gridHeight - elderRayHeight;

const timeDisplayFormat = timeFormat(dateTimeFormat);

return (
<ChartCanvas
height={height}
Expand Down Expand Up @@ -110,8 +113,7 @@ class StockChart extends React.Component<StockChartProps> {
<CandlestickSeries />
<LineSeries yAccessor={ema26.accessor()} stroke={ema26.stroke()} />
<LineSeries yAccessor={ema12.accessor()} stroke={ema12.stroke()} />
<MouseCoordinateY
displayFormat={this.pricesDisplayFormat} />
<MouseCoordinateY displayFormat={this.pricesDisplayFormat} />
<EdgeIndicator
itemType="last"
fill={this.openCloseColor}
Expand Down Expand Up @@ -151,7 +153,7 @@ class StockChart extends React.Component<StockChartProps> {
ticks={6} />
<YAxis ticks={4} tickFormat={this.pricesDisplayFormat} />

<MouseCoordinateX displayFormat={this.timeDisplayFormat} />
<MouseCoordinateX displayFormat={timeDisplayFormat} />
<MouseCoordinateY displayFormat={this.pricesDisplayFormat} />

<ElderRaySeries yAccessor={elder.accessor()} />
Expand Down Expand Up @@ -190,3 +192,4 @@ class StockChart extends React.Component<StockChartProps> {
}

export default withOHLCData()(withSize(600)(withDeviceRatio()(StockChart)));
export const IntradayStockChart = withOHLCData("MSFT_INTRA_DAY")(withSize(600)(withDeviceRatio()(StockChart)));

0 comments on commit e687fb7

Please sign in to comment.