@react-financial-charts/core
Advanced tools
Comparing version 1.0.0-alpha.15 to 1.0.0-alpha.16
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.0.0-alpha.16](https://github.com/reactivemarkets/react-financial-charts/compare/v1.0.0-alpha.15...v1.0.0-alpha.16) (2020-09-04) | ||
### Bug Fixes | ||
* **core:** removing colors ([ceb8217](https://github.com/reactivemarkets/react-financial-charts/commit/ceb8217e9c8795787565c3baa1cedc3e693dfb4c)) | ||
# [1.0.0-alpha.15](https://github.com/reactivemarkets/react-financial-charts/compare/v1.0.0-alpha.14...v1.0.0-alpha.15) (2020-09-03) | ||
@@ -8,0 +19,0 @@ |
@@ -171,3 +171,3 @@ import { ScaleContinuousNumeric, ScaleTime } from "d3-scale"; | ||
amIOnTop: (id: string) => boolean; | ||
handleContextMenu: (mouseXY: any, e: any) => void; | ||
handleContextMenu: (mouseXY: number[], e: React.MouseEvent) => void; | ||
calculateStateForDomain: (newDomain: any) => { | ||
@@ -174,0 +174,0 @@ xScale: ScaleTime<number, number> | ScaleContinuousNumeric<number, number>; |
@@ -22,3 +22,3 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
const CANDIDATES_FOR_RESET = ["seriesName"]; | ||
function shouldResetChart(thisProps, nextProps) { | ||
const shouldResetChart = (thisProps, nextProps) => { | ||
return !CANDIDATES_FOR_RESET.every((key) => { | ||
@@ -28,4 +28,4 @@ const result = shallowEqual(thisProps[key], nextProps[key]); | ||
}); | ||
} | ||
function getCursorStyle() { | ||
}; | ||
const getCursorStyle = () => { | ||
const tooltipStyle = ` | ||
@@ -72,16 +72,16 @@ .react-financial-charts-grabbing-cursor { | ||
return React.createElement("style", { type: "text/css" }, tooltipStyle); | ||
} | ||
function getDimensions(props) { | ||
}; | ||
const getDimensions = (props) => { | ||
const { margin, height, width } = props; | ||
return { | ||
height: props.height - props.margin.top - props.margin.bottom, | ||
width: props.width - props.margin.left - props.margin.right, | ||
height: height - margin.top - margin.bottom, | ||
width: width - margin.left - margin.right, | ||
}; | ||
} | ||
function getXScaleDirection(flipXScale) { | ||
}; | ||
const getXScaleDirection = (flipXScale) => { | ||
return flipXScale ? -1 : 1; | ||
} | ||
function calculateFullData(props) { | ||
const { data: fullData, plotFull, xScale, clamp, pointsPerPxThreshold, flipXScale } = props; | ||
const { xAccessor, displayXAccessor, minPointsPerPxThreshold } = props; | ||
const useWholeData = isDefined(plotFull) ? plotFull : xAccessor === identity; | ||
}; | ||
const calculateFullData = (props) => { | ||
const { data: fullData, plotFull, xScale, clamp, pointsPerPxThreshold, flipXScale, xAccessor, displayXAccessor, minPointsPerPxThreshold, } = props; | ||
const useWholeData = plotFull !== undefined ? plotFull : xAccessor === identity; | ||
const { filterData } = evaluator({ | ||
@@ -102,3 +102,3 @@ xScale, | ||
}; | ||
} | ||
}; | ||
const resetChart = (props) => { | ||
@@ -115,8 +115,8 @@ const state = calculateState(props); | ||
}; | ||
function updateChart(newState, initialXScale, props, lastItemWasVisible, initialChartConfig) { | ||
const updateChart = (newState, initialXScale, props, lastItemWasVisible, initialChartConfig) => { | ||
const { fullData, xScale, xAccessor, displayXAccessor, filterData } = newState; | ||
const lastItem = last(fullData); | ||
const lastXItem = xAccessor(lastItem); | ||
const [start, end] = initialXScale.domain(); | ||
const { postCalculator, children, padding, flipXScale } = props; | ||
const { maintainPointsPerPixelOnResize } = props; | ||
const { postCalculator, children, padding, flipXScale, maintainPointsPerPixelOnResize } = props; | ||
const direction = getXScaleDirection(flipXScale); | ||
@@ -126,3 +126,3 @@ const dimensions = getDimensions(props); | ||
let initialPlotData; | ||
if (!lastItemWasVisible || end >= xAccessor(lastItem)) { | ||
if (!lastItemWasVisible || end >= lastXItem) { | ||
// resize comes here... | ||
@@ -132,5 +132,5 @@ // get plotData between [start, end] and do not change the domain | ||
const [newRangeStart, newRangeEnd] = updatedXScale.range(); | ||
const newDomainExtent = ((newRangeEnd - newRangeStart) / (rangeEnd - rangeStart)) * (end - start); | ||
const newStart = maintainPointsPerPixelOnResize ? end - newDomainExtent : start; | ||
const lastItemX = initialXScale(xAccessor(lastItem)); | ||
const newDomainExtent = ((newRangeEnd - newRangeStart) / (rangeEnd - rangeStart)) * (end.valueOf() - start.valueOf()); | ||
const newStart = maintainPointsPerPixelOnResize ? end.valueOf() - newDomainExtent : start; | ||
const lastItemX = initialXScale(lastXItem); | ||
const response = filterData(fullData, [newStart, end], xAccessor, updatedXScale, { | ||
@@ -143,11 +143,11 @@ fallbackStart: start, | ||
} | ||
else if (lastItemWasVisible && end < xAccessor(lastItem)) { | ||
else if (lastItemWasVisible && end < lastXItem) { | ||
// this is when a new item is added and last item was visible | ||
// so slide over and show the new item also | ||
// get plotData between [xAccessor(l) - (end - start), xAccessor(l)] and DO change the domain | ||
const dx = initialXScale(xAccessor(lastItem)) - initialXScale.range()[1]; | ||
const dx = initialXScale(lastXItem) - initialXScale.range()[1]; | ||
const [newStart, newEnd] = initialXScale | ||
.range() | ||
.map((x) => x + dx) | ||
.map(initialXScale.invert); | ||
.map((x) => initialXScale.invert(x)); | ||
const response = filterData(fullData, [newStart, newEnd], xAccessor, updatedXScale); | ||
@@ -167,4 +167,4 @@ initialPlotData = response.plotData; | ||
}; | ||
} | ||
function calculateState(props) { | ||
}; | ||
const calculateState = (props) => { | ||
const { xAccessor: inputXAccesor, xExtents: xExtentsProp, data, padding, flipXScale } = props; | ||
@@ -187,4 +187,4 @@ const direction = getXScaleDirection(flipXScale); | ||
}; | ||
} | ||
function setXRange(xScale, dimensions, padding, direction = 1) { | ||
}; | ||
const setXRange = (xScale, dimensions, padding, direction = 1) => { | ||
if (xScale.rangeRoundPoints) { | ||
@@ -213,4 +213,4 @@ if (isNaN(padding)) { | ||
return xScale; | ||
} | ||
function pinchCoordinates(pinch) { | ||
}; | ||
const pinchCoordinates = (pinch) => { | ||
const { touch1Pos, touch2Pos } = pinch; | ||
@@ -221,7 +221,7 @@ return { | ||
}; | ||
} | ||
function isInteractionEnabled(xScale, xAccessor, data) { | ||
}; | ||
const isInteractionEnabled = (xScale, xAccessor, data) => { | ||
const interaction = !isNaN(xScale(xAccessor(head(data)))) && isDefined(xScale.invert); | ||
return interaction; | ||
} | ||
}; | ||
export class ChartCanvas extends React.Component { | ||
@@ -292,3 +292,2 @@ constructor(props) { | ||
const updatedScale = initialXScale.copy().domain(domain); | ||
// @ts-ignore | ||
const chartConfig = getChartConfigWithUpdatedYScales(initialChartConfig, { plotData, xAccessor, displayXAccessor, fullData }, updatedScale.domain()); | ||
@@ -303,4 +302,3 @@ return { | ||
const { xScale: initialPinchXScale } = initialPinch; | ||
const { xScale: initialXScale, chartConfig: initialChartConfig, plotData: initialPlotData, xAccessor, displayXAccessor, } = this.state; | ||
const { filterData } = this.state; | ||
const { xScale: initialXScale, chartConfig: initialChartConfig, plotData: initialPlotData, xAccessor, displayXAccessor, filterData, } = this.state; | ||
const { fullData } = this; | ||
@@ -316,3 +314,2 @@ const { postCalculator = ChartCanvas.defaultProps.postCalculator } = this.props; | ||
const newDomain = [x, y].map(initialPinchXScale.invert); | ||
// var domainR = initial.right + right; | ||
const { plotData: beforePlotData, domain } = filterData(fullData, newDomain, xAccessor, initialPinchXScale, { | ||
@@ -325,3 +322,2 @@ currentPlotData: initialPlotData, | ||
const mouseXY = finalPinch.touch1Pos; | ||
// @ts-ignore | ||
const chartConfig = getChartConfigWithUpdatedYScales(initialChartConfig, { plotData, xAccessor, displayXAccessor, fullData }, updatedScale.domain()); | ||
@@ -741,4 +737,4 @@ const currentItem = getCurrentItem(updatedScale, xAccessor, mouseXY, plotData); | ||
const reset = shouldResetChart(this.props, nextProps); | ||
const interaction = isInteractionEnabled(this.state.xScale, this.state.xAccessor, this.state.plotData); | ||
const { chartConfig: initialChartConfig } = this.state; | ||
const { chartConfig: initialChartConfig, plotData, xAccessor, xScale } = this.state; | ||
const interaction = isInteractionEnabled(xScale, xAccessor, plotData); | ||
let newState; | ||
@@ -751,8 +747,9 @@ if (!interaction || reset || !shallowEqual(this.props.xExtents, nextProps.xExtents)) { | ||
else { | ||
const [start, end] = this.state.xScale.domain(); | ||
const [start, end] = xScale.domain(); | ||
const prevLastItem = last(this.fullData); | ||
const calculatedState = calculateFullData(nextProps); | ||
const { xAccessor } = calculatedState; | ||
const lastItemWasVisible = xAccessor(prevLastItem) <= end && xAccessor(prevLastItem) >= start; | ||
newState = updateChart(calculatedState, this.state.xScale, nextProps, lastItemWasVisible, initialChartConfig); | ||
const previousX = xAccessor(prevLastItem); | ||
const lastItemWasVisible = previousX <= end && previousX >= start; | ||
newState = updateChart(calculatedState, xScale, nextProps, lastItemWasVisible, initialChartConfig); | ||
} | ||
@@ -759,0 +756,0 @@ const { fullData } = newState, state = __rest(newState, ["fullData"]); |
@@ -98,9 +98,9 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
this.handleMouseMove = () => { | ||
const e = d3Event; | ||
const { onMouseMove, mouseMove } = this.props; | ||
if (onMouseMove === undefined) { | ||
return; | ||
} | ||
if (this.mouseInteraction && mouseMove && !this.state.panInProgress) { | ||
const newPos = mouse(this.ref.current); | ||
if (onMouseMove !== undefined) { | ||
onMouseMove(newPos, "mouse", e); | ||
} | ||
onMouseMove(newPos, "mouse", d3Event); | ||
} | ||
@@ -149,3 +149,4 @@ }; | ||
this.handleDrag = () => { | ||
if (this.props.onDrag === undefined) { | ||
const { onDrag } = this.props; | ||
if (onDrag === undefined) { | ||
return; | ||
@@ -160,3 +161,3 @@ } | ||
const mouseXY = mouse(this.ref.current); | ||
this.props.onDrag({ | ||
onDrag({ | ||
startPos: dragStartPosition, | ||
@@ -310,3 +311,4 @@ mouseXY, | ||
} | ||
const touchXY = touchPosition(getTouchProps(e.touches[0]), e); | ||
const touch = getTouchProps(e.touches[0]); | ||
const touchXY = touchPosition(touch, e); | ||
onMouseMove(touchXY, "touch", e); | ||
@@ -316,4 +318,3 @@ }; | ||
this.mouseInteraction = false; | ||
const { pan: panEnabled, chartConfig, onMouseMove } = this.props; | ||
const { xScale, onPanEnd } = this.props; | ||
const { pan: panEnabled, chartConfig, onMouseMove, xScale, onPanEnd } = this.props; | ||
if (e.touches.length === 1) { | ||
@@ -371,5 +372,2 @@ this.panHappened = false; | ||
this.handlePinchZoom = () => { | ||
const e = d3Event; | ||
const [touch1Pos, touch2Pos] = touches(this.ref.current); | ||
const { xScale, zoom: zoomEnabled, onPinchZoom } = this.props; | ||
const { pinchZoomStart } = this.state; | ||
@@ -379,10 +377,14 @@ if (pinchZoomStart === undefined) { | ||
} | ||
const { xScale, zoom: zoomEnabled, onPinchZoom } = this.props; | ||
if (!zoomEnabled || onPinchZoom === undefined) { | ||
return; | ||
} | ||
const e = d3Event; | ||
const [touch1Pos, touch2Pos] = touches(this.ref.current); | ||
const { chartsToPan } = pinchZoomStart, initialPinch = __rest(pinchZoomStart, ["chartsToPan"]); | ||
if (zoomEnabled && onPinchZoom !== undefined) { | ||
onPinchZoom(initialPinch, { | ||
touch1Pos, | ||
touch2Pos, | ||
xScale, | ||
}, e); | ||
} | ||
onPinchZoom(initialPinch, { | ||
touch1Pos, | ||
touch2Pos, | ||
xScale, | ||
}, e); | ||
}; | ||
@@ -393,3 +395,2 @@ this.handlePinchZoomEnd = () => { | ||
select(win).on(TOUCHMOVE, null).on(TOUCHEND, null); | ||
const { zoom: zoomEnabled, onPinchZoomEnd } = this.props; | ||
const { pinchZoomStart } = this.state; | ||
@@ -400,2 +401,3 @@ if (pinchZoomStart === undefined) { | ||
const { chartsToPan } = pinchZoomStart, initialPinch = __rest(pinchZoomStart, ["chartsToPan"]); | ||
const { zoom: zoomEnabled, onPinchZoomEnd } = this.props; | ||
if (zoomEnabled && onPinchZoomEnd) { | ||
@@ -402,0 +404,0 @@ onPinchZoomEnd(initialPinch, e); |
@@ -18,6 +18,5 @@ import * as PropTypes from "prop-types"; | ||
const { margin, ratio } = this.context; | ||
const { chartConfig } = moreProps; | ||
const canvasOriginX = 0.5 * ratio + chartConfig.origin[0] + margin.left; | ||
const canvasOriginY = 0.5 * ratio + chartConfig.origin[1] + margin.top; | ||
const { chartConfig: { width, height }, } = moreProps; | ||
const { chartConfig: { width, height, origin }, } = moreProps; | ||
const canvasOriginX = 0.5 * ratio + origin[0] + margin.left; | ||
const canvasOriginY = 0.5 * ratio + origin[1] + margin.top; | ||
const { clip, edgeClip } = this.props; | ||
@@ -24,0 +23,0 @@ ctx.setTransform(1, 0, 0, 1, 0, 0); |
@@ -7,2 +7,3 @@ import * as PropTypes from "prop-types"; | ||
readonly canvasDraw?: (ctx: CanvasRenderingContext2D, moreProps: any) => void; | ||
readonly canvasToDraw?: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined; | ||
readonly clip?: boolean; | ||
@@ -14,3 +15,2 @@ readonly disablePan?: boolean; | ||
readonly interactiveCursorClass?: string; | ||
readonly canvasToDraw?: (contexts: ICanvasContexts) => CanvasRenderingContext2D | undefined; | ||
readonly isHover?: (moreProps: any, e: React.MouseEvent) => boolean; | ||
@@ -17,0 +17,0 @@ readonly onClick?: (e: React.MouseEvent, moreProps: any) => void; |
@@ -207,3 +207,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
isHover(e) { | ||
return this.props.isHover !== undefined ? this.props.isHover(this.getMoreProps(), e) : false; | ||
const { isHover } = this.props; | ||
if (isHover === undefined) { | ||
return false; | ||
} | ||
return isHover(this.getMoreProps(), e); | ||
} | ||
@@ -210,0 +214,0 @@ getPanConditions() { |
@@ -8,11 +8,9 @@ /// <reference types="react" /> | ||
export * from "./shallowEqual"; | ||
export { default as mappedSlidingWindow } from "./mappedSlidingWindow"; | ||
export { default as accumulatingWindow } from "./accumulatingWindow"; | ||
export * from "./barWidth"; | ||
export * from "./colors"; | ||
export * from "./strokeDasharray"; | ||
export * from "./PureComponent"; | ||
export declare function sign(x: any): number; | ||
export declare function path(loc?: never[]): (obj: any, defaultValue?: any) => any; | ||
export declare function functor(v: any): any; | ||
export declare const sign: (x: any) => number; | ||
export declare const path: (loc?: never[]) => (obj: any, defaultValue?: any) => any; | ||
export declare const functor: (v: any) => any; | ||
export declare function getClosestValue(inputValue: any, currentValue: any): any; | ||
@@ -33,3 +31,2 @@ export declare function d3Window(node: any): any; | ||
export declare function head(array: any[], accessor?: any): any; | ||
export declare function tail<T>(array: T[], accessor?: any): unknown[] | undefined; | ||
export declare const first: typeof head; | ||
@@ -36,0 +33,0 @@ export declare function last(array: any[], accessor?: any): any; |
@@ -7,13 +7,11 @@ export { default as zipper } from "./zipper"; | ||
export * from "./shallowEqual"; | ||
export { default as mappedSlidingWindow } from "./mappedSlidingWindow"; | ||
export { default as accumulatingWindow } from "./accumulatingWindow"; | ||
export * from "./barWidth"; | ||
export * from "./colors"; | ||
export * from "./strokeDasharray"; | ||
export * from "./PureComponent"; | ||
export function sign(x) { | ||
export const sign = (x) => { | ||
// @ts-ignore | ||
return (x > 0) - (x < 0); | ||
} | ||
export function path(loc = []) { | ||
}; | ||
export const path = (loc = []) => { | ||
const key = Array.isArray(loc) ? loc : [loc]; | ||
@@ -31,6 +29,6 @@ const length = key.length; | ||
}; | ||
} | ||
export function functor(v) { | ||
}; | ||
export const functor = (v) => { | ||
return typeof v === "function" ? v : () => v; | ||
} | ||
}; | ||
export function getClosestValue(inputValue, currentValue) { | ||
@@ -75,8 +73,2 @@ const values = Array.isArray(inputValue) ? inputValue : [inputValue]; | ||
} | ||
export function tail(array, accessor) { | ||
if (accessor && array) { | ||
return array.map(accessor).slice(1); | ||
} | ||
return array ? array.slice(1) : undefined; | ||
} | ||
export const first = head; | ||
@@ -83,0 +75,0 @@ export function last(array, accessor) { |
{ | ||
"name": "@react-financial-charts/core", | ||
"version": "1.0.0-alpha.15", | ||
"version": "1.0.0-alpha.16", | ||
"description": "Core code for react-financial-charts", | ||
@@ -36,3 +36,3 @@ "publishConfig": { | ||
"build": "npm run clean && npm run compile", | ||
"clean": "rimraf lib", | ||
"clean": "rimraf lib coverage", | ||
"compile": "tsc -p tsconfig.json", | ||
@@ -44,4 +44,4 @@ "test": "jest", | ||
"@types/d3-scale": "^2.2.0", | ||
"d3-array": "^2.5.0", | ||
"d3-scale": "^3.2.1", | ||
"d3-array": "^2.7.1", | ||
"d3-scale": "^2.2.2", | ||
"d3-selection": "^1.4.2", | ||
@@ -55,3 +55,3 @@ "lodash.flattendeep": "^4.4.0", | ||
}, | ||
"gitHead": "629968753ea1c094dab3931cf7eea194062cdc38" | ||
"gitHead": "3395829dd6bc7677d8a358ef2a78ed2cfbb8d58b" | ||
} |
@@ -7,15 +7,13 @@ export { default as zipper } from "./zipper"; | ||
export * from "./shallowEqual"; | ||
export { default as mappedSlidingWindow } from "./mappedSlidingWindow"; | ||
export { default as accumulatingWindow } from "./accumulatingWindow"; | ||
export * from "./barWidth"; | ||
export * from "./colors"; | ||
export * from "./strokeDasharray"; | ||
export * from "./PureComponent"; | ||
export function sign(x: any) { | ||
export const sign = (x: any) => { | ||
// @ts-ignore | ||
return (x > 0) - (x < 0); | ||
} | ||
}; | ||
export function path(loc = []) { | ||
export const path = (loc = []) => { | ||
const key = Array.isArray(loc) ? loc : [loc]; | ||
@@ -35,7 +33,7 @@ const length = key.length; | ||
}; | ||
} | ||
}; | ||
export function functor(v: any) { | ||
export const functor = (v: any) => { | ||
return typeof v === "function" ? v : () => v; | ||
} | ||
}; | ||
@@ -90,9 +88,2 @@ export function getClosestValue(inputValue: any, currentValue: any) { | ||
export function tail<T>(array: T[], accessor?: any) { | ||
if (accessor && array) { | ||
return array.map(accessor).slice(1); | ||
} | ||
return array ? array.slice(1) : undefined; | ||
} | ||
export const first = head; | ||
@@ -99,0 +90,0 @@ |
@@ -17,3 +17,2 @@ export type strokeDashTypes = | ||
const a = getStrokeDasharray(type).split(","); | ||
if (a.length === 1) { | ||
@@ -20,0 +19,0 @@ return []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
384653
93
6871
+ Addedd3-array@1.2.4(transitive)
+ Addedd3-collection@1.0.7(transitive)
+ Addedd3-color@1.4.1(transitive)
+ Addedd3-format@1.4.5(transitive)
+ Addedd3-interpolate@1.4.0(transitive)
+ Addedd3-scale@2.2.2(transitive)
+ Addedd3-time@1.1.0(transitive)
+ Addedd3-time-format@2.3.0(transitive)
- Removedd3-color@2.0.0(transitive)
- Removedd3-format@2.0.0(transitive)
- Removedd3-interpolate@2.0.1(transitive)
- Removedd3-scale@3.3.0(transitive)
- Removedd3-time@2.1.1(transitive)
- Removedd3-time-format@3.0.0(transitive)
Updatedd3-array@^2.7.1
Updatedd3-scale@^2.2.2