diff --git a/packages/core/src/Chart.tsx b/packages/core/src/Chart.tsx index 06657c2d6..103188787 100644 --- a/packages/core/src/Chart.tsx +++ b/packages/core/src/Chart.tsx @@ -1,7 +1,6 @@ import { scaleLinear, ScaleContinuousNumeric } from "d3-scale"; import * as PropTypes from "prop-types"; import * as React from "react"; - import { PureComponent } from "./utils"; export interface ChartProps { @@ -87,21 +86,27 @@ export class Chart extends PureComponent { switch (type) { case "contextmenu": { - if (onContextMenu !== undefined) { - const { currentCharts } = moreProps; - if (currentCharts.indexOf(id) > -1) { - onContextMenu(e, moreProps); - } + if (onContextMenu === undefined) { + return; + } + + const { currentCharts } = moreProps; + if (currentCharts.indexOf(id) > -1) { + onContextMenu(e, moreProps); } + break; } case "dblclick": { - if (onDoubleClick !== undefined) { - const { currentCharts } = moreProps; - if (currentCharts.indexOf(id) > -1) { - onDoubleClick(e, moreProps); - } + if (onDoubleClick === undefined) { + return; } + + const { currentCharts } = moreProps; + if (currentCharts.indexOf(id) > -1) { + onDoubleClick(e, moreProps); + } + break; } } diff --git a/packages/core/src/ChartCanvas.tsx b/packages/core/src/ChartCanvas.tsx index d1a392568..6ffb7092b 100644 --- a/packages/core/src/ChartCanvas.tsx +++ b/packages/core/src/ChartCanvas.tsx @@ -67,18 +67,18 @@ function getCursorStyle() { return ; } -function getDimensions(props: ChartCanvasProps) { +function getDimensions(props: ChartCanvasProps) { return { height: props.height - props.margin.top - props.margin.bottom, width: props.width - props.margin.left - props.margin.right, }; } -function getXScaleDirection(flipXScale: any) { +function getXScaleDirection(flipXScale?: boolean) { return flipXScale ? -1 : 1; } -function calculateFullData(props: ChartCanvasProps) { +function calculateFullData(props: ChartCanvasProps) { const { data: fullData, plotFull, xScale, clamp, pointsPerPxThreshold, flipXScale } = props; const { xAccessor, displayXAccessor, minPointsPerPxThreshold } = props; @@ -102,7 +102,7 @@ function calculateFullData(props: ChartCanvasProps) { }; } -const resetChart = (props: ChartCanvasProps) => { +const resetChart = (props: ChartCanvasProps) => { const state = calculateState(props); const { xAccessor, displayXAccessor, fullData, plotData: initialPlotData, xScale } = state; @@ -197,7 +197,7 @@ function updateChart( }; } -function calculateState(props: ChartCanvasProps) { +function calculateState(props: ChartCanvasProps) { const { xAccessor: inputXAccesor, xExtents: xExtentsProp, data, padding, flipXScale } = props; const direction = getXScaleDirection(flipXScale); @@ -207,7 +207,9 @@ function calculateState(props: ChartCanvasProps) { const extent = typeof xExtentsProp === "function" ? xExtentsProp(data) - : d3Extent(xExtentsProp.map((d: any) => functor(d)).map((each: any) => each(data, inputXAccesor))); + : (d3Extent( + xExtentsProp.map((d: any) => functor(d)).map((each: any) => each(data, inputXAccesor)), + ) as [TXAxis, TXAxis]); const { xAccessor, displayXAccessor, xScale, fullData, filterData } = calculateFullData(props); @@ -262,7 +264,7 @@ function isInteractionEnabled(xScale: any, xAccessor: any, data: any) { return interaction; } -export interface ChartCanvasProps { +export interface ChartCanvasProps { readonly clamp?: | boolean | ("left" | "right" | "both") @@ -274,7 +276,7 @@ export interface ChartCanvasProps { readonly disableInteraction?: boolean; readonly disablePan?: boolean; readonly disableZoom?: boolean; - readonly displayXAccessor?: (data: any) => number | Date; + readonly displayXAccessor?: (data: any) => TXAxis; readonly flipXScale?: boolean; readonly height: number; readonly margin: { @@ -289,11 +291,11 @@ export interface ChartCanvasProps { /** * Called when panning left past the first data point. */ - readonly onLoadAfter?: (start: number | Date, end: number | Date) => void; + readonly onLoadAfter?: (start: TXAxis, end: TXAxis) => void; /** * Called when panning right past the last data point. */ - readonly onLoadBefore?: (start: number | Date, end: number | Date) => void; + readonly onLoadBefore?: (start: TXAxis, end: TXAxis) => void; /** * Click event handler. */ @@ -317,24 +319,27 @@ export interface ChartCanvasProps { readonly seriesName: string; readonly useCrossHairStyleCursor?: boolean; readonly width: number; - readonly xAccessor: (data: any) => number | Date; - readonly xExtents?: any[] | any; // func + readonly xAccessor: (data: any) => TXAxis; + readonly xExtents: ((data: any[]) => [TXAxis, TXAxis]) | (((datum: any) => TXAxis) | TXAxis)[]; readonly xScale: ScaleContinuousNumeric | ScaleTime; readonly zIndex?: number; - readonly zoomAnchor?: (options: IZoomAnchorOptions) => number | Date; + readonly zoomAnchor?: (options: IZoomAnchorOptions) => TXAxis; readonly zoomMultiplier?: number; } -interface ChartCanvasState { - xAccessor?: (data: any) => number | Date; +interface ChartCanvasState { + xAccessor?: (data: any) => TXAxis; displayXAccessor?: any; filterData?: any; chartConfig?: any; - plotData?: any; + plotData: any[]; xScale: ScaleContinuousNumeric | ScaleTime; } -export class ChartCanvas extends React.Component { +export class ChartCanvas extends React.Component< + ChartCanvasProps, + ChartCanvasState +> { public static defaultProps = { clamp: false, className: "react-financial-charts", @@ -351,7 +356,7 @@ export class ChartCanvas extends React.Component number, + xAccessor: identity as (data: any) => any, xExtents: [min, max] as any[], zIndex: 1, zoomAnchor: mouseBasedZoomAnchor, @@ -420,7 +425,7 @@ export class ChartCanvas extends React.Component) { super(props); const { fullData, ...state } = resetChart(props); @@ -1125,7 +1130,7 @@ export class ChartCanvas extends React.Component) { const reset = shouldResetChart(this.props, nextProps); const interaction = isInteractionEnabled(this.state.xScale, this.state.xAccessor, this.state.plotData); diff --git a/packages/core/src/EventCapture.tsx b/packages/core/src/EventCapture.tsx index 0945030bc..410fe8b1f 100644 --- a/packages/core/src/EventCapture.tsx +++ b/packages/core/src/EventCapture.tsx @@ -42,24 +42,24 @@ interface EventCaptureProps { readonly onMouseLeave?: (event: React.MouseEvent) => void; readonly onPinchZoom?: ( initialPinch: { - xScale: ScaleContinuousNumeric | ScaleTime; - touch1Pos: [number, number]; - touch2Pos: [number, number]; - range: number[]; + readonly xScale: ScaleContinuousNumeric | ScaleTime; + readonly touch1Pos: [number, number]; + readonly touch2Pos: [number, number]; + readonly range: number[]; }, currentPinch: { - xScale: ScaleContinuousNumeric | ScaleTime; - touch1Pos: [number, number]; - touch2Pos: [number, number]; + readonly xScale: ScaleContinuousNumeric | ScaleTime; + readonly touch1Pos: [number, number]; + readonly touch2Pos: [number, number]; }, e: React.TouchEvent, ) => void; readonly onPinchZoomEnd?: ( initialPinch: { - xScale: ScaleContinuousNumeric | ScaleTime; - touch1Pos: [number, number]; - touch2Pos: [number, number]; - range: number[]; + readonly xScale: ScaleContinuousNumeric | ScaleTime; + readonly touch1Pos: [number, number]; + readonly touch2Pos: [number, number]; + readonly range: number[]; }, e: React.TouchEvent, ) => void; @@ -199,7 +199,7 @@ export class EventCapture extends React.Component { - const { zoom, onZoom } = this.props; + const { onPan, zoom, onZoom } = this.props; const { panInProgress } = this.state; const yZoom = Math.abs(e.deltaY) > Math.abs(e.deltaX) && Math.abs(e.deltaY) > 0; @@ -230,8 +230,8 @@ export class EventCapture extends React.Component number; + displayXAccessor: (data: any) => number; + }; + initialIndex(): any; + initialIndex(x: any): DiscontinuousTimeScaleProviderBuilder; + inputDateAccessor(): any; + inputDateAccessor(accessor: (data: any) => Date): DiscontinuousTimeScaleProviderBuilder; + indexAccessor(): any; + indexAccessor(x: any): DiscontinuousTimeScaleProviderBuilder; + indexMutator(): any; + indexMutator(x: any): DiscontinuousTimeScaleProviderBuilder; + withIndex(): any; + withIndex(x: any): DiscontinuousTimeScaleProviderBuilder; + utc(): DiscontinuousTimeScaleProviderBuilder; + setLocale(locale?: any, formatters?: IFormatters): DiscontinuousTimeScaleProviderBuilder; + indexCalculator(): any; +} + export function discontinuousTimeScaleProviderBuilder() { let initialIndex = 0; - let realDateAccessor = identity as (x: any) => any; + let realDateAccessor = (d: any) => d; let inputDateAccessor = (d: any) => d.date; let indexAccessor = (d: any) => d.idx; let indexMutator = (d: any, idx: any) => ({ ...d, idx }); @@ -150,7 +172,7 @@ export function discontinuousTimeScaleProviderBuilder() { let index = withIndex; if (index === undefined) { - const response = doStuff(realDateAccessor, inputDateAccessor, initialIndex, currentFormatters)(data); + const response = createIndex(realDateAccessor, inputDateAccessor, initialIndex, currentFormatters)(data); index = response.index; } @@ -228,10 +250,10 @@ export function discontinuousTimeScaleProviderBuilder() { }; discontinuousTimeScaleProvider.indexCalculator = function () { - return doStuff(realDateAccessor, inputDateAccessor, initialIndex, currentFormatters); + return createIndex(realDateAccessor, inputDateAccessor, initialIndex, currentFormatters); }; - return discontinuousTimeScaleProvider; + return discontinuousTimeScaleProvider as DiscontinuousTimeScaleProviderBuilder; } export default discontinuousTimeScaleProviderBuilder(); diff --git a/packages/scales/src/financeDiscontinuousScale.ts b/packages/scales/src/financeDiscontinuousScale.ts index 5fbe16dc0..d963318cc 100644 --- a/packages/scales/src/financeDiscontinuousScale.ts +++ b/packages/scales/src/financeDiscontinuousScale.ts @@ -1,4 +1,4 @@ -import { head, isDefined, last } from "@react-financial-charts/core"; +import { head, last } from "@react-financial-charts/core"; import { ascending } from "d3-array"; import { scaleLinear, InterpolatorFactory } from "d3-scale"; import { levelDefinition } from "./levels"; @@ -126,7 +126,7 @@ export default function financeDiscontinuousScale(index: any[], backingLinearSca scale.value = (x: any) => { const d = Math.abs(head(index).index); const row = index[Math.floor(x + d)]; - if (isDefined(row)) { + if (row !== undefined) { const { date } = row; return date; } diff --git a/packages/scales/src/index.ts b/packages/scales/src/index.ts index 6a8422ab1..1d5a152ac 100644 --- a/packages/scales/src/index.ts +++ b/packages/scales/src/index.ts @@ -6,6 +6,13 @@ export { export { default as financeDiscontinuousScale } from "./financeDiscontinuousScale"; export * from "./timeFormat"; -export const defaultScaleProvider = (xScale: ScaleContinuousNumeric | ScaleTime) => { - return (data: any[], xAccessor: any) => ({ data, xScale, xAccessor, displayXAccessor: xAccessor }); +export const defaultScaleProvider = ( + xScale: ScaleContinuousNumeric | ScaleTime, +) => { + return (data: TData[], xAccessor: (data: TData) => TXAxis) => ({ + data, + xScale, + xAccessor, + displayXAccessor: xAccessor, + }); }; diff --git a/packages/stories/src/features/StockChart.tsx b/packages/stories/src/features/StockChart.tsx index 29b738c04..75853c47f 100644 --- a/packages/stories/src/features/StockChart.tsx +++ b/packages/stories/src/features/StockChart.tsx @@ -70,9 +70,9 @@ class StockChart extends React.Component { 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]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max + 5]; const gridHeight = height - margin.top - margin.bottom; diff --git a/packages/stories/src/features/annotations/Annotations.tsx b/packages/stories/src/features/annotations/Annotations.tsx index 112c8327d..d9c4dcd10 100644 --- a/packages/stories/src/features/annotations/Annotations.tsx +++ b/packages/stories/src/features/annotations/Annotations.tsx @@ -42,9 +42,9 @@ class Annotations extends React.Component { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { 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]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { 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]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const { customX, ...cursorProps } = rest; diff --git a/packages/stories/src/features/interaction/Interaction.tsx b/packages/stories/src/features/interaction/Interaction.tsx index 0defd6954..7a5559f6f 100644 --- a/packages/stories/src/features/interaction/Interaction.tsx +++ b/packages/stories/src/features/interaction/Interaction.tsx @@ -46,9 +46,9 @@ class Interaction extends React.Component { 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]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, height, ratio, width, xScale = scaleTime(), yScale } = this.props; const xAccessor = (d: IOHLCData) => d.date; - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); const yAccessor = fiEMA13.accessor(); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const yAccessor = this.macdCalculator.accessor(); const options = this.macdCalculator.options(); diff --git a/packages/stories/src/indicators/rsi/RsiIndicator.tsx b/packages/stories/src/indicators/rsi/RsiIndicator.tsx index af012d564..6fecf8972 100644 --- a/packages/stories/src/indicators/rsi/RsiIndicator.tsx +++ b/packages/stories/src/indicators/rsi/RsiIndicator.tsx @@ -35,9 +35,9 @@ class RSIIndicator extends React.Component { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const yAccessor = this.rsiCalculator.accessor(); diff --git a/packages/stories/src/indicators/sar/SarIndicator.tsx b/packages/stories/src/indicators/sar/SarIndicator.tsx index 1135daee5..01e7821d4 100644 --- a/packages/stories/src/indicators/sar/SarIndicator.tsx +++ b/packages/stories/src/indicators/sar/SarIndicator.tsx @@ -41,9 +41,9 @@ class SARIndicator extends React.Component { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const yAccessor = this.sarCalculator.accessor(); diff --git a/packages/stories/src/indicators/sto/StoIndicator.tsx b/packages/stories/src/indicators/sto/StoIndicator.tsx index 316bf5224..f146411e6 100644 --- a/packages/stories/src/indicators/sto/StoIndicator.tsx +++ b/packages/stories/src/indicators/sto/StoIndicator.tsx @@ -61,9 +61,9 @@ class StoIndicator extends React.Component { 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]; + const min = xAccessor(data[data.length - 1]); + const max = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const gridHeight = height - margin.top - margin.bottom; diff --git a/packages/stories/src/series/area/basicAreaSeries.tsx b/packages/stories/src/series/area/basicAreaSeries.tsx index 985e38958..55cd85579 100644 --- a/packages/stories/src/series/area/basicAreaSeries.tsx +++ b/packages/stories/src/series/area/basicAreaSeries.tsx @@ -24,9 +24,9 @@ class BasicAreaSeries extends React.Component { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; const base = 56; return ( diff --git a/packages/stories/src/series/candlestick/basicCandlestick.tsx b/packages/stories/src/series/candlestick/basicCandlestick.tsx index ce215a443..9e4916098 100644 --- a/packages/stories/src/series/candlestick/basicCandlestick.tsx +++ b/packages/stories/src/series/candlestick/basicCandlestick.tsx @@ -24,9 +24,9 @@ class BasicCandlestick extends React.Component { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(calculatedData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const max = xAccessor(data[data.length - 1]); + const min = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [min, max]; return ( { const { data, xScale, xAccessor, displayXAccessor } = this.xScaleProvider(initialData); - const start = xAccessor(data[data.length - 1]); - const end = xAccessor(data[Math.max(0, data.length - 100)]); - const xExtents = [start, end]; + const maxX = xAccessor(data[data.length - 1]); + const minX = xAccessor(data[Math.max(0, data.length - 100)]); + const xExtents = [minX, maxX]; const maximium = max(data, (d) => d.volume);