plottable 3.9.0-dev-78-gfb876e95 → 3.9.0-dev-80-g90701cde
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/core/version.js +1 -1
- package/build/src/plots/barPlot.d.ts +6 -0
- package/build/src/plots/barPlot.js +12 -0
- package/build/src/plots/plot.d.ts +2 -0
- package/build/src/plots/plot.js +2 -0
- package/build/src/plots/rectanglePlot.d.ts +5 -0
- package/build/src/plots/rectanglePlot.js +11 -0
- package/build/src/plots/scatterPlot.d.ts +11 -0
- package/build/src/plots/scatterPlot.js +27 -0
- package/build/src/utils/entityStore.d.ts +6 -3
- package/build/src/utils/rTree.d.ts +11 -2
- package/build/src/utils/rTree.js +15 -3
- package/package.json +1 -1
- package/plottable.js +67 -3
- package/plottable.js.map +1 -1
|
@@ -10,4 +10,4 @@ exports.version = void 0;
|
|
|
10
10
|
* real version number during the dist phase for for npm module publishing. Modifying this line should
|
|
11
11
|
* be accompanied by modifying the "sed-version" task in package.json accordingly.
|
|
12
12
|
*/
|
|
13
|
-
exports.version = "3.9.0-dev-
|
|
13
|
+
exports.version = "3.9.0-dev-80-g90701cde";
|
|
@@ -199,6 +199,7 @@ export declare class Bar<X, Y> extends XYPlot<X, Y> {
|
|
|
199
199
|
* - If the query point is inside a bar, returns the PlotEntity for that bar.
|
|
200
200
|
* - Otherwise, gets the nearest PlotEntity by the positional direction (X for vertical, Y for horizontal),
|
|
201
201
|
* breaking ties with the secondary direction.
|
|
202
|
+
* - Remaining ties, such as overlapping bars, go to the bar drawn last (the last Dataset, then the last datum).
|
|
202
203
|
* Returns undefined if no PlotEntity can be found.
|
|
203
204
|
*
|
|
204
205
|
* @param {Point} queryPoint
|
|
@@ -243,6 +244,11 @@ export declare class Bar<X, Y> extends XYPlot<X, Y> {
|
|
|
243
244
|
protected _updateThicknessAttr(): void;
|
|
244
245
|
private _barPixelThickness;
|
|
245
246
|
entities(datasets?: Dataset[]): IPlotEntity[];
|
|
247
|
+
/**
|
|
248
|
+
* Undrawn bars stay in `_getDataToDraw` as null placeholders, so the drawer
|
|
249
|
+
* indexes each bar's element by its dataset index
|
|
250
|
+
*/
|
|
251
|
+
protected _buildLightweightPlotEntities(datasets: Dataset[]): Plots.ILightweightPlotEntity[];
|
|
246
252
|
protected _entityBounds(entity: Plots.IPlotEntity | Plots.ILightweightPlotEntity): Pick<DOMRect, "height" | "width" | "x" | "y">;
|
|
247
253
|
/**
|
|
248
254
|
* The rectangular bounds of a bar. Note that the x/y coordinates are not the
|
|
@@ -255,6 +255,7 @@ var Bar = /** @class */ (function (_super) {
|
|
|
255
255
|
* - If the query point is inside a bar, returns the PlotEntity for that bar.
|
|
256
256
|
* - Otherwise, gets the nearest PlotEntity by the positional direction (X for vertical, Y for horizontal),
|
|
257
257
|
* breaking ties with the secondary direction.
|
|
258
|
+
* - Remaining ties, such as overlapping bars, go to the bar drawn last (the last Dataset, then the last datum).
|
|
258
259
|
* Returns undefined if no PlotEntity can be found.
|
|
259
260
|
*
|
|
260
261
|
* @param {Point} queryPoint
|
|
@@ -631,6 +632,17 @@ var Bar = /** @class */ (function (_super) {
|
|
|
631
632
|
var entities = _super.prototype.entities.call(this, datasets);
|
|
632
633
|
return entities;
|
|
633
634
|
};
|
|
635
|
+
/**
|
|
636
|
+
* Undrawn bars stay in `_getDataToDraw` as null placeholders, so the drawer
|
|
637
|
+
* indexes each bar's element by its dataset index
|
|
638
|
+
*/
|
|
639
|
+
Bar.prototype._buildLightweightPlotEntities = function (datasets) {
|
|
640
|
+
var lightweightPlotEntities = _super.prototype._buildLightweightPlotEntities.call(this, datasets);
|
|
641
|
+
lightweightPlotEntities.forEach(function (lightweightPlotEntity) {
|
|
642
|
+
lightweightPlotEntity.validDatumIndex = lightweightPlotEntity.index;
|
|
643
|
+
});
|
|
644
|
+
return lightweightPlotEntities;
|
|
645
|
+
};
|
|
634
646
|
Bar.prototype._entityBounds = function (entity) {
|
|
635
647
|
var datum = entity.datum, index = entity.index, dataset = entity.dataset;
|
|
636
648
|
return this._pixelBounds(datum, index, dataset);
|
|
@@ -306,6 +306,8 @@ export declare class Plot extends Component {
|
|
|
306
306
|
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
307
307
|
* or undefined if no {Plots.PlotEntity} can be found.
|
|
308
308
|
*
|
|
309
|
+
* If several Entities are equally near, returns the one drawn last (the last Dataset, then the last datum).
|
|
310
|
+
*
|
|
309
311
|
* @param {Point} queryPoint
|
|
310
312
|
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
311
313
|
*/
|
package/build/src/plots/plot.js
CHANGED
|
@@ -685,6 +685,8 @@ var Plot = /** @class */ (function (_super) {
|
|
|
685
685
|
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
686
686
|
* or undefined if no {Plots.PlotEntity} can be found.
|
|
687
687
|
*
|
|
688
|
+
* If several Entities are equally near, returns the one drawn last (the last Dataset, then the last datum).
|
|
689
|
+
*
|
|
688
690
|
* @param {Point} queryPoint
|
|
689
691
|
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
690
692
|
*/
|
|
@@ -101,6 +101,11 @@ export declare class Rectangle<X, Y> extends XYPlot<X, Y> {
|
|
|
101
101
|
* @returns {PlotEntity[]} The PlotEntities at the particular point
|
|
102
102
|
*/
|
|
103
103
|
entitiesAt(point: Point): Plots.IPlotEntity[];
|
|
104
|
+
/**
|
|
105
|
+
* Undrawn rectangles stay in `_getDataToDraw` as null placeholders, so the
|
|
106
|
+
* drawer indexes each rectangle's element by its dataset index
|
|
107
|
+
*/
|
|
108
|
+
protected _buildLightweightPlotEntities(datasets: Dataset[]): Plots.ILightweightPlotEntity[];
|
|
104
109
|
protected _entityBounds(entity: Plots.IPlotEntity | Plots.ILightweightPlotEntity): Pick<DOMRect, "height" | "width" | "x" | "y">;
|
|
105
110
|
private _entityBBox;
|
|
106
111
|
/**
|
|
@@ -170,6 +170,17 @@ var Rectangle = /** @class */ (function (_super) {
|
|
|
170
170
|
return x <= point.x && point.x <= x + width && y <= point.y && point.y <= y + height;
|
|
171
171
|
});
|
|
172
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* Undrawn rectangles stay in `_getDataToDraw` as null placeholders, so the
|
|
175
|
+
* drawer indexes each rectangle's element by its dataset index
|
|
176
|
+
*/
|
|
177
|
+
Rectangle.prototype._buildLightweightPlotEntities = function (datasets) {
|
|
178
|
+
var lightweightPlotEntities = _super.prototype._buildLightweightPlotEntities.call(this, datasets);
|
|
179
|
+
lightweightPlotEntities.forEach(function (lightweightPlotEntity) {
|
|
180
|
+
lightweightPlotEntity.validDatumIndex = lightweightPlotEntity.index;
|
|
181
|
+
});
|
|
182
|
+
return lightweightPlotEntities;
|
|
183
|
+
};
|
|
173
184
|
Rectangle.prototype._entityBounds = function (entity) {
|
|
174
185
|
var datum = entity.datum, index = entity.index, dataset = entity.dataset;
|
|
175
186
|
return this._entityBBox(datum, index, dataset, this._getAttrToProjector());
|
|
@@ -77,6 +77,17 @@ export declare class Scatter<X, Y> extends XYPlot<X, Y> {
|
|
|
77
77
|
* @returns {PlotEntity[]}
|
|
78
78
|
*/
|
|
79
79
|
entitiesAt(p: Point): IPlotEntity[];
|
|
80
|
+
/**
|
|
81
|
+
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
82
|
+
* or undefined if no {Plots.PlotEntity} can be found.
|
|
83
|
+
*
|
|
84
|
+
* If the query point is inside several Entities' bounding boxes, returns the
|
|
85
|
+
* one whose position is nearest, then the one drawn last.
|
|
86
|
+
*
|
|
87
|
+
* @param {Point} queryPoint
|
|
88
|
+
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
89
|
+
*/
|
|
90
|
+
entityNearest(queryPoint: Point): IPlotEntity;
|
|
80
91
|
/**
|
|
81
92
|
* Get whether bar labels are enabled.
|
|
82
93
|
*
|
|
@@ -143,6 +143,33 @@ var Scatter = /** @class */ (function (_super) {
|
|
|
143
143
|
return x - size / 2 <= p.x && p.x <= x + size / 2 && y - size / 2 <= p.y && p.y <= y + size / 2;
|
|
144
144
|
});
|
|
145
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
148
|
+
* or undefined if no {Plots.PlotEntity} can be found.
|
|
149
|
+
*
|
|
150
|
+
* If the query point is inside several Entities' bounding boxes, returns the
|
|
151
|
+
* one whose position is nearest, then the one drawn last.
|
|
152
|
+
*
|
|
153
|
+
* @param {Point} queryPoint
|
|
154
|
+
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
155
|
+
*/
|
|
156
|
+
Scatter.prototype.entityNearest = function (queryPoint) {
|
|
157
|
+
var containing = this._getEntityStore().entitiesInBounds({ x: queryPoint.x, y: queryPoint.y, width: 0, height: 0 });
|
|
158
|
+
if (containing.length === 0) {
|
|
159
|
+
return _super.prototype.entityNearest.call(this, queryPoint);
|
|
160
|
+
}
|
|
161
|
+
containing.sort(function (a, b) { return a.datasetIndex - b.datasetIndex || a.index - b.index; });
|
|
162
|
+
var nearest;
|
|
163
|
+
var minDistSquared = Infinity;
|
|
164
|
+
containing.forEach(function (entity) {
|
|
165
|
+
var distSquared = Utils.Math.distanceSquared(entity.position, queryPoint);
|
|
166
|
+
if (distSquared <= minDistSquared) {
|
|
167
|
+
nearest = entity;
|
|
168
|
+
minDistSquared = distSquared;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return this._lightweightPlotEntityToPlotEntity(nearest);
|
|
172
|
+
};
|
|
146
173
|
Scatter.prototype.labelsEnabled = function (enabled) {
|
|
147
174
|
if (enabled == null) {
|
|
148
175
|
return this._labelsEnabled;
|
|
@@ -27,7 +27,8 @@ export interface IEntityStore<T extends IPositionedEntity> {
|
|
|
27
27
|
*/
|
|
28
28
|
addAll(entities: T[], entityBoundsFactory: (entity: T) => IEntityBounds, bounds?: Bounds): void;
|
|
29
29
|
/**
|
|
30
|
-
* Returns the entity closest to a given {Point}
|
|
30
|
+
* Returns the entity closest to a given {Point}. Ties are broken in favor of
|
|
31
|
+
* the entity added last.
|
|
31
32
|
*
|
|
32
33
|
* Note that if a {Bounds} was provided to the `addAll` method, entities
|
|
33
34
|
* outside those bounds will not be returned by this method.
|
|
@@ -38,7 +39,8 @@ export interface IEntityStore<T extends IPositionedEntity> {
|
|
|
38
39
|
entityNearest(point: Point): T;
|
|
39
40
|
/**
|
|
40
41
|
* Returns the entity closest to a given {Point} in the x-dimension. Ties are
|
|
41
|
-
* broken with a sort in the y-dimension
|
|
42
|
+
* broken with a sort in the y-dimension, then in favor of the entity added
|
|
43
|
+
* last.
|
|
42
44
|
*
|
|
43
45
|
* @param {Point} [point] Point around which to search for a closest entity
|
|
44
46
|
* @returns {T} Will return the nearest entity or undefined if none are found
|
|
@@ -46,7 +48,8 @@ export interface IEntityStore<T extends IPositionedEntity> {
|
|
|
46
48
|
entityNearestX(point: Point): T;
|
|
47
49
|
/**
|
|
48
50
|
* Returns the entity closest to a given {Point} in the y-dimension. Ties are
|
|
49
|
-
* broken with a sort in the x-dimension
|
|
51
|
+
* broken with a sort in the x-dimension, then in favor of the entity added
|
|
52
|
+
* last.
|
|
50
53
|
*
|
|
51
54
|
* @param {Point} [point] Point around which to search for a closest entity
|
|
52
55
|
* @returns {T} Will return the nearest entity or undefined if none are found
|
|
@@ -32,6 +32,9 @@ export type IDistanceFunction = (bounds: RTreeBounds, p: Point) => number;
|
|
|
32
32
|
export declare function createMinimizingNodePredicate<T>(point: Point, nearFn: IDistanceFunction, farFn: IDistanceFunction): (node: RTreeNode<T>) => QueryPredicateResult;
|
|
33
33
|
/**
|
|
34
34
|
* Create a `Array.sort` function from a query point and a distance function.
|
|
35
|
+
*
|
|
36
|
+
* Nodes are sorted from farthest to nearest. Ties are sorted from first
|
|
37
|
+
* inserted to last inserted.
|
|
35
38
|
*/
|
|
36
39
|
export declare function createNodeSort<T>(point: Point, distanceFn: IDistanceFunction): (a: RTreeNode<T>, b: RTreeNode<T>) => number;
|
|
37
40
|
/**
|
|
@@ -63,6 +66,9 @@ export declare class RTree<T> {
|
|
|
63
66
|
* Nearness is measured as the absolute distance from the query point to the
|
|
64
67
|
* nearest edge of the node bounds. If the node bounds contains the query
|
|
65
68
|
* point, the distance is 0.
|
|
69
|
+
*
|
|
70
|
+
* The results are equally near and sorted by insertion order, ending with
|
|
71
|
+
* the last inserted value.
|
|
66
72
|
*/
|
|
67
73
|
locateNearest(xy: Point): T[];
|
|
68
74
|
/**
|
|
@@ -72,7 +78,8 @@ export declare class RTree<T> {
|
|
|
72
78
|
* query's x point to the nearest edge of the node bounds. If the node
|
|
73
79
|
* bounds contains the query point, the distance is 0.
|
|
74
80
|
*
|
|
75
|
-
* The results are sorted by y-coordinate nearness
|
|
81
|
+
* The results are sorted by y-coordinate nearness, then by insertion
|
|
82
|
+
* order, ending with the nearest, last inserted value.
|
|
76
83
|
*/
|
|
77
84
|
locateNearestX(xy: Point): T[];
|
|
78
85
|
/**
|
|
@@ -82,7 +89,8 @@ export declare class RTree<T> {
|
|
|
82
89
|
* query's y point to the nearest edge of the node bounds. If the node
|
|
83
90
|
* bounds contains the query point, the distance is 0.
|
|
84
91
|
*
|
|
85
|
-
* The results are sorted by x-coordinate nearness
|
|
92
|
+
* The results are sorted by x-coordinate nearness, then by insertion
|
|
93
|
+
* order, ending with the nearest, last inserted value.
|
|
86
94
|
*/
|
|
87
95
|
locateNearestY(xy: Point): T[];
|
|
88
96
|
intersect(bounds: RTreeBounds): T[];
|
|
@@ -98,6 +106,7 @@ export declare class RTreeNode<T> {
|
|
|
98
106
|
entries: RTreeNode<T>[];
|
|
99
107
|
parent: RTreeNode<T>;
|
|
100
108
|
value: T;
|
|
109
|
+
insertionIndex: number;
|
|
101
110
|
constructor(leaf: boolean);
|
|
102
111
|
/**
|
|
103
112
|
* Returns `true` iff this node has more children than the `maxNodeChildren`
|
package/build/src/utils/rTree.js
CHANGED
|
@@ -76,10 +76,14 @@ function createMinimizingNodePredicate(point, nearFn, farFn) {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Create a `Array.sort` function from a query point and a distance function.
|
|
79
|
+
*
|
|
80
|
+
* Nodes are sorted from farthest to nearest. Ties are sorted from first
|
|
81
|
+
* inserted to last inserted.
|
|
79
82
|
*/
|
|
80
83
|
function createNodeSort(point, distanceFn) {
|
|
81
84
|
return function (a, b) {
|
|
82
|
-
|
|
85
|
+
var distanceDifference = distanceFn(b.bounds, point) - distanceFn(a.bounds, point);
|
|
86
|
+
return distanceDifference !== 0 ? distanceDifference : a.insertionIndex - b.insertionIndex;
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
/**
|
|
@@ -119,6 +123,7 @@ var RTree = /** @class */ (function () {
|
|
|
119
123
|
}
|
|
120
124
|
// Insert new value node into leaf node
|
|
121
125
|
var valueNode = RTreeNode.valueNode(bounds, value);
|
|
126
|
+
valueNode.insertionIndex = this.size;
|
|
122
127
|
node.insert(valueNode);
|
|
123
128
|
this.size += 1;
|
|
124
129
|
// While node overflows, split and walk up
|
|
@@ -139,10 +144,14 @@ var RTree = /** @class */ (function () {
|
|
|
139
144
|
* Nearness is measured as the absolute distance from the query point to the
|
|
140
145
|
* nearest edge of the node bounds. If the node bounds contains the query
|
|
141
146
|
* point, the distance is 0.
|
|
147
|
+
*
|
|
148
|
+
* The results are equally near and sorted by insertion order, ending with
|
|
149
|
+
* the last inserted value.
|
|
142
150
|
*/
|
|
143
151
|
RTree.prototype.locateNearest = function (xy) {
|
|
144
152
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.distanceSquaredToNearEdge, RTreeBounds.distanceSquaredToFarEdge);
|
|
145
153
|
var nodes = this.queryNodes(predicate);
|
|
154
|
+
nodes.sort(function (a, b) { return a.insertionIndex - b.insertionIndex; });
|
|
146
155
|
return nodes.map(function (node) { return node.value; });
|
|
147
156
|
};
|
|
148
157
|
/**
|
|
@@ -152,7 +161,8 @@ var RTree = /** @class */ (function () {
|
|
|
152
161
|
* query's x point to the nearest edge of the node bounds. If the node
|
|
153
162
|
* bounds contains the query point, the distance is 0.
|
|
154
163
|
*
|
|
155
|
-
* The results are sorted by y-coordinate nearness
|
|
164
|
+
* The results are sorted by y-coordinate nearness, then by insertion
|
|
165
|
+
* order, ending with the nearest, last inserted value.
|
|
156
166
|
*/
|
|
157
167
|
RTree.prototype.locateNearestX = function (xy) {
|
|
158
168
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.absoluteDistanceToNearEdgeX, RTreeBounds.absoluteDistanceToFarEdgeX);
|
|
@@ -167,7 +177,8 @@ var RTree = /** @class */ (function () {
|
|
|
167
177
|
* query's y point to the nearest edge of the node bounds. If the node
|
|
168
178
|
* bounds contains the query point, the distance is 0.
|
|
169
179
|
*
|
|
170
|
-
* The results are sorted by x-coordinate nearness
|
|
180
|
+
* The results are sorted by x-coordinate nearness, then by insertion
|
|
181
|
+
* order, ending with the nearest, last inserted value.
|
|
171
182
|
*/
|
|
172
183
|
RTree.prototype.locateNearestY = function (xy) {
|
|
173
184
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.absoluteDistanceToNearEdgeY, RTreeBounds.absoluteDistanceToFarEdgeY);
|
|
@@ -242,6 +253,7 @@ var RTreeNode = /** @class */ (function () {
|
|
|
242
253
|
this.entries = [];
|
|
243
254
|
this.parent = null;
|
|
244
255
|
this.value = null;
|
|
256
|
+
this.insertionIndex = null;
|
|
245
257
|
}
|
|
246
258
|
RTreeNode.valueNode = function (bounds, value) {
|
|
247
259
|
var node = new RTreeNode(true);
|
package/package.json
CHANGED
package/plottable.js
CHANGED
|
@@ -1087,6 +1087,8 @@ var Plot = /** @class */ (function (_super) {
|
|
|
1087
1087
|
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
1088
1088
|
* or undefined if no {Plots.PlotEntity} can be found.
|
|
1089
1089
|
*
|
|
1090
|
+
* If several Entities are equally near, returns the one drawn last (the last Dataset, then the last datum).
|
|
1091
|
+
*
|
|
1090
1092
|
* @param {Point} queryPoint
|
|
1091
1093
|
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
1092
1094
|
*/
|
|
@@ -4939,6 +4941,7 @@ var Bar = /** @class */ (function (_super) {
|
|
|
4939
4941
|
* - If the query point is inside a bar, returns the PlotEntity for that bar.
|
|
4940
4942
|
* - Otherwise, gets the nearest PlotEntity by the positional direction (X for vertical, Y for horizontal),
|
|
4941
4943
|
* breaking ties with the secondary direction.
|
|
4944
|
+
* - Remaining ties, such as overlapping bars, go to the bar drawn last (the last Dataset, then the last datum).
|
|
4942
4945
|
* Returns undefined if no PlotEntity can be found.
|
|
4943
4946
|
*
|
|
4944
4947
|
* @param {Point} queryPoint
|
|
@@ -5315,6 +5318,17 @@ var Bar = /** @class */ (function (_super) {
|
|
|
5315
5318
|
var entities = _super.prototype.entities.call(this, datasets);
|
|
5316
5319
|
return entities;
|
|
5317
5320
|
};
|
|
5321
|
+
/**
|
|
5322
|
+
* Undrawn bars stay in `_getDataToDraw` as null placeholders, so the drawer
|
|
5323
|
+
* indexes each bar's element by its dataset index
|
|
5324
|
+
*/
|
|
5325
|
+
Bar.prototype._buildLightweightPlotEntities = function (datasets) {
|
|
5326
|
+
var lightweightPlotEntities = _super.prototype._buildLightweightPlotEntities.call(this, datasets);
|
|
5327
|
+
lightweightPlotEntities.forEach(function (lightweightPlotEntity) {
|
|
5328
|
+
lightweightPlotEntity.validDatumIndex = lightweightPlotEntity.index;
|
|
5329
|
+
});
|
|
5330
|
+
return lightweightPlotEntities;
|
|
5331
|
+
};
|
|
5318
5332
|
Bar.prototype._entityBounds = function (entity) {
|
|
5319
5333
|
var datum = entity.datum, index = entity.index, dataset = entity.dataset;
|
|
5320
5334
|
return this._pixelBounds(datum, index, dataset);
|
|
@@ -10041,10 +10055,14 @@ function createMinimizingNodePredicate(point, nearFn, farFn) {
|
|
|
10041
10055
|
}
|
|
10042
10056
|
/**
|
|
10043
10057
|
* Create a `Array.sort` function from a query point and a distance function.
|
|
10058
|
+
*
|
|
10059
|
+
* Nodes are sorted from farthest to nearest. Ties are sorted from first
|
|
10060
|
+
* inserted to last inserted.
|
|
10044
10061
|
*/
|
|
10045
10062
|
function createNodeSort(point, distanceFn) {
|
|
10046
10063
|
return function (a, b) {
|
|
10047
|
-
|
|
10064
|
+
var distanceDifference = distanceFn(b.bounds, point) - distanceFn(a.bounds, point);
|
|
10065
|
+
return distanceDifference !== 0 ? distanceDifference : a.insertionIndex - b.insertionIndex;
|
|
10048
10066
|
};
|
|
10049
10067
|
}
|
|
10050
10068
|
/**
|
|
@@ -10084,6 +10102,7 @@ var RTree = /** @class */ (function () {
|
|
|
10084
10102
|
}
|
|
10085
10103
|
// Insert new value node into leaf node
|
|
10086
10104
|
var valueNode = RTreeNode.valueNode(bounds, value);
|
|
10105
|
+
valueNode.insertionIndex = this.size;
|
|
10087
10106
|
node.insert(valueNode);
|
|
10088
10107
|
this.size += 1;
|
|
10089
10108
|
// While node overflows, split and walk up
|
|
@@ -10104,10 +10123,14 @@ var RTree = /** @class */ (function () {
|
|
|
10104
10123
|
* Nearness is measured as the absolute distance from the query point to the
|
|
10105
10124
|
* nearest edge of the node bounds. If the node bounds contains the query
|
|
10106
10125
|
* point, the distance is 0.
|
|
10126
|
+
*
|
|
10127
|
+
* The results are equally near and sorted by insertion order, ending with
|
|
10128
|
+
* the last inserted value.
|
|
10107
10129
|
*/
|
|
10108
10130
|
RTree.prototype.locateNearest = function (xy) {
|
|
10109
10131
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.distanceSquaredToNearEdge, RTreeBounds.distanceSquaredToFarEdge);
|
|
10110
10132
|
var nodes = this.queryNodes(predicate);
|
|
10133
|
+
nodes.sort(function (a, b) { return a.insertionIndex - b.insertionIndex; });
|
|
10111
10134
|
return nodes.map(function (node) { return node.value; });
|
|
10112
10135
|
};
|
|
10113
10136
|
/**
|
|
@@ -10117,7 +10140,8 @@ var RTree = /** @class */ (function () {
|
|
|
10117
10140
|
* query's x point to the nearest edge of the node bounds. If the node
|
|
10118
10141
|
* bounds contains the query point, the distance is 0.
|
|
10119
10142
|
*
|
|
10120
|
-
* The results are sorted by y-coordinate nearness
|
|
10143
|
+
* The results are sorted by y-coordinate nearness, then by insertion
|
|
10144
|
+
* order, ending with the nearest, last inserted value.
|
|
10121
10145
|
*/
|
|
10122
10146
|
RTree.prototype.locateNearestX = function (xy) {
|
|
10123
10147
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.absoluteDistanceToNearEdgeX, RTreeBounds.absoluteDistanceToFarEdgeX);
|
|
@@ -10132,7 +10156,8 @@ var RTree = /** @class */ (function () {
|
|
|
10132
10156
|
* query's y point to the nearest edge of the node bounds. If the node
|
|
10133
10157
|
* bounds contains the query point, the distance is 0.
|
|
10134
10158
|
*
|
|
10135
|
-
* The results are sorted by x-coordinate nearness
|
|
10159
|
+
* The results are sorted by x-coordinate nearness, then by insertion
|
|
10160
|
+
* order, ending with the nearest, last inserted value.
|
|
10136
10161
|
*/
|
|
10137
10162
|
RTree.prototype.locateNearestY = function (xy) {
|
|
10138
10163
|
var predicate = createMinimizingNodePredicate(xy, RTreeBounds.absoluteDistanceToNearEdgeY, RTreeBounds.absoluteDistanceToFarEdgeY);
|
|
@@ -10207,6 +10232,7 @@ var RTreeNode = /** @class */ (function () {
|
|
|
10207
10232
|
this.entries = [];
|
|
10208
10233
|
this.parent = null;
|
|
10209
10234
|
this.value = null;
|
|
10235
|
+
this.insertionIndex = null;
|
|
10210
10236
|
}
|
|
10211
10237
|
RTreeNode.valueNode = function (bounds, value) {
|
|
10212
10238
|
var node = new RTreeNode(true);
|
|
@@ -16705,6 +16731,17 @@ var Rectangle = /** @class */ (function (_super) {
|
|
|
16705
16731
|
return x <= point.x && point.x <= x + width && y <= point.y && point.y <= y + height;
|
|
16706
16732
|
});
|
|
16707
16733
|
};
|
|
16734
|
+
/**
|
|
16735
|
+
* Undrawn rectangles stay in `_getDataToDraw` as null placeholders, so the
|
|
16736
|
+
* drawer indexes each rectangle's element by its dataset index
|
|
16737
|
+
*/
|
|
16738
|
+
Rectangle.prototype._buildLightweightPlotEntities = function (datasets) {
|
|
16739
|
+
var lightweightPlotEntities = _super.prototype._buildLightweightPlotEntities.call(this, datasets);
|
|
16740
|
+
lightweightPlotEntities.forEach(function (lightweightPlotEntity) {
|
|
16741
|
+
lightweightPlotEntity.validDatumIndex = lightweightPlotEntity.index;
|
|
16742
|
+
});
|
|
16743
|
+
return lightweightPlotEntities;
|
|
16744
|
+
};
|
|
16708
16745
|
Rectangle.prototype._entityBounds = function (entity) {
|
|
16709
16746
|
var datum = entity.datum, index = entity.index, dataset = entity.dataset;
|
|
16710
16747
|
return this._entityBBox(datum, index, dataset, this._getAttrToProjector());
|
|
@@ -17021,6 +17058,33 @@ var Scatter = /** @class */ (function (_super) {
|
|
|
17021
17058
|
return x - size / 2 <= p.x && p.x <= x + size / 2 && y - size / 2 <= p.y && p.y <= y + size / 2;
|
|
17022
17059
|
});
|
|
17023
17060
|
};
|
|
17061
|
+
/**
|
|
17062
|
+
* Returns the {Plots.PlotEntity} nearest to the query point,
|
|
17063
|
+
* or undefined if no {Plots.PlotEntity} can be found.
|
|
17064
|
+
*
|
|
17065
|
+
* If the query point is inside several Entities' bounding boxes, returns the
|
|
17066
|
+
* one whose position is nearest, then the one drawn last.
|
|
17067
|
+
*
|
|
17068
|
+
* @param {Point} queryPoint
|
|
17069
|
+
* @returns {Plots.PlotEntity} The nearest PlotEntity, or undefined if no {Plots.PlotEntity} can be found.
|
|
17070
|
+
*/
|
|
17071
|
+
Scatter.prototype.entityNearest = function (queryPoint) {
|
|
17072
|
+
var containing = this._getEntityStore().entitiesInBounds({ x: queryPoint.x, y: queryPoint.y, width: 0, height: 0 });
|
|
17073
|
+
if (containing.length === 0) {
|
|
17074
|
+
return _super.prototype.entityNearest.call(this, queryPoint);
|
|
17075
|
+
}
|
|
17076
|
+
containing.sort(function (a, b) { return a.datasetIndex - b.datasetIndex || a.index - b.index; });
|
|
17077
|
+
var nearest;
|
|
17078
|
+
var minDistSquared = Infinity;
|
|
17079
|
+
containing.forEach(function (entity) {
|
|
17080
|
+
var distSquared = Utils.Math.distanceSquared(entity.position, queryPoint);
|
|
17081
|
+
if (distSquared <= minDistSquared) {
|
|
17082
|
+
nearest = entity;
|
|
17083
|
+
minDistSquared = distSquared;
|
|
17084
|
+
}
|
|
17085
|
+
});
|
|
17086
|
+
return this._lightweightPlotEntityToPlotEntity(nearest);
|
|
17087
|
+
};
|
|
17024
17088
|
Scatter.prototype.labelsEnabled = function (enabled) {
|
|
17025
17089
|
if (enabled == null) {
|
|
17026
17090
|
return this._labelsEnabled;
|