plottable 3.9.0-dev-84-g91917c41 → 3.9.0-dev-83-g29b5abab
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/scales/categoryScale.d.ts +0 -1
- package/build/src/scales/categoryScale.js +4 -7
- package/build/src/scales/colorScale.d.ts +3 -4
- package/build/src/scales/colorScale.js +55 -29
- package/package.json +1 -1
- package/plottable.js +59 -36
- 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-83-g29b5abab";
|
|
@@ -20,7 +20,6 @@ var Category = /** @class */ (function (_super) {
|
|
|
20
20
|
*/
|
|
21
21
|
function Category() {
|
|
22
22
|
var _this = _super.call(this) || this;
|
|
23
|
-
_this._domain = [];
|
|
24
23
|
_this._range = [0, 1];
|
|
25
24
|
_this._d3Scale = d3.scaleBand();
|
|
26
25
|
_this._d3Scale.range(TRANSFORMATION_SPACE);
|
|
@@ -70,7 +69,7 @@ var Category = /** @class */ (function (_super) {
|
|
|
70
69
|
var normalizedDomain = domain.map(function (d) { return _this._d3Scale(d) + rangeBand / 2; });
|
|
71
70
|
var domainStart = d3.bisect(normalizedDomain, domainStartNormalized);
|
|
72
71
|
var domainEnd = d3.bisect(normalizedDomain, domainEndNormalized);
|
|
73
|
-
return
|
|
72
|
+
return domain.slice(domainStart, domainEnd);
|
|
74
73
|
};
|
|
75
74
|
Category.prototype.range = function (values) {
|
|
76
75
|
return _super.prototype.range.call(this, values);
|
|
@@ -128,9 +127,8 @@ var Category = /** @class */ (function (_super) {
|
|
|
128
127
|
return this;
|
|
129
128
|
};
|
|
130
129
|
Category.prototype.scale = function (value) {
|
|
131
|
-
// Accessors read untyped data, so values can be numbers, and 1 and "1" must share a band
|
|
132
130
|
// Determine the middle of the range band for the value
|
|
133
|
-
var untransformed = this._d3Scale(
|
|
131
|
+
var untransformed = this._d3Scale(value) + this._d3Scale.bandwidth() / 2;
|
|
134
132
|
// Convert to screen space
|
|
135
133
|
return this._d3TransformationScale(untransformed);
|
|
136
134
|
};
|
|
@@ -171,11 +169,10 @@ var Category = /** @class */ (function (_super) {
|
|
|
171
169
|
};
|
|
172
170
|
Category.prototype._backingScaleDomain = function (values) {
|
|
173
171
|
if (values == null) {
|
|
174
|
-
return this.
|
|
172
|
+
return this._d3Scale.domain();
|
|
175
173
|
}
|
|
176
174
|
else {
|
|
177
|
-
this.
|
|
178
|
-
this._d3Scale.domain(this._domain.map(String));
|
|
175
|
+
this._d3Scale.domain(values);
|
|
179
176
|
this._setBands();
|
|
180
177
|
return this;
|
|
181
178
|
}
|
|
@@ -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
|
|
11
|
-
private
|
|
12
|
-
private
|
|
10
|
+
private _d3Scale;
|
|
11
|
+
private _rangeLength;
|
|
12
|
+
private _tracker;
|
|
13
13
|
/**
|
|
14
14
|
* A Color Scale maps string values to color hex values expressed as a string.
|
|
15
15
|
*
|
|
@@ -33,7 +33,6 @@ export declare class Color extends Scale<string, string> {
|
|
|
33
33
|
* @returns {string}
|
|
34
34
|
*/
|
|
35
35
|
scale(value: string): string;
|
|
36
|
-
private _domainIndex;
|
|
37
36
|
protected _getDomain(): string[];
|
|
38
37
|
protected _backingScaleDomain(): string[];
|
|
39
38
|
protected _backingScaleDomain(values: string[]): this;
|
|
@@ -9,6 +9,41 @@ 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
|
+
}());
|
|
12
47
|
// Preserve the public D3 4 palette names removed in D3 5.
|
|
13
48
|
var CATEGORY20 = [
|
|
14
49
|
"#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c",
|
|
@@ -40,41 +75,43 @@ var Color = /** @class */ (function (_super) {
|
|
|
40
75
|
*/
|
|
41
76
|
function Color(scaleType) {
|
|
42
77
|
var _this = _super.call(this) || this;
|
|
43
|
-
|
|
44
|
-
_this.
|
|
45
|
-
|
|
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;
|
|
46
82
|
switch (scaleType) {
|
|
47
83
|
case null:
|
|
48
84
|
case undefined:
|
|
49
85
|
if (Color._plottableColorCache == null) {
|
|
50
86
|
Color._plottableColorCache = Color._getPlottableColors();
|
|
51
87
|
}
|
|
52
|
-
|
|
88
|
+
scale = d3.scaleOrdinal().range(Color._plottableColorCache);
|
|
53
89
|
break;
|
|
54
90
|
case "Category10":
|
|
55
91
|
case "category10":
|
|
56
92
|
case "10":
|
|
57
|
-
|
|
93
|
+
scale = d3.scaleOrdinal(d3.schemeCategory10);
|
|
58
94
|
break;
|
|
59
95
|
case "Category20":
|
|
60
96
|
case "category20":
|
|
61
97
|
case "20":
|
|
62
|
-
|
|
98
|
+
scale = d3.scaleOrdinal(CATEGORY20);
|
|
63
99
|
break;
|
|
64
100
|
case "Category20b":
|
|
65
101
|
case "category20b":
|
|
66
102
|
case "20b":
|
|
67
|
-
|
|
103
|
+
scale = d3.scaleOrdinal(CATEGORY20B);
|
|
68
104
|
break;
|
|
69
105
|
case "Category20c":
|
|
70
106
|
case "category20c":
|
|
71
107
|
case "20c":
|
|
72
|
-
|
|
108
|
+
scale = d3.scaleOrdinal(CATEGORY20C);
|
|
73
109
|
break;
|
|
74
110
|
default:
|
|
75
111
|
throw new Error("Unsupported ColorScale type");
|
|
76
112
|
}
|
|
77
|
-
_this.
|
|
113
|
+
_this._d3Scale = scale;
|
|
114
|
+
_this._rangeLength = _this._d3Scale.range().length;
|
|
78
115
|
return _this;
|
|
79
116
|
}
|
|
80
117
|
Color.prototype.extentOfValues = function (values) {
|
|
@@ -114,45 +151,34 @@ var Color = /** @class */ (function (_super) {
|
|
|
114
151
|
* @returns {string}
|
|
115
152
|
*/
|
|
116
153
|
Color.prototype.scale = function (value) {
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
var numLooped = Math.floor(index / this.
|
|
154
|
+
var color = this._d3Scale(value);
|
|
155
|
+
var index = this._tracker.getIndex(value);
|
|
156
|
+
var numLooped = Math.floor(index / this._rangeLength);
|
|
120
157
|
if (numLooped === 0) {
|
|
121
158
|
return color;
|
|
122
159
|
}
|
|
123
160
|
var modifyFactor = Math.log(numLooped * Color._LOOP_LIGHTEN_FACTOR + 1);
|
|
124
161
|
return Utils.Color.lightenColor(color, modifyFactor);
|
|
125
162
|
};
|
|
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
|
-
};
|
|
136
163
|
Color.prototype._getDomain = function () {
|
|
137
164
|
return this._backingScaleDomain();
|
|
138
165
|
};
|
|
139
166
|
Color.prototype._backingScaleDomain = function (values) {
|
|
140
|
-
var _this = this;
|
|
141
167
|
if (values == null) {
|
|
142
|
-
return this.
|
|
168
|
+
return this._d3Scale.domain();
|
|
143
169
|
}
|
|
144
170
|
else {
|
|
145
|
-
this.
|
|
146
|
-
this.
|
|
147
|
-
values.forEach(function (value) { return _this._domainIndex(value); });
|
|
171
|
+
this._d3Scale.domain(values);
|
|
172
|
+
this._tracker.clear();
|
|
148
173
|
return this;
|
|
149
174
|
}
|
|
150
175
|
};
|
|
151
176
|
Color.prototype._getRange = function () {
|
|
152
|
-
return this.
|
|
177
|
+
return this._d3Scale.range();
|
|
153
178
|
};
|
|
154
179
|
Color.prototype._setRange = function (values) {
|
|
155
|
-
this.
|
|
180
|
+
this._d3Scale.range(values);
|
|
181
|
+
this._rangeLength = values.length;
|
|
156
182
|
};
|
|
157
183
|
Color._LOOP_LIGHTEN_FACTOR = 1.6;
|
|
158
184
|
// The maximum number of colors we are getting from CSS stylesheets
|
package/package.json
CHANGED
package/plottable.js
CHANGED
|
@@ -9240,7 +9240,6 @@ var Category = /** @class */ (function (_super) {
|
|
|
9240
9240
|
*/
|
|
9241
9241
|
function Category() {
|
|
9242
9242
|
var _this = _super.call(this) || this;
|
|
9243
|
-
_this._domain = [];
|
|
9244
9243
|
_this._range = [0, 1];
|
|
9245
9244
|
_this._d3Scale = d3.scaleBand();
|
|
9246
9245
|
_this._d3Scale.range(TRANSFORMATION_SPACE);
|
|
@@ -9290,7 +9289,7 @@ var Category = /** @class */ (function (_super) {
|
|
|
9290
9289
|
var normalizedDomain = domain.map(function (d) { return _this._d3Scale(d) + rangeBand / 2; });
|
|
9291
9290
|
var domainStart = d3.bisect(normalizedDomain, domainStartNormalized);
|
|
9292
9291
|
var domainEnd = d3.bisect(normalizedDomain, domainEndNormalized);
|
|
9293
|
-
return
|
|
9292
|
+
return domain.slice(domainStart, domainEnd);
|
|
9294
9293
|
};
|
|
9295
9294
|
Category.prototype.range = function (values) {
|
|
9296
9295
|
return _super.prototype.range.call(this, values);
|
|
@@ -9348,9 +9347,8 @@ var Category = /** @class */ (function (_super) {
|
|
|
9348
9347
|
return this;
|
|
9349
9348
|
};
|
|
9350
9349
|
Category.prototype.scale = function (value) {
|
|
9351
|
-
// Accessors read untyped data, so values can be numbers, and 1 and "1" must share a band
|
|
9352
9350
|
// Determine the middle of the range band for the value
|
|
9353
|
-
var untransformed = this._d3Scale(
|
|
9351
|
+
var untransformed = this._d3Scale(value) + this._d3Scale.bandwidth() / 2;
|
|
9354
9352
|
// Convert to screen space
|
|
9355
9353
|
return this._d3TransformationScale(untransformed);
|
|
9356
9354
|
};
|
|
@@ -9391,11 +9389,10 @@ var Category = /** @class */ (function (_super) {
|
|
|
9391
9389
|
};
|
|
9392
9390
|
Category.prototype._backingScaleDomain = function (values) {
|
|
9393
9391
|
if (values == null) {
|
|
9394
|
-
return this.
|
|
9392
|
+
return this._d3Scale.domain();
|
|
9395
9393
|
}
|
|
9396
9394
|
else {
|
|
9397
|
-
this.
|
|
9398
|
-
this._d3Scale.domain(this._domain.map(String));
|
|
9395
|
+
this._d3Scale.domain(values);
|
|
9399
9396
|
this._setBands();
|
|
9400
9397
|
return this;
|
|
9401
9398
|
}
|
|
@@ -18117,6 +18114,41 @@ var tslib_1 = __webpack_require__(0);
|
|
|
18117
18114
|
var d3 = __webpack_require__(2);
|
|
18118
18115
|
var Utils = __webpack_require__(1);
|
|
18119
18116
|
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
|
+
}());
|
|
18120
18152
|
// Preserve the public D3 4 palette names removed in D3 5.
|
|
18121
18153
|
var CATEGORY20 = [
|
|
18122
18154
|
"#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c",
|
|
@@ -18148,41 +18180,43 @@ var Color = /** @class */ (function (_super) {
|
|
|
18148
18180
|
*/
|
|
18149
18181
|
function Color(scaleType) {
|
|
18150
18182
|
var _this = _super.call(this) || this;
|
|
18151
|
-
|
|
18152
|
-
_this.
|
|
18153
|
-
|
|
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;
|
|
18154
18187
|
switch (scaleType) {
|
|
18155
18188
|
case null:
|
|
18156
18189
|
case undefined:
|
|
18157
18190
|
if (Color._plottableColorCache == null) {
|
|
18158
18191
|
Color._plottableColorCache = Color._getPlottableColors();
|
|
18159
18192
|
}
|
|
18160
|
-
|
|
18193
|
+
scale = d3.scaleOrdinal().range(Color._plottableColorCache);
|
|
18161
18194
|
break;
|
|
18162
18195
|
case "Category10":
|
|
18163
18196
|
case "category10":
|
|
18164
18197
|
case "10":
|
|
18165
|
-
|
|
18198
|
+
scale = d3.scaleOrdinal(d3.schemeCategory10);
|
|
18166
18199
|
break;
|
|
18167
18200
|
case "Category20":
|
|
18168
18201
|
case "category20":
|
|
18169
18202
|
case "20":
|
|
18170
|
-
|
|
18203
|
+
scale = d3.scaleOrdinal(CATEGORY20);
|
|
18171
18204
|
break;
|
|
18172
18205
|
case "Category20b":
|
|
18173
18206
|
case "category20b":
|
|
18174
18207
|
case "20b":
|
|
18175
|
-
|
|
18208
|
+
scale = d3.scaleOrdinal(CATEGORY20B);
|
|
18176
18209
|
break;
|
|
18177
18210
|
case "Category20c":
|
|
18178
18211
|
case "category20c":
|
|
18179
18212
|
case "20c":
|
|
18180
|
-
|
|
18213
|
+
scale = d3.scaleOrdinal(CATEGORY20C);
|
|
18181
18214
|
break;
|
|
18182
18215
|
default:
|
|
18183
18216
|
throw new Error("Unsupported ColorScale type");
|
|
18184
18217
|
}
|
|
18185
|
-
_this.
|
|
18218
|
+
_this._d3Scale = scale;
|
|
18219
|
+
_this._rangeLength = _this._d3Scale.range().length;
|
|
18186
18220
|
return _this;
|
|
18187
18221
|
}
|
|
18188
18222
|
Color.prototype.extentOfValues = function (values) {
|
|
@@ -18222,45 +18256,34 @@ var Color = /** @class */ (function (_super) {
|
|
|
18222
18256
|
* @returns {string}
|
|
18223
18257
|
*/
|
|
18224
18258
|
Color.prototype.scale = function (value) {
|
|
18225
|
-
var
|
|
18226
|
-
var
|
|
18227
|
-
var numLooped = Math.floor(index / this.
|
|
18259
|
+
var color = this._d3Scale(value);
|
|
18260
|
+
var index = this._tracker.getIndex(value);
|
|
18261
|
+
var numLooped = Math.floor(index / this._rangeLength);
|
|
18228
18262
|
if (numLooped === 0) {
|
|
18229
18263
|
return color;
|
|
18230
18264
|
}
|
|
18231
18265
|
var modifyFactor = Math.log(numLooped * Color._LOOP_LIGHTEN_FACTOR + 1);
|
|
18232
18266
|
return Utils.Color.lightenColor(color, modifyFactor);
|
|
18233
18267
|
};
|
|
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
|
-
};
|
|
18244
18268
|
Color.prototype._getDomain = function () {
|
|
18245
18269
|
return this._backingScaleDomain();
|
|
18246
18270
|
};
|
|
18247
18271
|
Color.prototype._backingScaleDomain = function (values) {
|
|
18248
|
-
var _this = this;
|
|
18249
18272
|
if (values == null) {
|
|
18250
|
-
return this.
|
|
18273
|
+
return this._d3Scale.domain();
|
|
18251
18274
|
}
|
|
18252
18275
|
else {
|
|
18253
|
-
this.
|
|
18254
|
-
this.
|
|
18255
|
-
values.forEach(function (value) { return _this._domainIndex(value); });
|
|
18276
|
+
this._d3Scale.domain(values);
|
|
18277
|
+
this._tracker.clear();
|
|
18256
18278
|
return this;
|
|
18257
18279
|
}
|
|
18258
18280
|
};
|
|
18259
18281
|
Color.prototype._getRange = function () {
|
|
18260
|
-
return this.
|
|
18282
|
+
return this._d3Scale.range();
|
|
18261
18283
|
};
|
|
18262
18284
|
Color.prototype._setRange = function (values) {
|
|
18263
|
-
this.
|
|
18285
|
+
this._d3Scale.range(values);
|
|
18286
|
+
this._rangeLength = values.length;
|
|
18264
18287
|
};
|
|
18265
18288
|
Color._LOOP_LIGHTEN_FACTOR = 1.6;
|
|
18266
18289
|
// The maximum number of colors we are getting from CSS stylesheets
|