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
@@ -9,41 +9,6 @@ var tslib_1 = require("tslib");
9
9
  var d3 = require("d3");
10
10
  var Utils = require("../utils");
11
11
  var scale_1 = require("./scale");
12
- /**
13
- * Workaround for bad d3 behavior.
14
- *
15
- * d3's color scales, which are oridinal scales, have side-effects when invoked.
16
- * When you call the `scale(value)` as a function, it will implicitly add new
17
- * values to the domain.
18
- *
19
- * These side-effects cause us to rely on looking up the current scale state
20
- * with the `.domain()` and `.range()` methods. However, these methods have poor
21
- * performance implications since they will always slice their internal values
22
- * before returning. Inside the inner render loop of color scatter plot points,
23
- * these slices add up.
24
- */
25
- var ImplicitSeriesTracker = /** @class */ (function () {
26
- function ImplicitSeriesTracker() {
27
- this.count = 0;
28
- this.tracker = {};
29
- }
30
- ImplicitSeriesTracker.prototype.getIndex = function (value) {
31
- if (this.tracker[value] != null) {
32
- return this.tracker[value];
33
- }
34
- else {
35
- var idx = this.count;
36
- this.tracker[value] = idx;
37
- this.count += 1;
38
- return idx;
39
- }
40
- };
41
- ImplicitSeriesTracker.prototype.clear = function () {
42
- this.count = 0;
43
- this.tracker = {};
44
- };
45
- return ImplicitSeriesTracker;
46
- }());
47
12
  // Preserve the public D3 4 palette names removed in D3 5.
48
13
  var CATEGORY20 = [
49
14
  "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c",
@@ -75,43 +40,41 @@ var Color = /** @class */ (function (_super) {
75
40
  */
76
41
  function Color(scaleType) {
77
42
  var _this = _super.call(this) || this;
78
- // Cache the number of range value to avoid calling `scale.range().length`
79
- _this._rangeLength = 1;
80
- _this._tracker = new ImplicitSeriesTracker();
81
- var scale;
43
+ _this._domain = [];
44
+ _this._domainIndices = new Map();
45
+ var range;
82
46
  switch (scaleType) {
83
47
  case null:
84
48
  case undefined:
85
49
  if (Color._plottableColorCache == null) {
86
50
  Color._plottableColorCache = Color._getPlottableColors();
87
51
  }
88
- scale = d3.scaleOrdinal().range(Color._plottableColorCache);
52
+ range = Color._plottableColorCache;
89
53
  break;
90
54
  case "Category10":
91
55
  case "category10":
92
56
  case "10":
93
- scale = d3.scaleOrdinal(d3.schemeCategory10);
57
+ range = d3.schemeCategory10;
94
58
  break;
95
59
  case "Category20":
96
60
  case "category20":
97
61
  case "20":
98
- scale = d3.scaleOrdinal(CATEGORY20);
62
+ range = CATEGORY20;
99
63
  break;
100
64
  case "Category20b":
101
65
  case "category20b":
102
66
  case "20b":
103
- scale = d3.scaleOrdinal(CATEGORY20B);
67
+ range = CATEGORY20B;
104
68
  break;
105
69
  case "Category20c":
106
70
  case "category20c":
107
71
  case "20c":
108
- scale = d3.scaleOrdinal(CATEGORY20C);
72
+ range = CATEGORY20C;
109
73
  break;
110
74
  default:
111
75
  throw new Error("Unsupported ColorScale type");
112
76
  }
113
- _this._d3Scale = scale;
114
- _this._rangeLength = _this._d3Scale.range().length;
77
+ _this._range = range.slice();
115
78
  return _this;
116
79
  }
117
80
  Color.prototype.extentOfValues = function (values) {
@@ -151,34 +114,45 @@ var Color = /** @class */ (function (_super) {
151
114
  * @returns {string}
152
115
  */
153
116
  Color.prototype.scale = function (value) {
154
- var color = this._d3Scale(value);
155
- var index = this._tracker.getIndex(value);
156
- var numLooped = Math.floor(index / this._rangeLength);
117
+ var index = this._domainIndex(value);
118
+ var color = this._range[index % this._range.length];
119
+ var numLooped = Math.floor(index / this._range.length);
157
120
  if (numLooped === 0) {
158
121
  return color;
159
122
  }
160
123
  var modifyFactor = Math.log(numLooped * Color._LOOP_LIGHTEN_FACTOR + 1);
161
124
  return Utils.Color.lightenColor(color, modifyFactor);
162
125
  };
126
+ Color.prototype._domainIndex = function (value) {
127
+ // Accessors read untyped data, so values can be numbers, and 1 and "1" must share a color
128
+ var key = String(value);
129
+ var index = this._domainIndices.get(key);
130
+ if (index == null) {
131
+ index = this._domain.push(value) - 1;
132
+ this._domainIndices.set(key, index);
133
+ }
134
+ return index;
135
+ };
163
136
  Color.prototype._getDomain = function () {
164
137
  return this._backingScaleDomain();
165
138
  };
166
139
  Color.prototype._backingScaleDomain = function (values) {
140
+ var _this = this;
167
141
  if (values == null) {
168
- return this._d3Scale.domain();
142
+ return this._domain.slice();
169
143
  }
170
144
  else {
171
- this._d3Scale.domain(values);
172
- this._tracker.clear();
145
+ this._domain = [];
146
+ this._domainIndices.clear();
147
+ values.forEach(function (value) { return _this._domainIndex(value); });
173
148
  return this;
174
149
  }
175
150
  };
176
151
  Color.prototype._getRange = function () {
177
- return this._d3Scale.range();
152
+ return this._range.slice();
178
153
  };
179
154
  Color.prototype._setRange = function (values) {
180
- this._d3Scale.range(values);
181
- this._rangeLength = values.length;
155
+ this._range = values.slice();
182
156
  };
183
157
  Color._LOOP_LIGHTEN_FACTOR = 1.6;
184
158
  // The maximum number of colors we are getting from CSS stylesheets
@@ -9,6 +9,7 @@ var tslib_1 = require("tslib");
9
9
  var d3 = require("d3");
10
10
  var Utils = require("../utils");
11
11
  var scale_1 = require("./scale");
12
+ var UNKNOWN_COLOR = "rgb(0, 0, 0)";
12
13
  var InterpolatedColor = /** @class */ (function (_super) {
13
14
  tslib_1.__extends(InterpolatedColor, _super);
14
15
  /**
@@ -21,16 +22,16 @@ var InterpolatedColor = /** @class */ (function (_super) {
21
22
  var _this = _super.call(this) || this;
22
23
  switch (scaleType) {
23
24
  case "linear":
24
- _this._colorScale = d3.scaleLinear();
25
+ _this._colorScale = d3.scaleLinear().unknown(UNKNOWN_COLOR);
25
26
  break;
26
27
  case "log":
27
- _this._colorScale = d3.scaleLog();
28
+ _this._colorScale = d3.scaleLog().unknown(UNKNOWN_COLOR);
28
29
  break;
29
30
  case "sqrt":
30
- _this._colorScale = d3.scaleSqrt();
31
+ _this._colorScale = d3.scaleSqrt().unknown(UNKNOWN_COLOR);
31
32
  break;
32
33
  case "pow":
33
- _this._colorScale = d3.scalePow();
34
+ _this._colorScale = d3.scalePow().unknown(UNKNOWN_COLOR);
34
35
  break;
35
36
  }
36
37
  if (_this._colorScale == null) {
@@ -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`
@@ -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
- return distanceFn(b.bounds, point) - distanceFn(a.bounds, point);
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);
@@ -129,6 +129,39 @@ function stackedExtent(stackingResult, keyAccessor, filter) {
129
129
  var minStackExtent = Utils.Math.min(extents, 0);
130
130
  return [nativeMath.min(minStackExtent, 0), nativeMath.max(0, maxStackExtent)];
131
131
  }
132
+ /**
133
+ * A lodash `MapCache` backed by a `WeakMap`, so each cached string is
134
+ * released once its key object (such as a `Date`) is garbage collected.
135
+ * Primitive keys are never cached: a `WeakMap` cannot hold them, and
136
+ * `String()` on a primitive costs no more than a cache lookup.
137
+ */
138
+ var WeakKeyCache = /** @class */ (function () {
139
+ function WeakKeyCache() {
140
+ this.map = new WeakMap();
141
+ }
142
+ WeakKeyCache.prototype.get = function (key) {
143
+ return this.isObjectKey(key) ? this.map.get(key) : undefined;
144
+ };
145
+ WeakKeyCache.prototype.has = function (key) {
146
+ return this.isObjectKey(key) && this.map.has(key);
147
+ };
148
+ WeakKeyCache.prototype.set = function (key, value) {
149
+ if (this.isObjectKey(key)) {
150
+ this.map.set(key, value);
151
+ }
152
+ return this;
153
+ };
154
+ WeakKeyCache.prototype.delete = function (key) {
155
+ return this.isObjectKey(key) && this.map.delete(key);
156
+ };
157
+ WeakKeyCache.prototype.clear = function () {
158
+ this.map = new WeakMap();
159
+ };
160
+ WeakKeyCache.prototype.isObjectKey = function (key) {
161
+ return typeof key === "object" && key !== null;
162
+ };
163
+ return WeakKeyCache;
164
+ }());
132
165
  /**
133
166
  * Normalizes a key used for stacking
134
167
  *
@@ -138,3 +171,4 @@ function stackedExtent(stackingResult, keyAccessor, filter) {
138
171
  exports.normalizeKey = (0, memoize_1.default)(function (key) {
139
172
  return String(key);
140
173
  });
174
+ exports.normalizeKey.cache = new WeakKeyCache();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "plottable",
3
3
  "description": "A modular charting library built on D3",
4
- "version": "4.0.0",
4
+ "version": "4.1.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,11 +21,12 @@
21
21
  "lint": "npm-run-all lint:tslint lint:eslint",
22
22
  "lint:eslint": "grunt eslint",
23
23
  "lint:tslint": "tslint --project tsconfig.json",
24
- "start": "npm-run-all -p start:update-quicktests start:watch-tsc start:watch-quicktests start:webpack-dev-server",
24
+ "start": "npm-run-all -p start:update-quicktests start:watch-tsc start:watch-quicktests start:watch-webpack start:server",
25
+ "start:server": "grunt connect:server:keepalive",
25
26
  "start:update-quicktests": "grunt update-quicktests",
26
27
  "start:watch-quicktests": "grunt watch-quicktests",
27
28
  "start:watch-tsc": "tsc -w -p .",
28
- "start:webpack-dev-server": "webpack-dev-server",
29
+ "start:watch-webpack": "webpack --watch",
29
30
  "test": "grunt test-local",
30
31
  "test:ci": "grunt test-ci",
31
32
  "test:browser": "node scripts/test-browser.js"
@@ -58,7 +59,6 @@
58
59
  "tslint": "5.18.0",
59
60
  "typescript": "~5.9.3",
60
61
  "webpack": "2.6.1",
61
- "webpack-dev-server": "2.11.1",
62
62
  "webpack-merge": "^4.1.0"
63
63
  },
64
64
  "dependencies": {
package/plottable.css CHANGED
@@ -112,9 +112,10 @@
112
112
  fill: #32313F;
113
113
  }
114
114
 
115
- .plottable .tick-label-container.label-12 text,
116
- .plottable .bar-label-text-area.label-12 text,
117
- .plottable .scatter-label-text-area.label-12 text {
115
+ /* No label-12 rule, so consumer CSS can override the default size */
116
+ .plottable .tick-label-container text,
117
+ .plottable .bar-label-text-area text,
118
+ .plottable .scatter-label-text-area text {
118
119
  font-size: 12px;
119
120
  }
120
121