plottable 3.9.0-dev-81-g584986b2 → 3.9.0-dev-84-g91917c41

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.
@@ -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-81-g584986b2";
13
+ exports.version = "3.9.0-dev-84-g91917c41";
@@ -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;
@@ -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 = new Map();
29
- }
30
- ImplicitSeriesTracker.prototype.getIndex = function (value) {
31
- if (this.tracker.has(value)) {
32
- return this.tracker.get(value);
33
- }
34
- else {
35
- var idx = this.count;
36
- this.tracker.set(value, idx);
37
- this.count += 1;
38
- return idx;
39
- }
40
- };
41
- ImplicitSeriesTracker.prototype.clear = function () {
42
- this.count = 0;
43
- this.tracker.clear();
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
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": "3.9.0-dev-81-g584986b2",
4
+ "version": "3.9.0-dev-84-g91917c41",
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
 
package/plottable.js CHANGED
@@ -9240,6 +9240,7 @@ var Category = /** @class */ (function (_super) {
9240
9240
  */
9241
9241
  function Category() {
9242
9242
  var _this = _super.call(this) || this;
9243
+ _this._domain = [];
9243
9244
  _this._range = [0, 1];
9244
9245
  _this._d3Scale = d3.scaleBand();
9245
9246
  _this._d3Scale.range(TRANSFORMATION_SPACE);
@@ -9289,7 +9290,7 @@ var Category = /** @class */ (function (_super) {
9289
9290
  var normalizedDomain = domain.map(function (d) { return _this._d3Scale(d) + rangeBand / 2; });
9290
9291
  var domainStart = d3.bisect(normalizedDomain, domainStartNormalized);
9291
9292
  var domainEnd = d3.bisect(normalizedDomain, domainEndNormalized);
9292
- return domain.slice(domainStart, domainEnd);
9293
+ return this._domain.slice(domainStart, domainEnd);
9293
9294
  };
9294
9295
  Category.prototype.range = function (values) {
9295
9296
  return _super.prototype.range.call(this, values);
@@ -9347,8 +9348,9 @@ var Category = /** @class */ (function (_super) {
9347
9348
  return this;
9348
9349
  };
9349
9350
  Category.prototype.scale = function (value) {
9351
+ // Accessors read untyped data, so values can be numbers, and 1 and "1" must share a band
9350
9352
  // Determine the middle of the range band for the value
9351
- var untransformed = this._d3Scale(value) + this._d3Scale.bandwidth() / 2;
9353
+ var untransformed = this._d3Scale(String(value)) + this._d3Scale.bandwidth() / 2;
9352
9354
  // Convert to screen space
9353
9355
  return this._d3TransformationScale(untransformed);
9354
9356
  };
@@ -9389,10 +9391,11 @@ var Category = /** @class */ (function (_super) {
9389
9391
  };
9390
9392
  Category.prototype._backingScaleDomain = function (values) {
9391
9393
  if (values == null) {
9392
- return this._d3Scale.domain();
9394
+ return this._domain.slice();
9393
9395
  }
9394
9396
  else {
9395
- this._d3Scale.domain(values);
9397
+ this._domain = Utils.Array.uniq(values);
9398
+ this._d3Scale.domain(this._domain.map(String));
9396
9399
  this._setBands();
9397
9400
  return this;
9398
9401
  }
@@ -18114,41 +18117,6 @@ var tslib_1 = __webpack_require__(0);
18114
18117
  var d3 = __webpack_require__(2);
18115
18118
  var Utils = __webpack_require__(1);
18116
18119
  var scale_1 = __webpack_require__(18);
18117
- /**
18118
- * Workaround for bad d3 behavior.
18119
- *
18120
- * d3's color scales, which are oridinal scales, have side-effects when invoked.
18121
- * When you call the `scale(value)` as a function, it will implicitly add new
18122
- * values to the domain.
18123
- *
18124
- * These side-effects cause us to rely on looking up the current scale state
18125
- * with the `.domain()` and `.range()` methods. However, these methods have poor
18126
- * performance implications since they will always slice their internal values
18127
- * before returning. Inside the inner render loop of color scatter plot points,
18128
- * these slices add up.
18129
- */
18130
- var ImplicitSeriesTracker = /** @class */ (function () {
18131
- function ImplicitSeriesTracker() {
18132
- this.count = 0;
18133
- this.tracker = new Map();
18134
- }
18135
- ImplicitSeriesTracker.prototype.getIndex = function (value) {
18136
- if (this.tracker.has(value)) {
18137
- return this.tracker.get(value);
18138
- }
18139
- else {
18140
- var idx = this.count;
18141
- this.tracker.set(value, idx);
18142
- this.count += 1;
18143
- return idx;
18144
- }
18145
- };
18146
- ImplicitSeriesTracker.prototype.clear = function () {
18147
- this.count = 0;
18148
- this.tracker.clear();
18149
- };
18150
- return ImplicitSeriesTracker;
18151
- }());
18152
18120
  // Preserve the public D3 4 palette names removed in D3 5.
18153
18121
  var CATEGORY20 = [
18154
18122
  "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c",
@@ -18180,43 +18148,41 @@ var Color = /** @class */ (function (_super) {
18180
18148
  */
18181
18149
  function Color(scaleType) {
18182
18150
  var _this = _super.call(this) || this;
18183
- // Cache the number of range value to avoid calling `scale.range().length`
18184
- _this._rangeLength = 1;
18185
- _this._tracker = new ImplicitSeriesTracker();
18186
- var scale;
18151
+ _this._domain = [];
18152
+ _this._domainIndices = new Map();
18153
+ var range;
18187
18154
  switch (scaleType) {
18188
18155
  case null:
18189
18156
  case undefined:
18190
18157
  if (Color._plottableColorCache == null) {
18191
18158
  Color._plottableColorCache = Color._getPlottableColors();
18192
18159
  }
18193
- scale = d3.scaleOrdinal().range(Color._plottableColorCache);
18160
+ range = Color._plottableColorCache;
18194
18161
  break;
18195
18162
  case "Category10":
18196
18163
  case "category10":
18197
18164
  case "10":
18198
- scale = d3.scaleOrdinal(d3.schemeCategory10);
18165
+ range = d3.schemeCategory10;
18199
18166
  break;
18200
18167
  case "Category20":
18201
18168
  case "category20":
18202
18169
  case "20":
18203
- scale = d3.scaleOrdinal(CATEGORY20);
18170
+ range = CATEGORY20;
18204
18171
  break;
18205
18172
  case "Category20b":
18206
18173
  case "category20b":
18207
18174
  case "20b":
18208
- scale = d3.scaleOrdinal(CATEGORY20B);
18175
+ range = CATEGORY20B;
18209
18176
  break;
18210
18177
  case "Category20c":
18211
18178
  case "category20c":
18212
18179
  case "20c":
18213
- scale = d3.scaleOrdinal(CATEGORY20C);
18180
+ range = CATEGORY20C;
18214
18181
  break;
18215
18182
  default:
18216
18183
  throw new Error("Unsupported ColorScale type");
18217
18184
  }
18218
- _this._d3Scale = scale;
18219
- _this._rangeLength = _this._d3Scale.range().length;
18185
+ _this._range = range.slice();
18220
18186
  return _this;
18221
18187
  }
18222
18188
  Color.prototype.extentOfValues = function (values) {
@@ -18256,34 +18222,45 @@ var Color = /** @class */ (function (_super) {
18256
18222
  * @returns {string}
18257
18223
  */
18258
18224
  Color.prototype.scale = function (value) {
18259
- var color = this._d3Scale(value);
18260
- var index = this._tracker.getIndex(value);
18261
- var numLooped = Math.floor(index / this._rangeLength);
18225
+ var index = this._domainIndex(value);
18226
+ var color = this._range[index % this._range.length];
18227
+ var numLooped = Math.floor(index / this._range.length);
18262
18228
  if (numLooped === 0) {
18263
18229
  return color;
18264
18230
  }
18265
18231
  var modifyFactor = Math.log(numLooped * Color._LOOP_LIGHTEN_FACTOR + 1);
18266
18232
  return Utils.Color.lightenColor(color, modifyFactor);
18267
18233
  };
18234
+ Color.prototype._domainIndex = function (value) {
18235
+ // Accessors read untyped data, so values can be numbers, and 1 and "1" must share a color
18236
+ var key = String(value);
18237
+ var index = this._domainIndices.get(key);
18238
+ if (index == null) {
18239
+ index = this._domain.push(value) - 1;
18240
+ this._domainIndices.set(key, index);
18241
+ }
18242
+ return index;
18243
+ };
18268
18244
  Color.prototype._getDomain = function () {
18269
18245
  return this._backingScaleDomain();
18270
18246
  };
18271
18247
  Color.prototype._backingScaleDomain = function (values) {
18248
+ var _this = this;
18272
18249
  if (values == null) {
18273
- return this._d3Scale.domain();
18250
+ return this._domain.slice();
18274
18251
  }
18275
18252
  else {
18276
- this._d3Scale.domain(values);
18277
- this._tracker.clear();
18253
+ this._domain = [];
18254
+ this._domainIndices.clear();
18255
+ values.forEach(function (value) { return _this._domainIndex(value); });
18278
18256
  return this;
18279
18257
  }
18280
18258
  };
18281
18259
  Color.prototype._getRange = function () {
18282
- return this._d3Scale.range();
18260
+ return this._range.slice();
18283
18261
  };
18284
18262
  Color.prototype._setRange = function (values) {
18285
- this._d3Scale.range(values);
18286
- this._rangeLength = values.length;
18263
+ this._range = values.slice();
18287
18264
  };
18288
18265
  Color._LOOP_LIGHTEN_FACTOR = 1.6;
18289
18266
  // The maximum number of colors we are getting from CSS stylesheets