Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

make sure downsample is working for plotting functions #547

Merged
merged 2 commits into from Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions demo/components/victory-zoom-container-demo.js
Expand Up @@ -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()
};
});
}
Expand Down Expand Up @@ -167,7 +167,7 @@ export default class App extends React.Component {
<CustomChart style={{ parent: parentStyle }} data={allData} maxPoints={120}/>

<VictoryGroup
containerComponent={<VictoryZoomContainer dimension="y"/>}
containerComponent={<VictoryZoomContainer zoomDimension="y"/>}
style={{ parent: parentStyle }} data={this.state.transitionData}
>
<VictoryLine animate={{ duration: 1500 }} style={{ data: this.state.style }} />
Expand Down Expand Up @@ -210,7 +210,8 @@ export default class App extends React.Component {
containerComponent={
<VictoryZoomContainer
minimumZoom={{ x: 5 }}
dimension="x"
zoomDimension="x"
downsample={10}
clipContainerComponent={
<VictoryClipContainer clipPadding={{ top: 15, bottom: 15 }}/>
}
Expand All @@ -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"
/>
</VictoryPortal>
</VictoryChart>
Expand All @@ -232,7 +234,8 @@ export default class App extends React.Component {
containerComponent={
<VictoryZoomContainer
minimumZoom={{ x: 5 }}
dimension="x"
zoomDimension="x"
downsample={10}
clipContainerComponent={
<VictoryClipContainer clipPadding={{ top: 15, bottom: 15 }}/>
}
Expand All @@ -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={<VictoryTooltip/>}
/>
Expand Down Expand Up @@ -288,10 +292,11 @@ export default class App extends React.Component {
<VictoryArea
style={{ parent: parentStyle, data: { stroke: "#333", fill: "#888", opacity: 0.4 } }}
data={this.state.data}
x="a" y="b"
interpolation="stepBefore"
/>
<VictoryAxis/>
<VictoryLine data={this.state.data} interpolation="stepBefore"/>
<VictoryLine data={this.state.data} x="a" y="b" interpolation="stepBefore"/>
<VictoryAxis dependentAxis/>
</VictoryChart>

Expand Down
22 changes: 15 additions & 7 deletions 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, isFunction } from "lodash";
import ZoomHelpers from "./zoom-helpers";
import {
VictoryContainer, VictoryClipContainer, Data, PropTypes as CustomPropTypes
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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)
);
});
Expand Down