mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-15 20:57:56 +08:00
Remove d3 dependency in crossfilter (#1108)
* Remove d3 dependency in crossfilter
Fixes https://github.com/chanzuckerberg/cellxgene/issues/648
* Revert "Remove d3 dependency in crossfilter"
This reverts commit 03b478f7dc.
* Remove d3 dependency in crossfilter
Fixes https://github.com/chanzuckerberg/cellxgene/issues/648
* Fix typo in docstring
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import _ from "lodash";
|
||||
import { polygonContains } from "d3";
|
||||
|
||||
import Crossfilter from "../../../src/util/typedCrossfilter";
|
||||
|
||||
@@ -334,12 +333,17 @@ describe("ImmutableTypedCrossfilter", () => {
|
||||
);
|
||||
|
||||
test.each([
|
||||
[[[0, 0], [0, 1], [1, 1], [1, 0]]],
|
||||
[[[0, 0], [0, 0.5], [0.5, 0.5], [0.5, 0]]]
|
||||
])("within-polygon %p", polygon => {
|
||||
expect(
|
||||
p.select("coords", { mode: "within-polygon", polygon }).allSelected()
|
||||
).toEqual(_.filter(someData, d => polygonContains(polygon, d.coords)));
|
||||
[
|
||||
[[0, 0], [0, 1], [1, 1], [1, 0]],
|
||||
[true, true, true, true, true, false, true, true, true, true, true, true]
|
||||
],
|
||||
[
|
||||
[[0, 0], [0, 0.5], [0.5, 0.5], [0.5, 0]],
|
||||
[true, true, true, true, false, false, false, true, true, true, false, false]
|
||||
]
|
||||
])("within-polygon %p", (polygon, expected) => {
|
||||
expect(p.select("coords", { mode: "within-polygon", polygon }).allSelected())
|
||||
.toEqual(_.zip(someData, expected).filter(x => x[1]).map(x => x[0]));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
A redo/undo meta reducer for Redux. Designed to work well with the cascadeReducer().
|
||||
A redo/undo meta reducer for Redux. Designed to work well with the cascadeReducer().
|
||||
|
||||
Requires three parameters:
|
||||
* reducer - a reducer, which MUST return an object as state.
|
||||
* undoableKeys - an array of object keys (strings). If any of these keys
|
||||
* undoableKeys - an array of object keys (strings). If any of these keys
|
||||
are in the object/state returned by the reducer, they will be treated as
|
||||
state to be made "undoable".
|
||||
* options - an optional object, which may contain the following parameters:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { polygonContains } from "d3";
|
||||
|
||||
import PositiveIntervals from "./positiveIntervals";
|
||||
import BitArray from "./bitArray";
|
||||
import {
|
||||
@@ -662,7 +660,31 @@ function polygonBoundingBox(polygon) {
|
||||
return [minX, minY, maxX, maxY];
|
||||
}
|
||||
|
||||
/**
|
||||
* withinPolygon determines if a point is within a polygon
|
||||
* Code adapted from https://github.com/d3/d3-polygon/blob/master/src/contains.js
|
||||
* @param {array} polygon - is an array of point arrays of format [[x1, y1], [x2, y2], ...]
|
||||
* @param {float} x - point x coordinate
|
||||
* @param {float} y - point y coordinate
|
||||
* @type {boolean}
|
||||
*/
|
||||
function withinPolygon(polygon, x, y) {
|
||||
// TODO XXX replace
|
||||
return polygonContains(polygon, [x, y]);
|
||||
const n = polygon.length;
|
||||
let p = polygon[n - 1];
|
||||
let x0 = p[0];
|
||||
let y0 = p[1];
|
||||
let x1;
|
||||
let y1;
|
||||
let inside = false;
|
||||
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
p = polygon[i];
|
||||
x1 = p[0];
|
||||
y1 = p[1];
|
||||
|
||||
if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
|
||||
x0 = x1;
|
||||
y0 = y1;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user