@d3plus/core 3.0.0-alpha.0
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/README.md +6219 -0
- package/es/index.js +4 -0
- package/es/src/charts/AreaPlot.js +86 -0
- package/es/src/charts/BarChart.js +93 -0
- package/es/src/charts/BoxWhisker.js +97 -0
- package/es/src/charts/BumpChart.js +148 -0
- package/es/src/charts/Donut.js +84 -0
- package/es/src/charts/Geomap.js +833 -0
- package/es/src/charts/LinePlot.js +84 -0
- package/es/src/charts/Matrix.js +358 -0
- package/es/src/charts/Network.js +787 -0
- package/es/src/charts/Pack.js +318 -0
- package/es/src/charts/Pie.js +242 -0
- package/es/src/charts/Plot.js +2212 -0
- package/es/src/charts/Priestley.js +312 -0
- package/es/src/charts/Radar.js +365 -0
- package/es/src/charts/RadialMatrix.js +393 -0
- package/es/src/charts/Rings.js +777 -0
- package/es/src/charts/Sankey.js +413 -0
- package/es/src/charts/StackedArea.js +80 -0
- package/es/src/charts/Tree.js +312 -0
- package/es/src/charts/Treemap.js +406 -0
- package/es/src/charts/Viz.js +2017 -0
- package/es/src/charts/drawSteps/drawAttribution.js +14 -0
- package/es/src/charts/drawSteps/drawBack.js +23 -0
- package/es/src/charts/drawSteps/drawColorScale.js +69 -0
- package/es/src/charts/drawSteps/drawLegend.js +120 -0
- package/es/src/charts/drawSteps/drawSubtitle.js +31 -0
- package/es/src/charts/drawSteps/drawTimeline.js +80 -0
- package/es/src/charts/drawSteps/drawTitle.js +31 -0
- package/es/src/charts/drawSteps/drawTotal.js +32 -0
- package/es/src/charts/drawSteps/zoomControls.js +254 -0
- package/es/src/charts/events/click.legend.js +76 -0
- package/es/src/charts/events/click.shape.js +26 -0
- package/es/src/charts/events/mouseenter.js +31 -0
- package/es/src/charts/events/mouseleave.js +21 -0
- package/es/src/charts/events/mousemove.legend.js +64 -0
- package/es/src/charts/events/mousemove.shape.js +42 -0
- package/es/src/charts/events/touchstart.body.js +7 -0
- package/es/src/charts/helpers/matrixData.js +104 -0
- package/es/src/charts/helpers/tileAttributions.js +34 -0
- package/es/src/charts/index.js +21 -0
- package/es/src/charts/plotBuffers/Bar.js +65 -0
- package/es/src/charts/plotBuffers/Box.js +60 -0
- package/es/src/charts/plotBuffers/Circle.js +39 -0
- package/es/src/charts/plotBuffers/Line.js +30 -0
- package/es/src/charts/plotBuffers/Rect.js +40 -0
- package/es/src/charts/plotBuffers/discreteBuffer.js +24 -0
- package/es/src/charts/plotBuffers/numericBuffer.js +111 -0
- package/es/src/components/Axis.js +1567 -0
- package/es/src/components/AxisBottom.js +77 -0
- package/es/src/components/AxisLeft.js +77 -0
- package/es/src/components/AxisRight.js +77 -0
- package/es/src/components/AxisTop.js +77 -0
- package/es/src/components/ColorScale.js +958 -0
- package/es/src/components/Legend.js +673 -0
- package/es/src/components/Message.js +95 -0
- package/es/src/components/TextBox.js +752 -0
- package/es/src/components/Timeline.js +760 -0
- package/es/src/components/Tooltip.js +726 -0
- package/es/src/components/index.js +11 -0
- package/es/src/shapes/Area.js +361 -0
- package/es/src/shapes/Bar.js +342 -0
- package/es/src/shapes/Box.js +482 -0
- package/es/src/shapes/Circle.js +201 -0
- package/es/src/shapes/Image.js +255 -0
- package/es/src/shapes/Line.js +289 -0
- package/es/src/shapes/Path.js +186 -0
- package/es/src/shapes/Rect.js +215 -0
- package/es/src/shapes/Shape.js +1156 -0
- package/es/src/shapes/Whisker.js +330 -0
- package/es/src/shapes/index.js +10 -0
- package/es/src/utils/BaseClass.js +204 -0
- package/es/src/utils/RESET.js +4 -0
- package/es/src/utils/accessor.js +19 -0
- package/es/src/utils/configPrep.js +76 -0
- package/es/src/utils/constant.js +15 -0
- package/es/src/utils/getProp.js +9 -0
- package/es/src/utils/index.js +7 -0
- package/es/src/utils/uuid.js +13 -0
- package/package.json +68 -0
- package/umd/d3plus-core.full.js +56459 -0
- package/umd/d3plus-core.full.js.map +1 -0
- package/umd/d3plus-core.full.min.js +7241 -0
- package/umd/d3plus-core.js +14422 -0
- package/umd/d3plus-core.js.map +1 -0
- package/umd/d3plus-core.min.js +4564 -0
|
@@ -0,0 +1,958 @@
|
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function _call_super(_this, derived, args) {
|
|
8
|
+
derived = _get_prototype_of(derived);
|
|
9
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
10
|
+
}
|
|
11
|
+
function _class_call_check(instance, Constructor) {
|
|
12
|
+
if (!(instance instanceof Constructor)) {
|
|
13
|
+
throw new TypeError("Cannot call a class as a function");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _defineProperties(target, props) {
|
|
17
|
+
for(var i = 0; i < props.length; i++){
|
|
18
|
+
var descriptor = props[i];
|
|
19
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
20
|
+
descriptor.configurable = true;
|
|
21
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
22
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
26
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
27
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
28
|
+
return Constructor;
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _get_prototype_of(o) {
|
|
44
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
45
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
46
|
+
};
|
|
47
|
+
return _get_prototype_of(o);
|
|
48
|
+
}
|
|
49
|
+
function _inherits(subClass, superClass) {
|
|
50
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
51
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
52
|
+
}
|
|
53
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
54
|
+
constructor: {
|
|
55
|
+
value: subClass,
|
|
56
|
+
writable: true,
|
|
57
|
+
configurable: true
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
61
|
+
}
|
|
62
|
+
function _instanceof(left, right) {
|
|
63
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
64
|
+
return !!right[Symbol.hasInstance](left);
|
|
65
|
+
} else {
|
|
66
|
+
return left instanceof right;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function _possible_constructor_return(self, call) {
|
|
70
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
71
|
+
return call;
|
|
72
|
+
}
|
|
73
|
+
return _assert_this_initialized(self);
|
|
74
|
+
}
|
|
75
|
+
function _set_prototype_of(o, p) {
|
|
76
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
77
|
+
o.__proto__ = p;
|
|
78
|
+
return o;
|
|
79
|
+
};
|
|
80
|
+
return _set_prototype_of(o, p);
|
|
81
|
+
}
|
|
82
|
+
function _type_of(obj) {
|
|
83
|
+
"@swc/helpers - typeof";
|
|
84
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
85
|
+
}
|
|
86
|
+
function _is_native_reflect_construct() {
|
|
87
|
+
try {
|
|
88
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
89
|
+
} catch (_) {}
|
|
90
|
+
return (_is_native_reflect_construct = function() {
|
|
91
|
+
return !!result;
|
|
92
|
+
})();
|
|
93
|
+
}
|
|
94
|
+
import { extent, max, min, quantile, range, deviation } from "d3-array";
|
|
95
|
+
import { interpolateRgb } from "d3-interpolate";
|
|
96
|
+
import { scaleLinear, scaleThreshold } from "d3-scale";
|
|
97
|
+
import { select } from "d3-selection";
|
|
98
|
+
import { transition } from "d3-transition";
|
|
99
|
+
import { colorDefaults, colorLighter } from "@d3plus/color";
|
|
100
|
+
import { unique } from "@d3plus/data";
|
|
101
|
+
import { assign, elem, textWidth } from "@d3plus/dom";
|
|
102
|
+
import { formatAbbreviate } from "@d3plus/format";
|
|
103
|
+
import { ckmeans } from "@d3plus/math";
|
|
104
|
+
import { Axis, TextBox } from "../components/index.js";
|
|
105
|
+
import { Rect } from "../shapes/index.js";
|
|
106
|
+
import { accessor, BaseClass, constant } from "../utils/index.js";
|
|
107
|
+
import Legend from "./Legend.js";
|
|
108
|
+
var ColorScale = /*#__PURE__*/ function(BaseClass) {
|
|
109
|
+
"use strict";
|
|
110
|
+
_inherits(ColorScale, BaseClass);
|
|
111
|
+
function ColorScale() {
|
|
112
|
+
_class_call_check(this, ColorScale);
|
|
113
|
+
var _this;
|
|
114
|
+
_this = _call_super(this, ColorScale);
|
|
115
|
+
_this._axisClass = new Axis();
|
|
116
|
+
_this._axisConfig = {
|
|
117
|
+
gridSize: 0
|
|
118
|
+
};
|
|
119
|
+
_this._axisTest = new Axis();
|
|
120
|
+
_this._align = "middle";
|
|
121
|
+
_this._buckets = 5;
|
|
122
|
+
_this._bucketAxis = false;
|
|
123
|
+
_this._bucketFormat = function(tick, i, ticks, allValues) {
|
|
124
|
+
var format = _this._axisConfig.tickFormat ? _this._axisConfig.tickFormat : formatAbbreviate;
|
|
125
|
+
var next = ticks[i + 1];
|
|
126
|
+
var prev = i ? ticks[i - 1] : false;
|
|
127
|
+
var last = i === ticks.length - 1;
|
|
128
|
+
if (tick === next || last) {
|
|
129
|
+
var suffix = last && tick < max(allValues) ? "+" : "";
|
|
130
|
+
return "".concat(format(tick)).concat(suffix);
|
|
131
|
+
} else {
|
|
132
|
+
var mod = next ? next / 100 : tick / 100;
|
|
133
|
+
var pow = mod >= 1 || mod <= -1 ? Math.round(mod).toString().length - 1 : mod.toString().split(".")[1].replace(/([1-9])[1-9].*$/, "$1").length * -1;
|
|
134
|
+
var ten = Math.pow(10, pow);
|
|
135
|
+
var prevValue = prev === tick && i === 1 ? format(min([
|
|
136
|
+
tick + ten,
|
|
137
|
+
allValues.find(function(d) {
|
|
138
|
+
return d > tick && d < next;
|
|
139
|
+
})
|
|
140
|
+
])) : format(tick);
|
|
141
|
+
var nextValue = tick && i === 1 ? format(next) : format(max([
|
|
142
|
+
next - ten,
|
|
143
|
+
allValues.reverse().find(function(d) {
|
|
144
|
+
return d > tick && d < next;
|
|
145
|
+
})
|
|
146
|
+
]));
|
|
147
|
+
return _this._bucketJoiner(prevValue, nextValue);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
_this._bucketJoiner = function(a, b) {
|
|
151
|
+
return a !== b ? "".concat(a, " - ").concat(b) : "".concat(a);
|
|
152
|
+
};
|
|
153
|
+
_this._centered = true;
|
|
154
|
+
_this._color = [
|
|
155
|
+
"#54478C",
|
|
156
|
+
"#2C699A",
|
|
157
|
+
"#0DB39E",
|
|
158
|
+
"#83E377",
|
|
159
|
+
"#EFEA5A"
|
|
160
|
+
];
|
|
161
|
+
_this._colorMax = colorDefaults.on;
|
|
162
|
+
_this._colorMid = colorDefaults.light;
|
|
163
|
+
_this._colorMin = colorDefaults.off;
|
|
164
|
+
_this._data = [];
|
|
165
|
+
_this._duration = 600;
|
|
166
|
+
_this._height = 200;
|
|
167
|
+
_this._labelClass = new TextBox();
|
|
168
|
+
_this._labelConfig = {
|
|
169
|
+
fontColor: colorDefaults.dark,
|
|
170
|
+
fontSize: 12
|
|
171
|
+
};
|
|
172
|
+
_this._legendClass = new Legend();
|
|
173
|
+
_this._legendConfig = {
|
|
174
|
+
shapeConfig: {
|
|
175
|
+
stroke: colorDefaults.dark,
|
|
176
|
+
strokeWidth: 1
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
_this._midpoint = 0;
|
|
180
|
+
_this._orient = "bottom";
|
|
181
|
+
_this._outerBounds = {
|
|
182
|
+
width: 0,
|
|
183
|
+
height: 0,
|
|
184
|
+
x: 0,
|
|
185
|
+
y: 0
|
|
186
|
+
};
|
|
187
|
+
_this._padding = 5;
|
|
188
|
+
_this._rectClass = new Rect().parent(_this);
|
|
189
|
+
_this._rectConfig = {
|
|
190
|
+
stroke: "#999",
|
|
191
|
+
strokeWidth: 1
|
|
192
|
+
};
|
|
193
|
+
_this._scale = "linear";
|
|
194
|
+
_this._size = 10;
|
|
195
|
+
_this._value = accessor("value");
|
|
196
|
+
_this._width = 400;
|
|
197
|
+
return _this;
|
|
198
|
+
}
|
|
199
|
+
_create_class(ColorScale, [
|
|
200
|
+
{
|
|
201
|
+
/**
|
|
202
|
+
@memberof ColorScale
|
|
203
|
+
@desc Renders the current ColorScale to the page. If a *callback* is specified, it will be called once the ColorScale is done drawing.
|
|
204
|
+
@param {Function} [*callback* = undefined]
|
|
205
|
+
@chainable
|
|
206
|
+
*/ key: "render",
|
|
207
|
+
value: function render(callback) {
|
|
208
|
+
var _this = this;
|
|
209
|
+
if (this._select === void 0) this.select(select("body").append("svg").attr("width", "".concat(this._width, "px")).attr("height", "".concat(this._height, "px")).node());
|
|
210
|
+
var horizontal = [
|
|
211
|
+
"bottom",
|
|
212
|
+
"top"
|
|
213
|
+
].includes(this._orient);
|
|
214
|
+
var height = horizontal ? "height" : "width", width = horizontal ? "width" : "height", x = horizontal ? "x" : "y", y = horizontal ? "y" : "x";
|
|
215
|
+
// Shape <g> Group
|
|
216
|
+
this._group = elem("g.d3plus-ColorScale", {
|
|
217
|
+
parent: this._select
|
|
218
|
+
});
|
|
219
|
+
var allValues = this._data.map(this._value).filter(function(d) {
|
|
220
|
+
return d !== null && typeof d === "number";
|
|
221
|
+
}).sort(function(a, b) {
|
|
222
|
+
return a - b;
|
|
223
|
+
});
|
|
224
|
+
var domain = this._domain || extent(allValues);
|
|
225
|
+
var negative = domain[0] < this._midpoint;
|
|
226
|
+
var positive = domain[1] > this._midpoint;
|
|
227
|
+
var diverging = negative && positive;
|
|
228
|
+
var numBuckets = min([
|
|
229
|
+
_instanceof(this._buckets, Array) ? this._buckets.length : this._buckets,
|
|
230
|
+
diverging && this._scale !== "jenks" ? 2 * Math.floor(unique(allValues).length / 2) - 1 : unique(allValues).length
|
|
231
|
+
]);
|
|
232
|
+
var colors = diverging && (!this._color || _instanceof(this._color, Array) && !this._color.includes(this._colorMid)) ? undefined : this._color, labels, ticks;
|
|
233
|
+
if (colors && !_instanceof(colors, Array)) {
|
|
234
|
+
colors = range(0, numBuckets, 1).map(function(i) {
|
|
235
|
+
return colorLighter(colors, (i + 1) / numBuckets);
|
|
236
|
+
}).reverse();
|
|
237
|
+
}
|
|
238
|
+
if (this._scale === "jenks") {
|
|
239
|
+
var buckets = min([
|
|
240
|
+
colors ? colors.length : numBuckets,
|
|
241
|
+
numBuckets,
|
|
242
|
+
allValues.length
|
|
243
|
+
]);
|
|
244
|
+
var jenks = [];
|
|
245
|
+
if (_instanceof(this._buckets, Array)) {
|
|
246
|
+
ticks = this._buckets;
|
|
247
|
+
} else {
|
|
248
|
+
if (diverging && this._centered) {
|
|
249
|
+
var half = Math.floor(buckets / 2);
|
|
250
|
+
var residual = buckets % 2;
|
|
251
|
+
var negatives = allValues.filter(function(d) {
|
|
252
|
+
return d < _this._midpoint;
|
|
253
|
+
});
|
|
254
|
+
var negativesDeviation = deviation(negatives);
|
|
255
|
+
var positives = allValues.concat(this._midpoint).filter(function(d) {
|
|
256
|
+
return d >= _this._midpoint;
|
|
257
|
+
});
|
|
258
|
+
var positivesDeviation = deviation(positives);
|
|
259
|
+
var isNegativeMax = negativesDeviation > positivesDeviation ? 1 : 0;
|
|
260
|
+
var isPositiveMax = positivesDeviation > negativesDeviation ? 1 : 0;
|
|
261
|
+
var negativeJenks = ckmeans(negatives, min([
|
|
262
|
+
half + residual * isNegativeMax,
|
|
263
|
+
negatives.length
|
|
264
|
+
]));
|
|
265
|
+
var positiveJenks = ckmeans(positives, min([
|
|
266
|
+
half + residual * isPositiveMax,
|
|
267
|
+
positives.length
|
|
268
|
+
]));
|
|
269
|
+
jenks = negativeJenks.concat(positiveJenks);
|
|
270
|
+
} else {
|
|
271
|
+
jenks = ckmeans(allValues, buckets);
|
|
272
|
+
}
|
|
273
|
+
ticks = jenks.map(function(c) {
|
|
274
|
+
return c[0];
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
var tickSet = new Set(ticks);
|
|
278
|
+
if (ticks.length !== tickSet.size) labels = Array.from(tickSet);
|
|
279
|
+
if (!colors) {
|
|
280
|
+
if (diverging) {
|
|
281
|
+
colors = [
|
|
282
|
+
this._colorMin,
|
|
283
|
+
this._colorMid,
|
|
284
|
+
this._colorMax
|
|
285
|
+
];
|
|
286
|
+
var negatives1 = ticks.slice(0, buckets).filter(function(d, i) {
|
|
287
|
+
return d < _this._midpoint && ticks[i + 1] <= _this._midpoint;
|
|
288
|
+
});
|
|
289
|
+
var spanning = ticks.slice(0, buckets).filter(function(d, i) {
|
|
290
|
+
return d <= _this._midpoint && ticks[i + 1] > _this._midpoint;
|
|
291
|
+
});
|
|
292
|
+
var positives1 = ticks.slice(0, buckets).filter(function(d) {
|
|
293
|
+
return d > _this._midpoint;
|
|
294
|
+
});
|
|
295
|
+
var negativeColors = negatives1.map(function(d, i) {
|
|
296
|
+
return !i ? colors[0] : colorLighter(colors[0], i / negatives1.length);
|
|
297
|
+
});
|
|
298
|
+
var spanningColors = spanning.map(function() {
|
|
299
|
+
return colors[1];
|
|
300
|
+
});
|
|
301
|
+
var positiveColors = positives1.map(function(d, i) {
|
|
302
|
+
return i === positives1.length - 1 ? colors[2] : colorLighter(colors[2], 1 - (i + 1) / positives1.length);
|
|
303
|
+
});
|
|
304
|
+
colors = negativeColors.concat(spanningColors).concat(positiveColors);
|
|
305
|
+
} else {
|
|
306
|
+
colors = range(0, numBuckets, 1).map(function(i) {
|
|
307
|
+
return colorLighter(_this._colorMax, i / numBuckets);
|
|
308
|
+
}).reverse();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (ticks.length <= buckets) colors = colors.slice(-ticks.length);
|
|
312
|
+
colors = [
|
|
313
|
+
colors[0]
|
|
314
|
+
].concat(colors);
|
|
315
|
+
this._colorScale = scaleThreshold().domain(ticks).range(colors);
|
|
316
|
+
} else {
|
|
317
|
+
var buckets1 = _instanceof(this._buckets, Array) ? this._buckets : undefined;
|
|
318
|
+
if (diverging && !colors) {
|
|
319
|
+
var half1 = Math.floor(numBuckets / 2);
|
|
320
|
+
var negativeColorScale = interpolateRgb.gamma(2.2)(this._colorMin, this._colorMid);
|
|
321
|
+
var negativeColors1 = range(0, half1, 1).map(function(i) {
|
|
322
|
+
return negativeColorScale(i / half1);
|
|
323
|
+
});
|
|
324
|
+
var spanningColors1 = (numBuckets % 2 ? [
|
|
325
|
+
0
|
|
326
|
+
] : []).map(function() {
|
|
327
|
+
return _this._colorMid;
|
|
328
|
+
});
|
|
329
|
+
var positiveColorScale = interpolateRgb.gamma(2.2)(this._colorMax, this._colorMid);
|
|
330
|
+
var positiveColors1 = range(0, half1, 1).map(function(i) {
|
|
331
|
+
return positiveColorScale(i / half1);
|
|
332
|
+
}).reverse();
|
|
333
|
+
colors = negativeColors1.concat(spanningColors1).concat(positiveColors1);
|
|
334
|
+
if (!buckets1) {
|
|
335
|
+
var step = (colors.length - 1) / 2;
|
|
336
|
+
buckets1 = [
|
|
337
|
+
domain[0],
|
|
338
|
+
this._midpoint,
|
|
339
|
+
domain[1]
|
|
340
|
+
];
|
|
341
|
+
buckets1 = range(domain[0], this._midpoint, -(domain[0] - this._midpoint) / step).concat(range(this._midpoint, domain[1], (domain[1] - this._midpoint) / step)).concat([
|
|
342
|
+
domain[1]
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
if (!colors) {
|
|
347
|
+
if (this._scale === "buckets" || this._scale === "quantile") {
|
|
348
|
+
colors = range(0, numBuckets, 1).map(function(i) {
|
|
349
|
+
return colorLighter(negative ? _this._colorMin : _this._colorMax, i / numBuckets);
|
|
350
|
+
});
|
|
351
|
+
if (positive) colors = colors.reverse();
|
|
352
|
+
} else {
|
|
353
|
+
colors = negative ? [
|
|
354
|
+
this._colorMin,
|
|
355
|
+
colorLighter(this._colorMin, 0.8)
|
|
356
|
+
] : [
|
|
357
|
+
colorLighter(this._colorMax, 0.8),
|
|
358
|
+
this._colorMax
|
|
359
|
+
];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (!buckets1) {
|
|
363
|
+
if (this._scale === "quantile") {
|
|
364
|
+
var step1 = 1 / (colors.length - 1);
|
|
365
|
+
buckets1 = range(0, 1 + step1 / 2, step1).map(function(d) {
|
|
366
|
+
return quantile(allValues, d);
|
|
367
|
+
});
|
|
368
|
+
} else if (diverging && this._color && this._centered) {
|
|
369
|
+
var midIndex = colors.indexOf(this._colorMid);
|
|
370
|
+
var negativeStep = (this._midpoint - domain[0]) / midIndex;
|
|
371
|
+
var positiveStep = (domain[1] - this._midpoint) / (colors.length - midIndex);
|
|
372
|
+
var negativeBuckets = range(domain[0], this._midpoint, negativeStep);
|
|
373
|
+
var positiveBuckets = range(this._midpoint, domain[1] + positiveStep / 2, positiveStep);
|
|
374
|
+
buckets1 = negativeBuckets.concat(positiveBuckets);
|
|
375
|
+
} else {
|
|
376
|
+
var step2 = (domain[1] - domain[0]) / (colors.length - 1);
|
|
377
|
+
buckets1 = range(domain[0], domain[1] + step2 / 2, step2);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (this._scale === "buckets" || this._scale === "quantile") {
|
|
382
|
+
ticks = buckets1;
|
|
383
|
+
colors = [
|
|
384
|
+
colors[0]
|
|
385
|
+
].concat(colors);
|
|
386
|
+
} else if (this._scale === "log") {
|
|
387
|
+
var negativeBuckets1 = buckets1.filter(function(d) {
|
|
388
|
+
return d < 0;
|
|
389
|
+
});
|
|
390
|
+
if (negativeBuckets1.length) {
|
|
391
|
+
var minVal = negativeBuckets1[0];
|
|
392
|
+
var newNegativeBuckets = negativeBuckets1.map(function(d) {
|
|
393
|
+
return -Math.pow(Math.abs(minVal), d / minVal);
|
|
394
|
+
});
|
|
395
|
+
negativeBuckets1.forEach(function(bucket, i) {
|
|
396
|
+
buckets1[buckets1.indexOf(bucket)] = newNegativeBuckets[i];
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
var positiveBuckets1 = buckets1.filter(function(d) {
|
|
400
|
+
return d > 0;
|
|
401
|
+
});
|
|
402
|
+
if (positiveBuckets1.length) {
|
|
403
|
+
var maxVal = positiveBuckets1[positiveBuckets1.length - 1];
|
|
404
|
+
var newPositiveBuckets = positiveBuckets1.map(function(d) {
|
|
405
|
+
return Math.pow(maxVal, d / maxVal);
|
|
406
|
+
});
|
|
407
|
+
positiveBuckets1.forEach(function(bucket, i) {
|
|
408
|
+
buckets1[buckets1.indexOf(bucket)] = newPositiveBuckets[i];
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (buckets1.includes(0)) buckets1[buckets1.indexOf(0)] = 1;
|
|
412
|
+
}
|
|
413
|
+
this._colorScale = (this._scale === "buckets" || this._scale === "quantile" ? scaleThreshold : scaleLinear)().domain(buckets1).range(colors);
|
|
414
|
+
}
|
|
415
|
+
if (this._colorScale.clamp) this._colorScale.clamp(true);
|
|
416
|
+
var gradient = this._bucketAxis || ![
|
|
417
|
+
"buckets",
|
|
418
|
+
"jenks",
|
|
419
|
+
"quantile"
|
|
420
|
+
].includes(this._scale);
|
|
421
|
+
var t = transition().duration(this._duration);
|
|
422
|
+
var groupParams = {
|
|
423
|
+
enter: {
|
|
424
|
+
opacity: 0
|
|
425
|
+
},
|
|
426
|
+
exit: {
|
|
427
|
+
opacity: 0
|
|
428
|
+
},
|
|
429
|
+
parent: this._group,
|
|
430
|
+
transition: t,
|
|
431
|
+
update: {
|
|
432
|
+
opacity: 1
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var labelGroup = elem("g.d3plus-ColorScale-labels", Object.assign({
|
|
436
|
+
condition: gradient
|
|
437
|
+
}, groupParams));
|
|
438
|
+
var rectGroup = elem("g.d3plus-ColorScale-Rect", Object.assign({
|
|
439
|
+
condition: gradient
|
|
440
|
+
}, groupParams));
|
|
441
|
+
var legendGroup = elem("g.d3plus-ColorScale-legend", Object.assign({
|
|
442
|
+
condition: !gradient
|
|
443
|
+
}, groupParams));
|
|
444
|
+
if (gradient) {
|
|
445
|
+
var offsets = {
|
|
446
|
+
x: 0,
|
|
447
|
+
y: 0
|
|
448
|
+
};
|
|
449
|
+
var axisDomain = domain.slice();
|
|
450
|
+
if (this._bucketAxis) {
|
|
451
|
+
var last = axisDomain[axisDomain.length - 1];
|
|
452
|
+
var prev = axisDomain[axisDomain.length - 2];
|
|
453
|
+
var mod = last ? last / 10 : prev / 10;
|
|
454
|
+
var pow = mod >= 1 || mod <= -1 ? Math.round(mod).toString().length - 1 : mod.toString().split(".")[1].replace(/([1-9])[1-9].*$/, "$1").length * -1;
|
|
455
|
+
var ten = Math.pow(10, pow);
|
|
456
|
+
axisDomain[axisDomain.length - 1] = last + ten;
|
|
457
|
+
}
|
|
458
|
+
var axisConfig = assign({
|
|
459
|
+
domain: horizontal ? axisDomain : axisDomain.slice().reverse(),
|
|
460
|
+
duration: this._duration,
|
|
461
|
+
height: this._height,
|
|
462
|
+
labels: labels || ticks,
|
|
463
|
+
orient: this._orient,
|
|
464
|
+
padding: this._padding,
|
|
465
|
+
scale: this._scale === "log" ? "log" : "linear",
|
|
466
|
+
ticks: ticks,
|
|
467
|
+
width: this._width
|
|
468
|
+
}, this._axisConfig);
|
|
469
|
+
var labelConfig = assign({
|
|
470
|
+
height: this["_".concat(height)] / 2,
|
|
471
|
+
width: this["_".concat(width)] / 2
|
|
472
|
+
}, this._labelConfig);
|
|
473
|
+
this._labelClass.config(labelConfig);
|
|
474
|
+
var labelData = [];
|
|
475
|
+
if (horizontal && this._labelMin) {
|
|
476
|
+
var labelCSS = {
|
|
477
|
+
"font-family": this._labelClass.fontFamily()(this._labelMin),
|
|
478
|
+
"font-size": this._labelClass.fontSize()(this._labelMin),
|
|
479
|
+
"font-weight": this._labelClass.fontWeight()(this._labelMin)
|
|
480
|
+
};
|
|
481
|
+
if (_instanceof(labelCSS["font-family"], Array)) labelCSS["font-family"] = labelCSS["font-family"][0];
|
|
482
|
+
var labelMinWidth = textWidth(this._labelMin, labelCSS);
|
|
483
|
+
if (labelMinWidth && labelMinWidth < this["_".concat(width)] / 2) {
|
|
484
|
+
labelData.push(this._labelMin);
|
|
485
|
+
labelMinWidth += this._padding;
|
|
486
|
+
if (horizontal) offsets.x += labelMinWidth;
|
|
487
|
+
axisConfig[width] -= labelMinWidth;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (horizontal && this._labelMax) {
|
|
491
|
+
var labelCSS1 = {
|
|
492
|
+
"font-family": this._labelClass.fontFamily()(this._labelMax),
|
|
493
|
+
"font-size": this._labelClass.fontSize()(this._labelMax),
|
|
494
|
+
"font-weight": this._labelClass.fontWeight()(this._labelMax)
|
|
495
|
+
};
|
|
496
|
+
if (_instanceof(labelCSS1["font-family"], Array)) labelCSS1["font-family"] = labelCSS1["font-family"][0];
|
|
497
|
+
var labelMaxWidth = textWidth(this._labelMax, labelCSS1);
|
|
498
|
+
if (labelMaxWidth && labelMaxWidth < this["_".concat(width)] / 2) {
|
|
499
|
+
labelData.push(this._labelMax);
|
|
500
|
+
labelMaxWidth += this._padding;
|
|
501
|
+
if (!horizontal) offsets.y += labelMaxWidth;
|
|
502
|
+
axisConfig[width] -= labelMaxWidth;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
this._axisTest.select(elem("g.d3plus-ColorScale-axisTest", {
|
|
506
|
+
enter: {
|
|
507
|
+
opacity: 0
|
|
508
|
+
},
|
|
509
|
+
parent: this._group
|
|
510
|
+
}).node()).config(axisConfig).duration(0).render();
|
|
511
|
+
var axisBounds = this._axisTest.outerBounds();
|
|
512
|
+
this._outerBounds[width] = this["_".concat(width)] - this._padding * 2;
|
|
513
|
+
this._outerBounds[height] = axisBounds[height] + this._size;
|
|
514
|
+
this._outerBounds[x] = this._padding;
|
|
515
|
+
this._outerBounds[y] = this._padding;
|
|
516
|
+
if (this._align === "middle") this._outerBounds[y] = (this["_".concat(height)] - this._outerBounds[height]) / 2;
|
|
517
|
+
else if (this._align === "end") this._outerBounds[y] = this["_".concat(height)] - this._padding - this._outerBounds[height];
|
|
518
|
+
var axisGroupOffset = this._outerBounds[y] + ([
|
|
519
|
+
"bottom",
|
|
520
|
+
"right"
|
|
521
|
+
].includes(this._orient) ? this._size : 0) - (axisConfig.padding || this._axisClass.padding());
|
|
522
|
+
var transform = "translate(".concat(offsets.x + (horizontal ? 0 : axisGroupOffset), ", ").concat(offsets.y + (horizontal ? axisGroupOffset : 0), ")");
|
|
523
|
+
this._axisClass.select(elem("g.d3plus-ColorScale-axis", assign(groupParams, {
|
|
524
|
+
condition: true,
|
|
525
|
+
enter: {
|
|
526
|
+
transform: transform
|
|
527
|
+
},
|
|
528
|
+
update: {
|
|
529
|
+
transform: transform
|
|
530
|
+
}
|
|
531
|
+
})).node()).config(axisConfig).align("start").render();
|
|
532
|
+
var axisScale = this._axisTest._getPosition.bind(this._axisTest);
|
|
533
|
+
var scaleRange = this._axisTest._getRange();
|
|
534
|
+
var defs = this._group.selectAll("defs").data([
|
|
535
|
+
0
|
|
536
|
+
]);
|
|
537
|
+
var defsEnter = defs.enter().append("defs");
|
|
538
|
+
defsEnter.append("linearGradient").attr("id", "gradient-".concat(this._uuid));
|
|
539
|
+
defs = defsEnter.merge(defs);
|
|
540
|
+
defs.select("linearGradient").attr("".concat(x, "1"), horizontal ? "0%" : "100%").attr("".concat(x, "2"), horizontal ? "100%" : "0%").attr("".concat(y, "1"), "0%").attr("".concat(y, "2"), "0%");
|
|
541
|
+
var stops = defs.select("linearGradient").selectAll("stop").data(colors);
|
|
542
|
+
var scaleDomain = this._colorScale.domain();
|
|
543
|
+
var offsetScale = scaleLinear().domain(scaleRange).range(horizontal ? [
|
|
544
|
+
0,
|
|
545
|
+
100
|
|
546
|
+
] : [
|
|
547
|
+
100,
|
|
548
|
+
0
|
|
549
|
+
]);
|
|
550
|
+
stops.enter().append("stop").merge(stops).attr("offset", function(d, i) {
|
|
551
|
+
return "".concat(i <= scaleDomain.length - 1 ? offsetScale(axisScale(scaleDomain[i])) : 100, "%");
|
|
552
|
+
}).attr("stop-color", String);
|
|
553
|
+
/** determines the width of buckets */ var bucketWidth = function(d, i) {
|
|
554
|
+
var next = ticks[i + 1] || axisDomain[axisDomain.length - 1];
|
|
555
|
+
return Math.abs(axisScale(next) - axisScale(d));
|
|
556
|
+
};
|
|
557
|
+
var _obj;
|
|
558
|
+
var rectConfig = assign((_obj = {
|
|
559
|
+
duration: this._duration,
|
|
560
|
+
fill: ticks ? function(d) {
|
|
561
|
+
return _this._colorScale(d);
|
|
562
|
+
} : "url(#gradient-".concat(this._uuid, ")")
|
|
563
|
+
}, _define_property(_obj, x, ticks ? function(d, i) {
|
|
564
|
+
return axisScale(d) + bucketWidth(d, i) / 2 - ([
|
|
565
|
+
"left",
|
|
566
|
+
"right"
|
|
567
|
+
].includes(_this._orient) ? bucketWidth(d, i) : 0);
|
|
568
|
+
} : scaleRange[0] + (scaleRange[1] - scaleRange[0]) / 2 + offsets[x]), _define_property(_obj, y, this._outerBounds[y] + ([
|
|
569
|
+
"top",
|
|
570
|
+
"left"
|
|
571
|
+
].includes(this._orient) ? axisBounds[height] : 0) + this._size / 2 + offsets[y]), _define_property(_obj, width, ticks ? bucketWidth : scaleRange[1] - scaleRange[0]), _define_property(_obj, height, this._size), _obj), this._rectConfig);
|
|
572
|
+
this._rectClass.data(ticks || [
|
|
573
|
+
0
|
|
574
|
+
]).id(function(d, i) {
|
|
575
|
+
return i;
|
|
576
|
+
}).select(rectGroup.node()).config(rectConfig).render();
|
|
577
|
+
labelConfig.height = this._outerBounds[height];
|
|
578
|
+
labelConfig.width = this._outerBounds[width];
|
|
579
|
+
this._labelClass.config(labelConfig).data(labelData).select(labelGroup.node()).x(function(d) {
|
|
580
|
+
return d === _this._labelMax ? rectConfig.x + rectConfig.width / 2 + _this._padding : _this._outerBounds.x;
|
|
581
|
+
}).y(function(d) {
|
|
582
|
+
return rectConfig.y - _this._labelClass.fontSize()(d) / 2;
|
|
583
|
+
}).text(function(d) {
|
|
584
|
+
return d;
|
|
585
|
+
}).rotate(horizontal ? 0 : this._orient === "right" ? 90 : -90).render();
|
|
586
|
+
} else {
|
|
587
|
+
elem("g.d3plus-ColorScale-axis", Object.assign({
|
|
588
|
+
condition: gradient
|
|
589
|
+
}, groupParams));
|
|
590
|
+
var legendData = ticks.reduce(function(arr, tick, i) {
|
|
591
|
+
var label = _this._bucketFormat.bind(_this)(tick, i, ticks, allValues);
|
|
592
|
+
arr.push({
|
|
593
|
+
color: colors[i + 1],
|
|
594
|
+
id: label
|
|
595
|
+
});
|
|
596
|
+
return arr;
|
|
597
|
+
}, []);
|
|
598
|
+
if (!horizontal) legendData = legendData.reverse();
|
|
599
|
+
var legendConfig = assign({
|
|
600
|
+
align: horizontal ? "center" : ({
|
|
601
|
+
start: "left",
|
|
602
|
+
middle: "center",
|
|
603
|
+
end: "right"
|
|
604
|
+
})[this._align],
|
|
605
|
+
direction: horizontal ? "row" : "column",
|
|
606
|
+
duration: this._duration,
|
|
607
|
+
height: this._height,
|
|
608
|
+
padding: this._padding,
|
|
609
|
+
shapeConfig: assign({
|
|
610
|
+
duration: this._duration
|
|
611
|
+
}, this._axisConfig.shapeConfig || {}),
|
|
612
|
+
title: this._axisConfig.title,
|
|
613
|
+
titleConfig: this._axisConfig.titleConfig || {},
|
|
614
|
+
width: this._width,
|
|
615
|
+
verticalAlign: horizontal ? ({
|
|
616
|
+
start: "top",
|
|
617
|
+
middle: "middle",
|
|
618
|
+
end: "bottom"
|
|
619
|
+
})[this._align] : "middle"
|
|
620
|
+
}, this._legendConfig);
|
|
621
|
+
this._legendClass.data(legendData).select(legendGroup.node()).config(legendConfig).render();
|
|
622
|
+
this._outerBounds = this._legendClass.outerBounds();
|
|
623
|
+
}
|
|
624
|
+
if (callback) setTimeout(callback, this._duration + 100);
|
|
625
|
+
return this;
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
/**
|
|
630
|
+
@memberof ColorScale
|
|
631
|
+
@desc The [ColorScale](http://d3plus.org/docs/#ColorScale) is constructed by combining an [Axis](http://d3plus.org/docs/#Axis) for the ticks/labels and a [Rect](http://d3plus.org/docs/#Rect) for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the [Axis](http://d3plus.org/docs/#Axis) class used to display the text ([axisConfig](http://d3plus.org/docs/#ColorScale.axisConfig)) and the [Rect](http://d3plus.org/docs/#Rect) class used to draw the color breaks ([rectConfig](http://d3plus.org/docs/#ColorScale.rectConfig)). This method acts as a pass-through to the config method of the [Axis](http://d3plus.org/docs/#Axis). An example usage of this method can be seen [here](http://d3plus.org/examples/d3plus-legend/colorScale-dark/).
|
|
632
|
+
@param {Object} [*value*]
|
|
633
|
+
@chainable
|
|
634
|
+
*/ key: "axisConfig",
|
|
635
|
+
value: function axisConfig(_) {
|
|
636
|
+
return arguments.length ? (this._axisConfig = assign(this._axisConfig, _), this) : this._axisConfig;
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
/**
|
|
641
|
+
@memberof ColorScale
|
|
642
|
+
@desc If *value* is specified, sets the horizontal alignment to the specified value and returns the current class instance. If *value* is not specified, returns the current horizontal alignment.
|
|
643
|
+
@param {String} [*value* = "center"] Supports `"left"` and `"center"` and `"right"`.
|
|
644
|
+
@chainable
|
|
645
|
+
*/ key: "align",
|
|
646
|
+
value: function align(_) {
|
|
647
|
+
return arguments.length ? (this._align = _, this) : this._align;
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
/**
|
|
652
|
+
@memberof ColorScale
|
|
653
|
+
@desc The number of discrete buckets to create in a bucketed color scale. Will be overridden by any custom Array of colors passed to the `color` method. Optionally, users can supply an Array of values used to separate buckets, such as `[0, 10, 25, 50, 90]` for a percentage scale. This value would create 4 buckets, with each value representing the break point between each bucket (so 5 values makes 4 buckets).
|
|
654
|
+
@param {Number|Array} [*value* = 5]
|
|
655
|
+
@chainable
|
|
656
|
+
*/ key: "buckets",
|
|
657
|
+
value: function buckets(_) {
|
|
658
|
+
return arguments.length ? (this._buckets = _, this) : this._buckets;
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
/**
|
|
663
|
+
@memberof ColorScale
|
|
664
|
+
@desc Determines whether or not to use an Axis to display bucket scales (both "buckets" and "jenks"). When set to `false`, bucketed scales will use the `Legend` class to display squares for each range of data. When set to `true`, bucketed scales will be displayed on an `Axis`, similar to "linear" scales.
|
|
665
|
+
@param {Boolean} [*value* = false]
|
|
666
|
+
@chainable
|
|
667
|
+
*/ key: "bucketAxis",
|
|
668
|
+
value: function bucketAxis(_) {
|
|
669
|
+
return arguments.length ? (this._bucketAxis = _, this) : this._bucketAxis;
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
/**
|
|
674
|
+
@memberof ColorScale
|
|
675
|
+
@desc A function for formatting the labels associated to each bucket in a bucket-type scale ("jenks", "quantile", etc). The function is passed four arguments: the start value of the current bucket, it's index in the full Array of buckets, the full Array of buckets, and an Array of every value present in the data used to construct the buckets. Keep in mind that the end value for the bucket is not actually the next bucket in the list, but includes every value up until that next bucket value (less than, but not equal to). By default, d3plus will make the end value slightly less than it's current value, so that it does not overlap with the start label for the next bucket.
|
|
676
|
+
@param {Function} [*value*]
|
|
677
|
+
@chainable
|
|
678
|
+
*/ key: "bucketFormat",
|
|
679
|
+
value: function bucketFormat(_) {
|
|
680
|
+
return arguments.length ? (this._bucketFormat = _, this) : this._bucketFormat;
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
/**
|
|
685
|
+
@memberof ColorScale
|
|
686
|
+
@desc A function that receives the minimum and maximum values of a bucket, and is expected to return the full label.
|
|
687
|
+
@param {Function} [*value*]
|
|
688
|
+
@chainable
|
|
689
|
+
*/ key: "bucketJoiner",
|
|
690
|
+
value: function bucketJoiner(_) {
|
|
691
|
+
return arguments.length ? (this._bucketJoiner = _, this) : this._bucketJoiner;
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
/**
|
|
696
|
+
@memberof ColorScale
|
|
697
|
+
@desc Determines whether or not to display a midpoint centered Axis. Does not apply to quantile scales.
|
|
698
|
+
@param {Boolean} [*value* = false]
|
|
699
|
+
@chainable
|
|
700
|
+
*/ key: "centered",
|
|
701
|
+
value: function centered(_) {
|
|
702
|
+
return arguments.length ? (this._centered = _, this) : this._centered;
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
/**
|
|
707
|
+
@memberof ColorScale
|
|
708
|
+
@desc Overrides the default internal logic of `colorMin`, `colorMid`, and `colorMax` to only use just this specified color. If a single color is given as a String, then the scale is interpolated by lightening that color. Otherwise, the function expects an Array of color values to be used in order for the scale.
|
|
709
|
+
@param {String|Array} [*value*]
|
|
710
|
+
@chainable
|
|
711
|
+
*/ key: "color",
|
|
712
|
+
value: function color(_) {
|
|
713
|
+
return arguments.length ? (this._color = _, this) : this._color;
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
/**
|
|
718
|
+
@memberof ColorScale
|
|
719
|
+
@desc Defines the color to be used for numbers greater than the value of the `midpoint` on the scale (defaults to `0`). Colors in between this value and the value of `colorMid` will be interpolated, unless a custom Array of colors has been specified using the `color` method.
|
|
720
|
+
@param {String} [*value* = "#0C8040"]
|
|
721
|
+
@chainable
|
|
722
|
+
*/ key: "colorMax",
|
|
723
|
+
value: function colorMax(_) {
|
|
724
|
+
return arguments.length ? (this._colorMax = _, this) : this._colorMax;
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
/**
|
|
729
|
+
@memberof ColorScale
|
|
730
|
+
@desc Defines the color to be used for the midpoint of a diverging scale, based on the current value of the `midpoint` method (defaults to `0`). Colors in between this value and the values of `colorMin` and `colorMax` will be interpolated, unless a custom Array of colors has been specified using the `color` method.
|
|
731
|
+
@param {String} [*value* = "#f7f7f7"]
|
|
732
|
+
@chainable
|
|
733
|
+
*/ key: "colorMid",
|
|
734
|
+
value: function colorMid(_) {
|
|
735
|
+
return arguments.length ? (this._colorMid = _, this) : this._colorMid;
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
/**
|
|
740
|
+
@memberof ColorScale
|
|
741
|
+
@desc Defines the color to be used for numbers less than the value of the `midpoint` on the scale (defaults to `0`). Colors in between this value and the value of `colorMid` will be interpolated, unless a custom Array of colors has been specified using the `color` method.
|
|
742
|
+
@param {String} [*value* = "#b22200"]
|
|
743
|
+
@chainable
|
|
744
|
+
*/ key: "colorMin",
|
|
745
|
+
value: function colorMin(_) {
|
|
746
|
+
return arguments.length ? (this._colorMin = _, this) : this._colorMin;
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
/**
|
|
751
|
+
@memberof ColorScale
|
|
752
|
+
@desc If *data* is specified, sets the data array to the specified array and returns the current class instance. If *data* is not specified, returns the current data array. A shape key will be drawn for each object in the array.
|
|
753
|
+
@param {Array} [*data* = []]
|
|
754
|
+
@chainable
|
|
755
|
+
*/ key: "data",
|
|
756
|
+
value: function data(_) {
|
|
757
|
+
return arguments.length ? (this._data = _, this) : this._data;
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
/**
|
|
762
|
+
@memberof ColorScale
|
|
763
|
+
@desc In a linear scale, this Array of 2 values defines the min and max values used in the color scale. Any values outside of this range will be mapped to the nearest color value.
|
|
764
|
+
@param {Array} [*value*]
|
|
765
|
+
@chainable
|
|
766
|
+
*/ key: "domain",
|
|
767
|
+
value: function domain(_) {
|
|
768
|
+
return arguments.length ? (this._domain = _, this) : this._domain;
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
/**
|
|
773
|
+
@memberof ColorScale
|
|
774
|
+
@desc If *value* is specified, sets the transition duration of the ColorScale and returns the current class instance. If *value* is not specified, returns the current duration.
|
|
775
|
+
@param {Number} [*value* = 600]
|
|
776
|
+
@chainable
|
|
777
|
+
*/ key: "duration",
|
|
778
|
+
value: function duration(_) {
|
|
779
|
+
return arguments.length ? (this._duration = _, this) : this._duration;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
/**
|
|
784
|
+
@memberof ColorScale
|
|
785
|
+
@desc If *value* is specified, sets the overall height of the ColorScale and returns the current class instance. If *value* is not specified, returns the current height value.
|
|
786
|
+
@param {Number} [*value* = 100]
|
|
787
|
+
@chainable
|
|
788
|
+
*/ key: "height",
|
|
789
|
+
value: function height(_) {
|
|
790
|
+
return arguments.length ? (this._height = _, this) : this._height;
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
/**
|
|
795
|
+
@memberof ColorScale
|
|
796
|
+
@desc A pass-through for the [TextBox](http://d3plus.org/docs/#TextBox) class used to style the labelMin and labelMax text.
|
|
797
|
+
@param {Object} [*value*]
|
|
798
|
+
@chainable
|
|
799
|
+
*/ key: "labelConfig",
|
|
800
|
+
value: function labelConfig(_) {
|
|
801
|
+
return arguments.length ? (this._labelConfig = assign(this._labelConfig, _), this) : this._labelConfig;
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
/**
|
|
806
|
+
@memberof ColorScale
|
|
807
|
+
@desc Defines a text label to be displayed off of the end of the minimum point in the scale (currently only available in horizontal orientation).
|
|
808
|
+
@param {String} [*value*]
|
|
809
|
+
@chainable
|
|
810
|
+
*/ key: "labelMin",
|
|
811
|
+
value: function labelMin(_) {
|
|
812
|
+
return arguments.length ? (this._labelMin = _, this) : this._labelMin;
|
|
813
|
+
}
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
/**
|
|
817
|
+
@memberof ColorScale
|
|
818
|
+
@desc Defines a text label to be displayed off of the end of the maximum point in the scale (currently only available in horizontal orientation).
|
|
819
|
+
@param {String} [*value*]
|
|
820
|
+
@chainable
|
|
821
|
+
*/ key: "labelMax",
|
|
822
|
+
value: function labelMax(_) {
|
|
823
|
+
return arguments.length ? (this._labelMax = _, this) : this._labelMax;
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
/**
|
|
828
|
+
@memberof ColorScale
|
|
829
|
+
@desc The [ColorScale](http://d3plus.org/docs/#ColorScale) is constructed by combining an [Axis](http://d3plus.org/docs/#Axis) for the ticks/labels and a [Rect](http://d3plus.org/docs/#Rect) for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the [Axis](http://d3plus.org/docs/#Axis) class used to display the text ([axisConfig](http://d3plus.org/docs/#ColorScale.axisConfig)) and the [Rect](http://d3plus.org/docs/#Rect) class used to draw the color breaks ([rectConfig](http://d3plus.org/docs/#ColorScale.rectConfig)). This method acts as a pass-through to the config method of the [Axis](http://d3plus.org/docs/#Axis). An example usage of this method can be seen [here](http://d3plus.org/examples/d3plus-legend/colorScale-dark/).
|
|
830
|
+
@param {Object} [*value*]
|
|
831
|
+
@chainable
|
|
832
|
+
*/ key: "legendConfig",
|
|
833
|
+
value: function legendConfig(_) {
|
|
834
|
+
return arguments.length ? (this._legendConfig = assign(this._legendConfig, _), this) : this._legendConfig;
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
/**
|
|
839
|
+
@memberof ColorScale
|
|
840
|
+
@desc The number value to be used as the anchor for `colorMid`, and defines the center point of the diverging color scale.
|
|
841
|
+
@param {Number} [*value* = 0]
|
|
842
|
+
@chainable
|
|
843
|
+
*/ key: "midpoint",
|
|
844
|
+
value: function midpoint(_) {
|
|
845
|
+
return arguments.length ? (this._midpoint = _, this) : this._midpoint;
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
/**
|
|
850
|
+
@memberof ColorScale
|
|
851
|
+
@desc Sets the flow of the items inside the ColorScale. If no value is passed, the current flow will be returned.
|
|
852
|
+
@param {String} [*value* = "bottom"]
|
|
853
|
+
@chainable
|
|
854
|
+
*/ key: "orient",
|
|
855
|
+
value: function orient(_) {
|
|
856
|
+
return arguments.length ? (this._orient = _, this) : this._orient;
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
/**
|
|
861
|
+
@memberof ColorScale
|
|
862
|
+
@desc If called after the elements have been drawn to DOM, will returns the outer bounds of the ColorScale content.
|
|
863
|
+
@example
|
|
864
|
+
{"width": 180, "height": 24, "x": 10, "y": 20}
|
|
865
|
+
*/ key: "outerBounds",
|
|
866
|
+
value: function outerBounds() {
|
|
867
|
+
return this._outerBounds;
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
/**
|
|
872
|
+
@memberof ColorScale
|
|
873
|
+
@desc If *value* is specified, sets the padding between each key to the specified number and returns the current class instance. If *value* is not specified, returns the current padding value.
|
|
874
|
+
@param {Number} [*value* = 10]
|
|
875
|
+
@chainable
|
|
876
|
+
*/ key: "padding",
|
|
877
|
+
value: function padding(_) {
|
|
878
|
+
return arguments.length ? (this._padding = _, this) : this._padding;
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
/**
|
|
883
|
+
@memberof ColorScale
|
|
884
|
+
@desc The [ColorScale](http://d3plus.org/docs/#ColorScale) is constructed by combining an [Axis](http://d3plus.org/docs/#Axis) for the ticks/labels and a [Rect](http://d3plus.org/docs/#Rect) for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the [Axis](http://d3plus.org/docs/#Axis) class used to display the text ([axisConfig](http://d3plus.org/docs/#ColorScale.axisConfig)) and the [Rect](http://d3plus.org/docs/#Rect) class used to draw the color breaks ([rectConfig](http://d3plus.org/docs/#ColorScale.rectConfig)). This method acts as a pass-through to the config method of the [Rect](http://d3plus.org/docs/#Rect). An example usage of this method can be seen [here](http://d3plus.org/examples/d3plus-legend/colorScale-dark/).
|
|
885
|
+
@param {Object} [*value*]
|
|
886
|
+
@chainable
|
|
887
|
+
*/ key: "rectConfig",
|
|
888
|
+
value: function rectConfig(_) {
|
|
889
|
+
return arguments.length ? (this._rectConfig = assign(this._rectConfig, _), this) : this._rectConfig;
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
/**
|
|
894
|
+
@memberof ColorScale
|
|
895
|
+
@desc If *value* is specified, sets the scale of the ColorScale and returns the current class instance. If *value* is not specified, returns the current scale value.
|
|
896
|
+
@param {String} [*value* = "linear"] Can either be "linear", "jenks", or "buckets".
|
|
897
|
+
@chainable
|
|
898
|
+
*/ key: "scale",
|
|
899
|
+
value: function scale(_) {
|
|
900
|
+
return arguments.length ? (this._scale = _, this) : this._scale;
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
/**
|
|
905
|
+
@memberof ColorScale
|
|
906
|
+
@desc If *selector* is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If *selector* is not specified, returns the current SVG container element.
|
|
907
|
+
@param {String|HTMLElement} [*selector* = d3.select("body").append("svg")]
|
|
908
|
+
@chainable
|
|
909
|
+
*/ key: "select",
|
|
910
|
+
value: function select1(_) {
|
|
911
|
+
return arguments.length ? (this._select = select(_), this) : this._select;
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
{
|
|
915
|
+
/**
|
|
916
|
+
@memberof ColorScale
|
|
917
|
+
@desc The height of horizontal color scales, and width when positioned vertical.
|
|
918
|
+
@param {Number} [*value* = 10]
|
|
919
|
+
@chainable
|
|
920
|
+
*/ key: "size",
|
|
921
|
+
value: function size(_) {
|
|
922
|
+
return arguments.length ? (this._size = _, this) : this._size;
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
/**
|
|
927
|
+
@memberof ColorScale
|
|
928
|
+
@desc If *value* is specified, sets the value accessor to the specified function or string and returns the current class instance. If *value* is not specified, returns the current value accessor.
|
|
929
|
+
@param {Function|String} [*value*]
|
|
930
|
+
@chainable
|
|
931
|
+
@example
|
|
932
|
+
function value(d) {
|
|
933
|
+
return d.value;
|
|
934
|
+
}
|
|
935
|
+
*/ key: "value",
|
|
936
|
+
value: function value(_) {
|
|
937
|
+
return arguments.length ? (this._value = typeof _ === "function" ? _ : constant(_), this) : this._value;
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
/**
|
|
942
|
+
@memberof ColorScale
|
|
943
|
+
@desc If *value* is specified, sets the overall width of the ColorScale and returns the current class instance. If *value* is not specified, returns the current width value.
|
|
944
|
+
@param {Number} [*value* = 400]
|
|
945
|
+
@chainable
|
|
946
|
+
*/ key: "width",
|
|
947
|
+
value: function width(_) {
|
|
948
|
+
return arguments.length ? (this._width = _, this) : this._width;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
]);
|
|
952
|
+
return ColorScale;
|
|
953
|
+
}(BaseClass);
|
|
954
|
+
/**
|
|
955
|
+
@class ColorScale
|
|
956
|
+
@extends BaseClass
|
|
957
|
+
@desc Creates an SVG scale based on an array of data. If *data* is specified, immediately draws based on the specified array and returns the current class instance. If *data* is not specified on instantiation, it can be passed/updated after instantiation using the [data](#shape.data) method.
|
|
958
|
+
*/ export { ColorScale as default };
|