Skip to content

Commit

Permalink
Merge pull request #1871 from FormidableLabs/bug/log-scale-voronoi
Browse files Browse the repository at this point in the history
use domain min rather than zero for _voronoi point when voronoiDimens…
  • Loading branch information
boygirl authored Jun 1, 2021
2 parents 2ece7f1 + 27a237a commit 625f4a7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
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

0 comments on commit 625f4a7

Please sign in to comment.