Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use domain min rather than zero for _voronoi point when voronoiDimens… #1871

Merged
merged 1 commit into from
Jun 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions demo/js/components/victory-voronoi-container-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ import { Flyout, VictoryTooltip } from "Packages/victory-tooltip/src/index";
import { VictoryLegend } from "Packages/victory-legend/src/index";
import { VictoryLabel, VictoryTheme } from "Packages/victory-core/src/index";

const series1 = [
{ x: 0, y: 2500 },
{ x: 2, y: 3300 },
{ x: 4, y: 4300 },
{ x: 6, y: 2400 },
{ x: 8, y: 3300 },
{ x: 10, y: 5400 },
{ x: 12, y: 8900 }
];

const series2 = [
{ x: 0, y: 200 },
{ x: 2, y: 3100 },
{ x: 4, y: 2500 },
{ x: 6, y: 870 },
{ x: 8, y: 2300 },
{ x: 10, y: 550 },
{ x: 12, y: 5200 }
];

class App extends React.Component {
constructor() {
super();
Expand Down Expand Up @@ -82,6 +102,22 @@ class App extends React.Component {
return (
<div className="demo">
<div style={containerStyle}>
<VictoryChart
style={chartStyle}
scale={{ y: "log" }}
containerComponent={
<VictoryVoronoiContainer
voronoiDimension="x"
labels={({ datum }) => `y: ${datum.y}`}
/>
}
>
<VictoryScatter
style={{ data: { fill: "red" }, labels: { fill: "red" } }}
data={series1}
/>
<VictoryScatter data={series2} />
</VictoryChart>
<VictoryChart
style={chartStyle}
domain={{ y: [0, 6] }}
Expand Down
11 changes: 8 additions & 3 deletions packages/victory-voronoi-container/src/voronoi-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Selection, Data, Helpers } from "victory-core";
import { Collection, Selection, Data, Helpers } from "victory-core";
import { assign, throttle, isFunction, isEmpty, includes, isString, isRegExp } from "lodash";
import isEqual from "react-fast-compare";
import Delaunay from "delaunay-find/lib/index.js";
Expand All @@ -24,6 +24,10 @@ const VoronoiHelpers = {
},

getDatasets(props) {
const minDomain = {
x: Collection.getMinValue(props.domain.x),
y: Collection.getMinValue(props.domain.y)
};
const children = React.Children.toArray(props.children);
const addMeta = (data, name, child) => {
const continuous = child && child.type && child.type.continuous;
Expand All @@ -32,10 +36,11 @@ const VoronoiHelpers = {
const { x, y, y0, x0 } = Helpers.getPoint(datum);
const voronoiX = (+x + +x0) / 2;
const voronoiY = (+y + +y0) / 2;

return assign(
{
_voronoiX: props.voronoiDimension === "y" ? 0 : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? 0 : voronoiY,
_voronoiX: props.voronoiDimension === "y" ? minDomain.x : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? minDomain.y : voronoiY,
eventKey: index,
childName: name,
continuous,
Expand Down