plottable 4.0.0 → 4.1.1

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.
Files changed (36) hide show
  1. package/build/src/components/legend.js +10 -2
  2. package/build/src/core/version.js +1 -1
  3. package/build/src/dispatchers/dispatcher.js +8 -1
  4. package/build/src/drawers/svgDrawer.d.ts +4 -0
  5. package/build/src/drawers/svgDrawer.js +15 -6
  6. package/build/src/interactions/clickInteraction.js +7 -0
  7. package/build/src/interactions/dragInteraction.js +6 -0
  8. package/build/src/interactions/interaction.d.ts +2 -1
  9. package/build/src/interactions/interaction.js +11 -1
  10. package/build/src/interactions/keyInteraction.js +7 -0
  11. package/build/src/interactions/panZoomInteraction.js +6 -0
  12. package/build/src/interactions/pointerInteraction.js +7 -0
  13. package/build/src/memoize/memoizeProjectors.js +41 -9
  14. package/build/src/plots/barPlot.d.ts +6 -0
  15. package/build/src/plots/barPlot.js +12 -0
  16. package/build/src/plots/piePlot.js +1 -0
  17. package/build/src/plots/plot.d.ts +2 -0
  18. package/build/src/plots/plot.js +3 -1
  19. package/build/src/plots/rectanglePlot.d.ts +5 -0
  20. package/build/src/plots/rectanglePlot.js +11 -0
  21. package/build/src/plots/scatterPlot.d.ts +11 -0
  22. package/build/src/plots/scatterPlot.js +27 -0
  23. package/build/src/plots/xyPlot.js +1 -0
  24. package/build/src/scales/categoryScale.d.ts +1 -0
  25. package/build/src/scales/categoryScale.js +7 -4
  26. package/build/src/scales/colorScale.d.ts +4 -3
  27. package/build/src/scales/colorScale.js +29 -55
  28. package/build/src/scales/interpolatedColorScale.js +5 -4
  29. package/build/src/utils/entityStore.d.ts +6 -3
  30. package/build/src/utils/rTree.d.ts +11 -2
  31. package/build/src/utils/rTree.js +15 -3
  32. package/build/src/utils/stackingUtils.js +34 -0
  33. package/package.json +4 -4
  34. package/plottable.css +4 -3
  35. package/plottable.js +265 -88
  36. package/plottable.js.map +1 -1
@@ -211,12 +211,20 @@ var Legend = /** @class */ (function (_super) {
211
211
  return _this;
212
212
  }
213
213
  Legend.prototype._setup = function () {
214
+ var _this = this;
214
215
  _super.prototype._setup.call(this);
215
- var fakeLegendRow = this.content().append("g").classed(Legend.LEGEND_ROW_CLASS, true);
216
+ // Keep the row out of content() except while measuring, since renderImmediately() clears content()
217
+ var fakeLegendRow = d3.create("svg:g").classed(Legend.LEGEND_ROW_CLASS, true);
216
218
  var fakeLegendEntry = fakeLegendRow.append("g").classed(Legend.LEGEND_ENTRY_CLASS, true);
217
219
  fakeLegendEntry.append("text");
218
220
  var context = new Typesettable.SvgContext(fakeLegendRow.node(), null, Configs.ADD_TITLE_ELEMENTS);
219
- this._measurer = new Typesettable.CacheMeasurer(context);
221
+ var ruler = context.createRuler();
222
+ this._measurer = new Typesettable.CacheMeasurer(function (text) {
223
+ _this.content().append(function () { return fakeLegendRow.node(); });
224
+ var dimensions = ruler(text);
225
+ fakeLegendRow.remove();
226
+ return dimensions;
227
+ });
220
228
  this._wrapper = new Typesettable.Wrapper().maxLines(this.maxLinesPerEntry());
221
229
  this._writer = new Typesettable.Writer(this._measurer, context, this._wrapper);
222
230
  };
@@ -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 = "4.0.0";
13
+ exports.version = "4.1.1";
@@ -78,7 +78,14 @@ var Dispatcher = /** @class */ (function () {
78
78
  }
79
79
  var callbackSet = this._eventNameToCallbackSet[eventName];
80
80
  if (callbackSet != null) {
81
- callbackSet.callCallbacks.apply(callbackSet, args);
81
+ // Interactions can resubscribe while handling an event, which Set.forEach would visit again
82
+ var callbacks_1 = [];
83
+ callbackSet.forEach(function (callback) { return callbacks_1.push(callback); });
84
+ callbacks_1.forEach(function (callback) {
85
+ if (callbackSet.has(callback)) {
86
+ callback.apply(callbackSet, args);
87
+ }
88
+ });
82
89
  }
83
90
  };
84
91
  return Dispatcher;
@@ -24,6 +24,10 @@ export declare class SVGDrawer implements IDrawer {
24
24
  * All of the DOM elements from the last draw.
25
25
  */
26
26
  private _selection;
27
+ /**
28
+ * The source data index of each element in _selection, by position
29
+ */
30
+ private _sourceDataIndices;
27
31
  /**
28
32
  * Cache of the _selection.nodes().
29
33
  */
@@ -78,10 +78,12 @@ var SVGDrawer = /** @class */ (function () {
78
78
  // first store source data index before any filtering takes place
79
79
  var mappedData = data.map(function (d, i) { return d != null ? { d: d, i: i } : null; });
80
80
  // Whereas canvas renders can cope with null data values, svg renderer
81
- // attribute accessors assume non-null data values, so we must filter them
82
- // out. Unfortunately, this means the index passed to each accessor will
83
- // not necessarily match the index of the datum in the dataset.
81
+ // attribute accessors assume non-null data values, so we must filter them out
84
82
  var filteredData = mappedData.filter(function (d) { return d != null; });
83
+ this._sourceDataIndices = filteredData.map(function (_a) {
84
+ var i = _a.i;
85
+ return i;
86
+ });
85
87
  var dataElementsUpdate = this._root.selectAll(this.selector()).data(filteredData);
86
88
  this._selection = dataElementsUpdate
87
89
  .enter()
@@ -115,13 +117,20 @@ var SVGDrawer = /** @class */ (function () {
115
117
  */
116
118
  SVGDrawer.prototype._drawStep = function (step) {
117
119
  var _this = this;
120
+ // d3 passes each element's position in _selection, which skips null data, so map it back to the source data index
121
+ var sourceDataIndices = this._sourceDataIndices;
122
+ var attrToSourceIndexProjector = {};
123
+ Object.keys(step.attrToAppliedProjector).forEach(function (attr) {
124
+ var projector = step.attrToAppliedProjector[attr];
125
+ attrToSourceIndexProjector[attr] = function (datum, position) { return projector(datum, sourceDataIndices[position]); };
126
+ });
118
127
  var colorAttributes = ["fill", "stroke"];
119
128
  colorAttributes.forEach(function (colorAttribute) {
120
- if (step.attrToAppliedProjector[colorAttribute] != null) {
121
- _this._selection.attr(colorAttribute, step.attrToAppliedProjector[colorAttribute]);
129
+ if (attrToSourceIndexProjector[colorAttribute] != null) {
130
+ _this._selection.attr(colorAttribute, attrToSourceIndexProjector[colorAttribute]);
122
131
  }
123
132
  });
124
- step.animator.animate(this._selection, step.attrToAppliedProjector);
133
+ step.animator.animate(this._selection, attrToSourceIndexProjector);
125
134
  if (this._className != null) {
126
135
  this._selection.classed(this._className, true);
127
136
  }
@@ -41,7 +41,14 @@ var Click = /** @class */ (function (_super) {
41
41
  this._touchDispatcher.onTouchCancel(this._touchCancelCallback);
42
42
  };
43
43
  Click.prototype._unanchor = function () {
44
+ var _this = this;
44
45
  _super.prototype._unanchor.call(this);
46
+ // Preserve a press through synchronous renderTo(), but discard it if its release can be missed.
47
+ Promise.resolve().then(function () {
48
+ if (!_this._isAnchored) {
49
+ _this._clickedDown = false;
50
+ }
51
+ });
45
52
  this._mouseDispatcher.offMouseDown(this._mouseDownCallback);
46
53
  this._mouseDispatcher.offMouseUp(this._mouseUpCallback);
47
54
  this._mouseDispatcher.offDblClick(this._dblClickCallback);
@@ -45,7 +45,13 @@ var Drag = /** @class */ (function (_super) {
45
45
  this._touchDispatcher.onTouchEnd(this._touchEndCallback);
46
46
  };
47
47
  Drag.prototype._unanchor = function () {
48
+ var _this = this;
48
49
  _super.prototype._unanchor.call(this);
50
+ Promise.resolve().then(function () {
51
+ if (!_this._isAnchored) {
52
+ _this._dragging = false;
53
+ }
54
+ });
49
55
  this._mouseDispatcher.offMouseDown(this._mouseDownCallback);
50
56
  this._mouseDispatcher.offMouseMove(this._mouseMoveCallback);
51
57
  this._mouseDispatcher.offMouseUp(this._mouseUpCallback);
@@ -6,7 +6,8 @@ import { Component } from "../components/component";
6
6
  import { Point } from "../core/interfaces";
7
7
  export declare class Interaction {
8
8
  private _anchorCallback;
9
- private _isAnchored;
9
+ private _detachCallback;
10
+ protected _isAnchored: boolean;
10
11
  private _enabled;
11
12
  protected _componentAttachedTo: Component;
12
13
  /**
@@ -8,7 +8,15 @@ exports.Interaction = void 0;
8
8
  var Interaction = /** @class */ (function () {
9
9
  function Interaction() {
10
10
  var _this = this;
11
- this._anchorCallback = function (component) { return _this._anchor(component); };
11
+ this._anchorCallback = function (component) {
12
+ _this._detachCallback();
13
+ _this._anchor(component);
14
+ };
15
+ this._detachCallback = function () {
16
+ if (_this._isAnchored) {
17
+ _this._unanchor();
18
+ }
19
+ };
12
20
  this._enabled = true;
13
21
  }
14
22
  /**
@@ -87,6 +95,7 @@ var Interaction = /** @class */ (function () {
87
95
  Interaction.prototype._connect = function () {
88
96
  if (this.enabled() && this._componentAttachedTo != null && !this._isAnchored) {
89
97
  this._componentAttachedTo.onAnchor(this._anchorCallback);
98
+ this._componentAttachedTo.onDetach(this._detachCallback);
90
99
  }
91
100
  };
92
101
  Interaction.prototype._disconnect = function () {
@@ -95,6 +104,7 @@ var Interaction = /** @class */ (function () {
95
104
  }
96
105
  if (this._componentAttachedTo != null) {
97
106
  this._componentAttachedTo.offAnchor(this._anchorCallback);
107
+ this._componentAttachedTo.offDetach(this._detachCallback);
98
108
  }
99
109
  };
100
110
  return Interaction;
@@ -30,7 +30,14 @@ var Key = /** @class */ (function (_super) {
30
30
  this._keyDispatcher.onKeyUp(this._keyUpCallback);
31
31
  };
32
32
  Key.prototype._unanchor = function () {
33
+ var _this = this;
33
34
  _super.prototype._unanchor.call(this);
35
+ // Preserve held keys through synchronous renderTo(), but discard them if keyup can be missed.
36
+ Promise.resolve().then(function () {
37
+ if (!_this._isAnchored) {
38
+ _this._downedKeys = new Utils.Set();
39
+ }
40
+ });
34
41
  this._positionDispatcher.offMouseMove(this._mouseMoveCallback);
35
42
  this._positionDispatcher = null;
36
43
  this._keyDispatcher.offKeyDown(this._keyDownCallback);
@@ -140,7 +140,13 @@ var PanZoom = /** @class */ (function (_super) {
140
140
  this._touchDispatcher.onTouchCancel(this._touchCancelCallback);
141
141
  };
142
142
  PanZoom.prototype._unanchor = function () {
143
+ var _this = this;
143
144
  _super.prototype._unanchor.call(this);
145
+ Promise.resolve().then(function () {
146
+ if (!_this._isAnchored) {
147
+ _this._touchIds.clear();
148
+ }
149
+ });
144
150
  this._mouseDispatcher.offWheel(this._wheelCallback);
145
151
  this._mouseDispatcher = null;
146
152
  this._touchDispatcher.offTouchStart(this._touchStartCallback);
@@ -29,7 +29,14 @@ var Pointer = /** @class */ (function (_super) {
29
29
  this._touchDispatcher.onTouchStart(this._touchStartCallback);
30
30
  };
31
31
  Pointer.prototype._unanchor = function () {
32
+ var _this = this;
32
33
  _super.prototype._unanchor.call(this);
34
+ // Preserve hover through synchronous renderTo(), but discard state if pointer events can be missed.
35
+ Promise.resolve().then(function () {
36
+ if (!_this._isAnchored) {
37
+ _this._overComponent = false;
38
+ }
39
+ });
33
40
  this._mouseDispatcher.offMouseMove(this._mouseMoveCallback);
34
41
  this._mouseDispatcher = null;
35
42
  this._touchDispatcher.offTouchStart(this._touchStartCallback);
@@ -33,8 +33,40 @@ var IndexMap = /** @class */ (function () {
33
33
  return IndexMap;
34
34
  }());
35
35
  /**
36
- * A lodash-style `MapCache` that utilizes a [number, number] key to create a
37
- * fast-lookup 2D index. This is much faster than stringifying the key.
36
+ * An `IndexMap` that records the datum each value was computed for in place of
37
+ * an existence flag, so a lookup only matches that datum
38
+ */
39
+ var DatumIndexMap = /** @class */ (function () {
40
+ function DatumIndexMap() {
41
+ this.values = Object.create(null);
42
+ this.datums = Object.create(null);
43
+ }
44
+ DatumIndexMap.prototype.delete = function (key) {
45
+ delete this.values[key];
46
+ delete this.datums[key];
47
+ return true;
48
+ };
49
+ DatumIndexMap.prototype.get = function (key) {
50
+ return this.values[key];
51
+ };
52
+ DatumIndexMap.prototype.has = function (key, datum) {
53
+ return this.datums[key] === datum && (datum !== undefined || key in this.datums);
54
+ };
55
+ DatumIndexMap.prototype.set = function (key, datum, value) {
56
+ this.values[key] = value;
57
+ this.datums[key] = datum;
58
+ return this;
59
+ };
60
+ return DatumIndexMap;
61
+ }());
62
+ /**
63
+ * A lodash-style `MapCache` keyed by [updateId, index, datum], stored as a
64
+ * fast-lookup 2D index on the first two. This is much faster than stringifying
65
+ * the key.
66
+ *
67
+ * Entries only match the datum they were computed for, because plots that
68
+ * filter data before drawing call projectors with each datum's position in the
69
+ * filtered data rather than its dataset index.
38
70
  */
39
71
  var DatasetIndexCache = /** @class */ (function () {
40
72
  function DatasetIndexCache() {
@@ -44,24 +76,24 @@ var DatasetIndexCache = /** @class */ (function () {
44
76
  return this.map.get(key[0]).get(key[1]);
45
77
  };
46
78
  DatasetIndexCache.prototype.has = function (key) {
47
- return this.map.has(key[0]) && this.map.get(key[0]).has(key[1]);
79
+ return this.map.has(key[0]) && this.map.get(key[0]).has(key[1], key[2]);
48
80
  };
49
81
  DatasetIndexCache.prototype.set = function (key, value) {
50
- this.map.has(key[0]) || this.map.set(key[0], new IndexMap());
51
- this.map.get(key[0]).set(key[1], value);
82
+ this.map.has(key[0]) || this.map.set(key[0], new DatumIndexMap());
83
+ this.map.get(key[0]).set(key[1], key[2], value);
52
84
  return this;
53
85
  };
54
86
  DatasetIndexCache.prototype.delete = function (key) {
55
- // NOTE: this can potentially leave dangling `IndexMap`s if we delete
56
- // all the keys from the index instead of using `clear`. The overhead is
57
- // minimal, so this is fine.
87
+ // NOTE: this can potentially leave dangling `DatumIndexMap`s if we
88
+ // delete all the keys from the index instead of using `clear`. The
89
+ // overhead is minimal, so this is fine.
58
90
  this.map.has(key[0]) && this.map.get(key[0]).delete(key[1]);
59
91
  return true;
60
92
  };
61
93
  DatasetIndexCache.prototype.clear = function () {
62
94
  this.map = new IndexMap();
63
95
  };
64
- DatasetIndexCache.resolver = function (d, i, dataset) { return [dataset.updateId(), i]; };
96
+ DatasetIndexCache.resolver = function (d, i, dataset) { return [dataset.updateId(), i, d]; };
65
97
  return DatasetIndexCache;
66
98
  }());
67
99
  function memoizeProjector(projector) {
@@ -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);
@@ -55,6 +55,7 @@ var Pie = /** @class */ (function (_super) {
55
55
  if (this.outerRadius().scale != null) {
56
56
  this.outerRadius().scale.range([0, radiusLimit]);
57
57
  }
58
+ this._updateExtents();
58
59
  return this;
59
60
  };
60
61
  Pie.prototype.addDataset = function (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
  */
@@ -120,7 +120,7 @@ var Plot = /** @class */ (function (_super) {
120
120
  };
121
121
  Plot.prototype.setBounds = function (width, height, originX, originY) {
122
122
  _super.prototype.setBounds.call(this, width, height, originX, originY);
123
- this._updateExtents();
123
+ this._resetEntityStore();
124
124
  if (this._canvas != null) {
125
125
  if (this._bufferCanvas && !this._bufferCanvasValid) {
126
126
  // copy current canvas to buffer 1:1
@@ -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;
@@ -196,6 +196,7 @@ var XYPlot = /** @class */ (function (_super) {
196
196
  yScale.range([this.height(), 0]);
197
197
  }
198
198
  }
199
+ this._updateExtents();
199
200
  return this;
200
201
  };
201
202
  XYPlot.prototype._updateXExtentsAndAutodomain = function () {
@@ -22,6 +22,7 @@ export declare class Category extends Scale<string, number> implements ITransfor
22
22
  */
23
23
  private _d3TransformationScale;
24
24
  private _d3Scale;
25
+ private _domain;
25
26
  private _range;
26
27
  private _innerPadding;
27
28
  private _outerPadding;
@@ -20,6 +20,7 @@ var Category = /** @class */ (function (_super) {
20
20
  */
21
21
  function Category() {
22
22
  var _this = _super.call(this) || this;
23
+ _this._domain = [];
23
24
  _this._range = [0, 1];
24
25
  _this._d3Scale = d3.scaleBand();
25
26
  _this._d3Scale.range(TRANSFORMATION_SPACE);
@@ -69,7 +70,7 @@ var Category = /** @class */ (function (_super) {
69
70
  var normalizedDomain = domain.map(function (d) { return _this._d3Scale(d) + rangeBand / 2; });
70
71
  var domainStart = d3.bisect(normalizedDomain, domainStartNormalized);
71
72
  var domainEnd = d3.bisect(normalizedDomain, domainEndNormalized);
72
- return domain.slice(domainStart, domainEnd);
73
+ return this._domain.slice(domainStart, domainEnd);
73
74
  };
74
75
  Category.prototype.range = function (values) {
75
76
  return _super.prototype.range.call(this, values);
@@ -127,8 +128,9 @@ var Category = /** @class */ (function (_super) {
127
128
  return this;
128
129
  };
129
130
  Category.prototype.scale = function (value) {
131
+ // Accessors read untyped data, so values can be numbers, and 1 and "1" must share a band
130
132
  // Determine the middle of the range band for the value
131
- var untransformed = this._d3Scale(value) + this._d3Scale.bandwidth() / 2;
133
+ var untransformed = this._d3Scale(String(value)) + this._d3Scale.bandwidth() / 2;
132
134
  // Convert to screen space
133
135
  return this._d3TransformationScale(untransformed);
134
136
  };
@@ -169,10 +171,11 @@ var Category = /** @class */ (function (_super) {
169
171
  };
170
172
  Category.prototype._backingScaleDomain = function (values) {
171
173
  if (values == null) {
172
- return this._d3Scale.domain();
174
+ return this._domain.slice();
173
175
  }
174
176
  else {
175
- this._d3Scale.domain(values);
177
+ this._domain = Utils.Array.uniq(values);
178
+ this._d3Scale.domain(this._domain.map(String));
176
179
  this._setBands();
177
180
  return this;
178
181
  }
@@ -7,9 +7,9 @@ export declare class Color extends Scale<string, string> {
7
7
  private static _LOOP_LIGHTEN_FACTOR;
8
8
  private static _MAXIMUM_COLORS_FROM_CSS;
9
9
  private static _plottableColorCache;
10
- private _d3Scale;
11
- private _rangeLength;
12
- private _tracker;
10
+ private _domain;
11
+ private _domainIndices;
12
+ private _range;
13
13
  /**
14
14
  * A Color Scale maps string values to color hex values expressed as a string.
15
15
  *
@@ -33,6 +33,7 @@ export declare class Color extends Scale<string, string> {
33
33
  * @returns {string}
34
34
  */
35
35
  scale(value: string): string;
36
+ private _domainIndex;
36
37
  protected _getDomain(): string[];
37
38
  protected _backingScaleDomain(): string[];
38
39
  protected _backingScaleDomain(values: string[]): this;