From cd22f75bbaf7f2898422f1d9e315d30377f57e31 Mon Sep 17 00:00:00 2001 From: boygirl Date: Mon, 8 Jan 2018 14:23:22 -0800 Subject: [PATCH 1/2] make sure downsample is working for plotting functions --- .../components/victory-zoom-container-demo.js | 17 +++++++++----- .../containers/victory-zoom-container.js | 22 +++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/demo/components/victory-zoom-container-demo.js b/demo/components/victory-zoom-container-demo.js index 60c4103a..a4ec5285 100644 --- a/demo/components/victory-zoom-container-demo.js +++ b/demo/components/victory-zoom-container-demo.js @@ -135,8 +135,8 @@ export default class App extends React.Component { getData() { return range(50).map((i) => { return { - x: i + 20, - y: Math.random() + a: i + 20, + b: Math.random() }; }); } @@ -167,7 +167,7 @@ export default class App extends React.Component { } + containerComponent={} style={{ parent: parentStyle }} data={this.state.transitionData} > @@ -210,7 +210,8 @@ export default class App extends React.Component { containerComponent={ } @@ -222,6 +223,7 @@ export default class App extends React.Component { style={{ parent: parentStyle, data: { fill: "orange" } }} size={15} data={this.state.data} + x="a" y="b" /> @@ -232,7 +234,8 @@ export default class App extends React.Component { containerComponent={ } @@ -243,6 +246,7 @@ export default class App extends React.Component { style={{ parent: parentStyle, data: { fill: "orange" } }} size={15} data={this.state.data} + x="a" y="b" labels={(d) => d.x} labelComponent={} /> @@ -288,10 +292,11 @@ export default class App extends React.Component { - + diff --git a/src/components/containers/victory-zoom-container.js b/src/components/containers/victory-zoom-container.js index a722c52d..05c35403 100644 --- a/src/components/containers/victory-zoom-container.js +++ b/src/components/containers/victory-zoom-container.js @@ -1,6 +1,6 @@ import PropTypes from "prop-types"; import React from "react"; -import { defaults, get } from "lodash"; +import { defaults, get, isFunction } from "lodash"; import ZoomHelpers from "./zoom-helpers"; import { VictoryContainer, VictoryClipContainer, Data, PropTypes as CustomPropTypes @@ -135,14 +135,22 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b }; } - downsampleZoomData(props, childProps, domain) { + downsampleZoomData(props, child, domain) { const { downsample } = props; - const rawData = get(childProps, "data"); + + const getData = (childProps) => { + const { data, x, y } = childProps; + const defaultGetData = child.type && isFunction(child.type.getData) ? + child.type.getData : () => undefined; + // skip costly data formatting if x and y accessors are not present + return Array.isArray(data) && !x && !y ? data : defaultGetData(childProps); + }; + + const data = getData(child.props); + // return undefined if downsample is not run, then default() will replace with child.props.data - if (!downsample || !rawData || !domain) { return undefined; } + if (!downsample || !domain || !data) { return undefined; } - // if data accessors are not used, skip calling expensive Data.formatData - const data = (childProps.x || childProps.y) ? Data.formatData(rawData, childProps) : rawData; const maxPoints = (downsample === true) ? DEFAULT_DOWNSAMPLE : downsample; const dimension = props.zoomDimension || "x"; @@ -195,7 +203,7 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b defaults({ domain: newDomain, data: role === "legend" ? - undefined : this.downsampleZoomData(props, currentChild.props, newDomain) + undefined : this.downsampleZoomData(props, currentChild, newDomain) }, currentChild.props) ); }); From 0bd9330c82e8b57fe51532c68fef1fe8286b75fc Mon Sep 17 00:00:00 2001 From: boygirl Date: Mon, 8 Jan 2018 14:47:22 -0800 Subject: [PATCH 2/2] lint --- src/components/containers/victory-zoom-container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/containers/victory-zoom-container.js b/src/components/containers/victory-zoom-container.js index 05c35403..03b69a7b 100644 --- a/src/components/containers/victory-zoom-container.js +++ b/src/components/containers/victory-zoom-container.js @@ -1,6 +1,6 @@ import PropTypes from "prop-types"; import React from "react"; -import { defaults, get, isFunction } from "lodash"; +import { defaults, isFunction } from "lodash"; import ZoomHelpers from "./zoom-helpers"; import { VictoryContainer, VictoryClipContainer, Data, PropTypes as CustomPropTypes