@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,1567 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _assert_this_initialized(self) {
|
|
13
|
+
if (self === void 0) {
|
|
14
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
15
|
+
}
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
function _call_super(_this, derived, args) {
|
|
19
|
+
derived = _get_prototype_of(derived);
|
|
20
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
21
|
+
}
|
|
22
|
+
function _class_call_check(instance, Constructor) {
|
|
23
|
+
if (!(instance instanceof Constructor)) {
|
|
24
|
+
throw new TypeError("Cannot call a class as a function");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function _defineProperties(target, props) {
|
|
28
|
+
for(var i = 0; i < props.length; i++){
|
|
29
|
+
var descriptor = props[i];
|
|
30
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
31
|
+
descriptor.configurable = true;
|
|
32
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
33
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
37
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
38
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
39
|
+
return Constructor;
|
|
40
|
+
}
|
|
41
|
+
function _define_property(obj, key, value) {
|
|
42
|
+
if (key in obj) {
|
|
43
|
+
Object.defineProperty(obj, key, {
|
|
44
|
+
value: value,
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
obj[key] = value;
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
function _get_prototype_of(o) {
|
|
55
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
56
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
57
|
+
};
|
|
58
|
+
return _get_prototype_of(o);
|
|
59
|
+
}
|
|
60
|
+
function _inherits(subClass, superClass) {
|
|
61
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
62
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
63
|
+
}
|
|
64
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
65
|
+
constructor: {
|
|
66
|
+
value: subClass,
|
|
67
|
+
writable: true,
|
|
68
|
+
configurable: true
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
72
|
+
}
|
|
73
|
+
function _iterable_to_array(iter) {
|
|
74
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
75
|
+
}
|
|
76
|
+
function _iterable_to_array_limit(arr, i) {
|
|
77
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
78
|
+
if (_i == null) return;
|
|
79
|
+
var _arr = [];
|
|
80
|
+
var _n = true;
|
|
81
|
+
var _d = false;
|
|
82
|
+
var _s, _e;
|
|
83
|
+
try {
|
|
84
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
85
|
+
_arr.push(_s.value);
|
|
86
|
+
if (i && _arr.length === i) break;
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
_d = true;
|
|
90
|
+
_e = err;
|
|
91
|
+
} finally{
|
|
92
|
+
try {
|
|
93
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
94
|
+
} finally{
|
|
95
|
+
if (_d) throw _e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return _arr;
|
|
99
|
+
}
|
|
100
|
+
function _non_iterable_rest() {
|
|
101
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
102
|
+
}
|
|
103
|
+
function _non_iterable_spread() {
|
|
104
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
105
|
+
}
|
|
106
|
+
function _possible_constructor_return(self, call) {
|
|
107
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
108
|
+
return call;
|
|
109
|
+
}
|
|
110
|
+
return _assert_this_initialized(self);
|
|
111
|
+
}
|
|
112
|
+
function _set_prototype_of(o, p) {
|
|
113
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
114
|
+
o.__proto__ = p;
|
|
115
|
+
return o;
|
|
116
|
+
};
|
|
117
|
+
return _set_prototype_of(o, p);
|
|
118
|
+
}
|
|
119
|
+
function _sliced_to_array(arr, i) {
|
|
120
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
121
|
+
}
|
|
122
|
+
function _to_consumable_array(arr) {
|
|
123
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
124
|
+
}
|
|
125
|
+
function _type_of(obj) {
|
|
126
|
+
"@swc/helpers - typeof";
|
|
127
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
128
|
+
}
|
|
129
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
130
|
+
if (!o) return;
|
|
131
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
132
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
133
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
134
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
135
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
136
|
+
}
|
|
137
|
+
function _is_native_reflect_construct() {
|
|
138
|
+
try {
|
|
139
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
140
|
+
} catch (_) {}
|
|
141
|
+
return (_is_native_reflect_construct = function() {
|
|
142
|
+
return !!result;
|
|
143
|
+
})();
|
|
144
|
+
}
|
|
145
|
+
import { extent, max, min, range as d3Range, sum } from "d3-array";
|
|
146
|
+
import { timeFormat, timeFormatDefaultLocale } from "d3-time-format";
|
|
147
|
+
import * as scales from "d3-scale";
|
|
148
|
+
import { select } from "d3-selection";
|
|
149
|
+
import { transition } from "d3-transition";
|
|
150
|
+
import { colorDefaults } from "@d3plus/color";
|
|
151
|
+
import { assign, attrize, date, elem, rtl as detectRTL } from "@d3plus/dom";
|
|
152
|
+
import { formatAbbreviate, formatDate } from "@d3plus/format";
|
|
153
|
+
import { formatLocale, locale } from "@d3plus/locales";
|
|
154
|
+
import { closest } from "@d3plus/math";
|
|
155
|
+
import { textWrap } from "@d3plus/text";
|
|
156
|
+
import { TextBox } from "../components/index.js";
|
|
157
|
+
import * as shapes from "../shapes/index.js";
|
|
158
|
+
import { configPrep, BaseClass, constant } from "../utils/index.js";
|
|
159
|
+
/* catches for -0 and less */ var isNegative = function(d) {
|
|
160
|
+
return d < 0 || Object.is(d, -0);
|
|
161
|
+
};
|
|
162
|
+
var floorPow = function(d) {
|
|
163
|
+
return Math.pow(10, Math.floor(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d));
|
|
164
|
+
};
|
|
165
|
+
var ceilPow = function(d) {
|
|
166
|
+
return Math.pow(10, Math.ceil(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d));
|
|
167
|
+
};
|
|
168
|
+
var fixFloat = function(d) {
|
|
169
|
+
var str = "".concat(d);
|
|
170
|
+
if (str.includes("e-") || str === "0") return 0;
|
|
171
|
+
var nineMatch = str.match(/(-*[0-9]+\.[0]*)([0-8]+)9{3,}[0-9]+$/);
|
|
172
|
+
if (nineMatch) return +"".concat(nineMatch[1]).concat(+nineMatch[2] + 1);
|
|
173
|
+
var zeroMatch = str.match(/(-*[0-9]+\.[0]*)([1-9]+)0*[0-9]*0{3,}[0-9]+$/);
|
|
174
|
+
if (zeroMatch) return +"".concat(zeroMatch[1]).concat(+zeroMatch[2]);
|
|
175
|
+
return d;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Calculates ticks from a given scale (negative and/or positive)
|
|
179
|
+
* @param {scale} scale A d3-scale object
|
|
180
|
+
* @private
|
|
181
|
+
*/ function calculateStep(scale) {
|
|
182
|
+
var minorTicks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
183
|
+
var stepScale = scales.scaleLinear().domain([
|
|
184
|
+
200,
|
|
185
|
+
1200
|
|
186
|
+
]).range([
|
|
187
|
+
8,
|
|
188
|
+
28
|
|
189
|
+
]);
|
|
190
|
+
var scaleRange = scale.range();
|
|
191
|
+
var size = Math.abs(scaleRange[1] - scaleRange[0]);
|
|
192
|
+
var step = Math.floor(stepScale(size));
|
|
193
|
+
if (this._scale === "time") {
|
|
194
|
+
if (this._data && this._data.length) {
|
|
195
|
+
var dataExtent = extent(this._data);
|
|
196
|
+
var distance = this._data.reduce(function(n, d, i, arr) {
|
|
197
|
+
if (i) {
|
|
198
|
+
var dist = Math.abs(d - arr[i - 1]);
|
|
199
|
+
if (dist < n) n = dist;
|
|
200
|
+
}
|
|
201
|
+
return n;
|
|
202
|
+
}, Infinity);
|
|
203
|
+
var newStep = Math.round((dataExtent[1] - dataExtent[0]) / distance);
|
|
204
|
+
step = min([
|
|
205
|
+
step * (minorTicks ? 2 : 0.5),
|
|
206
|
+
newStep
|
|
207
|
+
]);
|
|
208
|
+
} else {
|
|
209
|
+
step = minorTicks ? step * 2 : step / 2;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return Math.floor(step);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Calculates ticks from a given scale (negative and/or positive)
|
|
216
|
+
* @param {scale} scale A d3-scale object
|
|
217
|
+
* @private
|
|
218
|
+
*/ function calculateTicks(scale) {
|
|
219
|
+
var minorTicks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
220
|
+
var ticks = [];
|
|
221
|
+
var step = calculateStep.bind(this)(scale, minorTicks);
|
|
222
|
+
var domain = scale.domain();
|
|
223
|
+
var inverted = domain[1] < domain[0];
|
|
224
|
+
if (!minorTicks && this._scale === "log") {
|
|
225
|
+
var roundDomain = domain.map(function(d) {
|
|
226
|
+
return Math.log10(d) % 1 === 0 ? d : (inverted ? ceilPow : floorPow)(d);
|
|
227
|
+
});
|
|
228
|
+
var invertedRound = roundDomain[1] < roundDomain[0];
|
|
229
|
+
var powers = roundDomain.map(function(d) {
|
|
230
|
+
return (isNegative(d) ? -1 : 1) * ([
|
|
231
|
+
-1,
|
|
232
|
+
1
|
|
233
|
+
].includes(d) || Math.abs(d) < 1 ? 1 : Math.log10(Math.abs(d)));
|
|
234
|
+
});
|
|
235
|
+
var powMod = Math.ceil((Math.abs(powers[1] - powers[0]) + 1) / (step * 0.65));
|
|
236
|
+
ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scale.ticks(step).filter(function(d) {
|
|
237
|
+
return +"".concat(d).replace("0.", "") % 2 === 0;
|
|
238
|
+
}) : d3Range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
|
|
239
|
+
powers[1]
|
|
240
|
+
]).filter(function(d) {
|
|
241
|
+
return Math.abs(d) % powMod === 0;
|
|
242
|
+
}).map(function(d) {
|
|
243
|
+
return +"".concat((isNegative(d) ? -1 : 1) * (d ? Math.pow(10, Math.abs(d)) : Math.sign(1 / d) > 0 ? 1 : -1)).replace(/9+/g, "1");
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
ticks = scale.ticks(step);
|
|
247
|
+
if (!minorTicks && ![
|
|
248
|
+
"log",
|
|
249
|
+
"time"
|
|
250
|
+
].includes(this._scale) && ticks.length > 1) {
|
|
251
|
+
var majorDiff = Math.abs(fixFloat(ticks[1] - ticks[0]) * 2);
|
|
252
|
+
ticks = ticks.filter(function(d) {
|
|
253
|
+
var mod = Math.abs(d) % majorDiff;
|
|
254
|
+
var modFloat = fixFloat(mod);
|
|
255
|
+
if (modFloat !== mod) {
|
|
256
|
+
return !modFloat || modFloat === majorDiff;
|
|
257
|
+
}
|
|
258
|
+
return mod === 0;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// forces min/max into ticks, if not present
|
|
263
|
+
if (!this._d3ScaleNegative || isNegative(domain[inverted ? 1 : 0]) === ticks.some(function(d) {
|
|
264
|
+
return isNegative(d);
|
|
265
|
+
})) {
|
|
266
|
+
if (!ticks.map(Number).includes(+domain[0])) {
|
|
267
|
+
ticks.unshift(domain[0]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (!this._d3ScaleNegative || isNegative(domain[inverted ? 0 : 1]) === ticks.some(function(d) {
|
|
271
|
+
return isNegative(d);
|
|
272
|
+
})) {
|
|
273
|
+
if (!ticks.map(Number).includes(+domain[1])) {
|
|
274
|
+
ticks.push(domain[1]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// for time scale, if data array has been provided, filter out ticks that are not in the array
|
|
278
|
+
if (this._scale === "time" && this._data.length) {
|
|
279
|
+
var dataNumbers = this._data.map(Number);
|
|
280
|
+
ticks = ticks.filter(function(t) {
|
|
281
|
+
return dataNumbers.includes(+t);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return ticks;
|
|
285
|
+
}
|
|
286
|
+
var Axis = /*#__PURE__*/ function(BaseClass) {
|
|
287
|
+
"use strict";
|
|
288
|
+
_inherits(Axis, BaseClass);
|
|
289
|
+
function Axis() {
|
|
290
|
+
_class_call_check(this, Axis);
|
|
291
|
+
var _this;
|
|
292
|
+
_this = _call_super(this, Axis);
|
|
293
|
+
_this._align = "middle";
|
|
294
|
+
_this._barConfig = {
|
|
295
|
+
"stroke": "#999",
|
|
296
|
+
"stroke-width": 1
|
|
297
|
+
};
|
|
298
|
+
_this._data = [];
|
|
299
|
+
_this._domain = [
|
|
300
|
+
0,
|
|
301
|
+
10
|
|
302
|
+
];
|
|
303
|
+
_this._duration = 600;
|
|
304
|
+
_this._gridConfig = {
|
|
305
|
+
"stroke": "#eee",
|
|
306
|
+
"stroke-width": 1
|
|
307
|
+
};
|
|
308
|
+
_this._gridLog = false;
|
|
309
|
+
_this._height = 400;
|
|
310
|
+
_this._labelOffset = false;
|
|
311
|
+
_this._labelRotation = false;
|
|
312
|
+
_this.orient("bottom");
|
|
313
|
+
_this._outerBounds = {
|
|
314
|
+
width: 0,
|
|
315
|
+
height: 0,
|
|
316
|
+
x: 0,
|
|
317
|
+
y: 0
|
|
318
|
+
};
|
|
319
|
+
_this._padding = 5;
|
|
320
|
+
_this._paddingInner = 0.1;
|
|
321
|
+
_this._paddingOuter = 0.1;
|
|
322
|
+
_this._rounding = "none";
|
|
323
|
+
_this._roundingInsideMinPrefix = "< ";
|
|
324
|
+
_this._roundingInsideMinSuffix = "";
|
|
325
|
+
_this._roundingInsideMaxPrefix = "";
|
|
326
|
+
_this._roundingInsideMaxSuffix = "+";
|
|
327
|
+
_this._scale = "linear";
|
|
328
|
+
_this._scalePadding = 0.5;
|
|
329
|
+
_this._shape = "Line";
|
|
330
|
+
_this._shapeConfig = {
|
|
331
|
+
fill: "#999",
|
|
332
|
+
height: function(d) {
|
|
333
|
+
return d.tick ? 8 : 0;
|
|
334
|
+
},
|
|
335
|
+
label: function(d) {
|
|
336
|
+
return d.text;
|
|
337
|
+
},
|
|
338
|
+
labelBounds: function(d) {
|
|
339
|
+
return d.labelBounds;
|
|
340
|
+
},
|
|
341
|
+
labelConfig: {
|
|
342
|
+
fontColor: "#999",
|
|
343
|
+
fontResize: false,
|
|
344
|
+
fontSize: constant(12),
|
|
345
|
+
padding: 5,
|
|
346
|
+
textAnchor: function() {
|
|
347
|
+
var rtl = detectRTL(_this._select.node());
|
|
348
|
+
return _this._orient === "left" ? rtl ? "start" : "end" : _this._orient === "right" ? rtl ? "end" : "start" : _this._labelRotation ? _this._orient === "bottom" ? "end" : "start" : "middle";
|
|
349
|
+
},
|
|
350
|
+
verticalAlign: function() {
|
|
351
|
+
return _this._orient === "bottom" ? "top" : _this._orient === "top" ? "bottom" : "middle";
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
r: function(d) {
|
|
355
|
+
return d.tick ? 4 : 0;
|
|
356
|
+
},
|
|
357
|
+
stroke: "#999",
|
|
358
|
+
strokeWidth: 1,
|
|
359
|
+
width: function(d) {
|
|
360
|
+
return d.tick ? 8 : 0;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
_this._tickSize = 8;
|
|
364
|
+
_this._tickSuffix = "normal";
|
|
365
|
+
_this._tickUnit = 0;
|
|
366
|
+
_this._timeLocale = undefined;
|
|
367
|
+
_this._titleClass = new TextBox();
|
|
368
|
+
_this._titleConfig = {
|
|
369
|
+
fontColor: colorDefaults.dark,
|
|
370
|
+
fontSize: 12,
|
|
371
|
+
textAnchor: "middle"
|
|
372
|
+
};
|
|
373
|
+
_this._width = 400;
|
|
374
|
+
return _this;
|
|
375
|
+
}
|
|
376
|
+
_create_class(Axis, [
|
|
377
|
+
{
|
|
378
|
+
/**
|
|
379
|
+
@memberof Axis
|
|
380
|
+
@desc Sets positioning for the axis bar.
|
|
381
|
+
@param {D3Selection} *bar*
|
|
382
|
+
@private
|
|
383
|
+
*/ key: "_barPosition",
|
|
384
|
+
value: function _barPosition(bar) {
|
|
385
|
+
var _this__position = this._position, height = _this__position.height, x = _this__position.x, y = _this__position.y, opposite = _this__position.opposite, offset = this._margin[opposite], position = [
|
|
386
|
+
"top",
|
|
387
|
+
"left"
|
|
388
|
+
].includes(this._orient) ? this._outerBounds[y] + this._outerBounds[height] - offset : this._outerBounds[y] + offset;
|
|
389
|
+
var x1mod = this._scale === "band" ? this._d3Scale.step() - this._d3Scale.bandwidth() : this._scale === "point" ? this._d3Scale.step() * this._d3Scale.padding() : 0;
|
|
390
|
+
var x2mod = this._scale === "band" ? this._d3Scale.step() : this._scale === "point" ? this._d3Scale.step() * this._d3Scale.padding() : 0;
|
|
391
|
+
var sortedDomain = (this._d3ScaleNegative ? this._d3ScaleNegative.domain() : []).concat(this._d3Scale ? this._d3Scale.domain() : []).sort(function(a, b) {
|
|
392
|
+
return a - b;
|
|
393
|
+
});
|
|
394
|
+
bar.call(attrize, this._barConfig).attr("".concat(x, "1"), this._getPosition(sortedDomain[0]) - x1mod).attr("".concat(x, "2"), this._getPosition(sortedDomain[sortedDomain.length - 1]) + x2mod).attr("".concat(y, "1"), position).attr("".concat(y, "2"), position);
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
/**
|
|
399
|
+
@memberof Axis
|
|
400
|
+
@desc Returns the scale's domain, taking into account negative and positive log scales.
|
|
401
|
+
@private
|
|
402
|
+
*/ key: "_getDomain",
|
|
403
|
+
value: function _getDomain() {
|
|
404
|
+
var ticks = [];
|
|
405
|
+
if (this._d3ScaleNegative) ticks = this._d3ScaleNegative.domain();
|
|
406
|
+
if (this._d3Scale) ticks = ticks.concat(this._d3Scale.domain());
|
|
407
|
+
var domain = [
|
|
408
|
+
"band",
|
|
409
|
+
"ordinal",
|
|
410
|
+
"point"
|
|
411
|
+
].includes(this._scale) ? ticks : extent(ticks);
|
|
412
|
+
return ticks[0] > ticks[1] ? domain.reverse() : domain;
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
/**
|
|
417
|
+
@memberof Axis
|
|
418
|
+
@desc Returns a value's scale position, taking into account negative and positive log scales.
|
|
419
|
+
@param {Number|String} *d*
|
|
420
|
+
@private
|
|
421
|
+
*/ key: "_getPosition",
|
|
422
|
+
value: function _getPosition(d) {
|
|
423
|
+
if (this._scale === "log") {
|
|
424
|
+
if (d === 0) return (this._d3Scale || this._d3ScaleNegative).range()[this._d3Scale ? 0 : 1];
|
|
425
|
+
return (isNegative(d) ? this._d3ScaleNegative || function() {
|
|
426
|
+
return 0;
|
|
427
|
+
} : this._d3Scale)(d);
|
|
428
|
+
}
|
|
429
|
+
return this._d3Scale(d);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
/**
|
|
434
|
+
@memberof Axis
|
|
435
|
+
@desc Returns the scale's range, taking into account negative and positive log scales.
|
|
436
|
+
@private
|
|
437
|
+
*/ key: "_getRange",
|
|
438
|
+
value: function _getRange() {
|
|
439
|
+
var ticks = [];
|
|
440
|
+
if (this._d3ScaleNegative) ticks = this._d3ScaleNegative.range();
|
|
441
|
+
if (this._d3Scale) ticks = ticks.concat(this._d3Scale.range());
|
|
442
|
+
return ticks[0] > ticks[1] ? extent(ticks).reverse() : extent(ticks);
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
/**
|
|
447
|
+
@memberof Axis
|
|
448
|
+
@desc Returns the scale's labels, taking into account negative and positive log scales.
|
|
449
|
+
@private
|
|
450
|
+
*/ key: "_getLabels",
|
|
451
|
+
value: function _getLabels() {
|
|
452
|
+
var labels = [];
|
|
453
|
+
if (this._d3ScaleNegative) labels = labels.concat(calculateTicks.bind(this)(this._d3ScaleNegative, false));
|
|
454
|
+
if (this._d3Scale) labels = labels.concat(calculateTicks.bind(this)(this._d3Scale, false));
|
|
455
|
+
if (this._scale === "log") {
|
|
456
|
+
var diverging = labels.some(function(d) {
|
|
457
|
+
return isNegative(d);
|
|
458
|
+
}) && labels.some(function(d) {
|
|
459
|
+
return d > 0;
|
|
460
|
+
});
|
|
461
|
+
if (diverging) {
|
|
462
|
+
var minValue = min(_to_consumable_array(this._d3ScaleNegative.domain().map(Math.abs)).concat(_to_consumable_array(this._d3Scale.domain())));
|
|
463
|
+
// add minValue if it does not exist, and should
|
|
464
|
+
if (!labels.includes(minValue)) {
|
|
465
|
+
labels.splice(labels.findIndex(function(d) {
|
|
466
|
+
return d > minValue;
|
|
467
|
+
}), 0, minValue);
|
|
468
|
+
}
|
|
469
|
+
// remove -minValue if minValue also exists
|
|
470
|
+
if (labels.includes(-minValue) && labels.includes(minValue)) {
|
|
471
|
+
labels.splice(labels.indexOf(-minValue), 1);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return labels;
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
/**
|
|
480
|
+
@memberof Axis
|
|
481
|
+
@desc Returns the scale's ticks, taking into account negative and positive log scales.
|
|
482
|
+
@private
|
|
483
|
+
*/ key: "_getTicks",
|
|
484
|
+
value: function _getTicks() {
|
|
485
|
+
if ([
|
|
486
|
+
"band",
|
|
487
|
+
"ordinal",
|
|
488
|
+
"point",
|
|
489
|
+
"time"
|
|
490
|
+
].includes(this._scale) && this._data.length && this._data.length < this._width / 4) {
|
|
491
|
+
return this._scale === "time" ? this._data.map(date) : this._data;
|
|
492
|
+
}
|
|
493
|
+
var ticks = [];
|
|
494
|
+
if (this._d3ScaleNegative) ticks = ticks.concat(calculateTicks.bind(this)(this._d3ScaleNegative, true));
|
|
495
|
+
if (this._d3Scale) ticks = ticks.concat(calculateTicks.bind(this)(this._d3Scale, true));
|
|
496
|
+
if (this._scale === "log" && ticks.includes(-1) && ticks.includes(1)) ticks.splice(ticks.indexOf(-1), 1);
|
|
497
|
+
return ticks;
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
/**
|
|
502
|
+
@memberof Axis
|
|
503
|
+
@desc Sets positioning for the grid lines.
|
|
504
|
+
@param {D3Selection} *lines*
|
|
505
|
+
@private
|
|
506
|
+
*/ key: "_gridPosition",
|
|
507
|
+
value: function _gridPosition(lines) {
|
|
508
|
+
var last = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
509
|
+
var _this__position = this._position, height = _this__position.height, x = _this__position.x, y = _this__position.y, opposite = _this__position.opposite, offset = this._margin[opposite], position = [
|
|
510
|
+
"top",
|
|
511
|
+
"left"
|
|
512
|
+
].includes(this._orient) ? this._outerBounds[y] + this._outerBounds[height] - offset : this._outerBounds[y] + offset, scale = last ? this._lastScale || this._getPosition.bind(this) : this._getPosition.bind(this), size = [
|
|
513
|
+
"top",
|
|
514
|
+
"left"
|
|
515
|
+
].includes(this._orient) ? offset : -offset, xDiff = this._scale === "band" ? this._d3Scale.bandwidth() / 2 : 0, xPos = function(d) {
|
|
516
|
+
return scale(d.id) + xDiff;
|
|
517
|
+
};
|
|
518
|
+
lines.call(attrize, this._gridConfig).attr("".concat(x, "1"), xPos).attr("".concat(x, "2"), xPos).attr("".concat(y, "1"), position).attr("".concat(y, "2"), last ? position : position + size);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
/**
|
|
523
|
+
@memberof Axis
|
|
524
|
+
@desc Renders the current Axis to the page. If a *callback* is specified, it will be called once the legend is done drawing.
|
|
525
|
+
@param {Function} [*callback* = undefined]
|
|
526
|
+
@chainable
|
|
527
|
+
*/ key: "render",
|
|
528
|
+
value: function render(callback) {
|
|
529
|
+
var _this = this;
|
|
530
|
+
/**
|
|
531
|
+
* Creates an SVG element to contain the axis if none
|
|
532
|
+
* has been specified using the "select" method.
|
|
533
|
+
*/ if (this._select === void 0) {
|
|
534
|
+
this.select(select("body").append("svg").attr("width", "".concat(this._width, "px")).attr("height", "".concat(this._height, "px")).node());
|
|
535
|
+
}
|
|
536
|
+
var timeLocale = this._timeLocale || locale[this._locale] || locale["en-US"];
|
|
537
|
+
timeFormatDefaultLocale(timeLocale).format();
|
|
538
|
+
/**
|
|
539
|
+
* Declares some commonly used variables.
|
|
540
|
+
*/ var _this__position = this._position, width = _this__position.width, height = _this__position.height, x = _this__position.x, y = _this__position.y, horizontal = _this__position.horizontal, opposite = _this__position.opposite, clipId = "d3plus-Axis-clip-".concat(this._uuid), flip = [
|
|
541
|
+
"top",
|
|
542
|
+
"left"
|
|
543
|
+
].includes(this._orient), p = this._padding, parent = this._select, rangeOuter = [
|
|
544
|
+
p,
|
|
545
|
+
this["_".concat(width)] - p
|
|
546
|
+
], t = transition().duration(this._duration);
|
|
547
|
+
var tickValue = this._shape === "Circle" ? this._shapeConfig.r : this._shape === "Rect" ? this._shapeConfig[width] : this._shapeConfig.strokeWidth;
|
|
548
|
+
var tickGet = typeof tickValue !== "function" ? function() {
|
|
549
|
+
return tickValue;
|
|
550
|
+
} : tickValue;
|
|
551
|
+
/**
|
|
552
|
+
* Zeros out the margins for re-calculation.
|
|
553
|
+
*/ var margin = this._margin = {
|
|
554
|
+
top: 0,
|
|
555
|
+
right: 0,
|
|
556
|
+
bottom: 0,
|
|
557
|
+
left: 0
|
|
558
|
+
};
|
|
559
|
+
var labels, range, ticks;
|
|
560
|
+
/**
|
|
561
|
+
* Constructs the tick formatter function.
|
|
562
|
+
*/ var tickFormat = this._tickFormat ? this._tickFormat : function(d) {
|
|
563
|
+
if (isNaN(d) || [
|
|
564
|
+
"band",
|
|
565
|
+
"ordinal",
|
|
566
|
+
"point"
|
|
567
|
+
].includes(_this._scale)) {
|
|
568
|
+
return d;
|
|
569
|
+
} else if (_this._scale === "time") {
|
|
570
|
+
var refData = (_this._data.length ? _this._data : _this._domain).map(date).sort(function(a, b) {
|
|
571
|
+
return +a - +b;
|
|
572
|
+
});
|
|
573
|
+
return formatDate(d, refData, timeFormat).replace(/^Q/g, timeLocale.quarter);
|
|
574
|
+
} else if (_this._scale === "linear" && _this._tickSuffix === "smallest") {
|
|
575
|
+
var _$locale = _type_of(_this._locale) === "object" ? _this._locale : formatLocale[_this._locale];
|
|
576
|
+
var separator = _$locale.separator, suffixes = _$locale.suffixes;
|
|
577
|
+
var suff = d >= 1000 ? suffixes[_this._tickUnit + 8] : "";
|
|
578
|
+
var tick = d / Math.pow(10, 3 * _this._tickUnit);
|
|
579
|
+
var number = formatAbbreviate(tick, _$locale, ",.".concat(tick.toString().length, "r"));
|
|
580
|
+
return "".concat(number).concat(separator).concat(suff);
|
|
581
|
+
} else {
|
|
582
|
+
var inverted = ticks[1] < ticks[0];
|
|
583
|
+
var minTick = inverted ? ticks.length - 1 : 0;
|
|
584
|
+
var maxTick = inverted ? 0 : ticks.length - 1;
|
|
585
|
+
var prefix = _this._rounding === "inside" ? ticks.indexOf(d) === minTick ? _this._roundingInsideMinPrefix : ticks.indexOf(d) === maxTick ? _this._roundingInsideMaxPrefix : "" : "";
|
|
586
|
+
var suffix = _this._rounding === "inside" ? ticks.indexOf(d) === minTick ? _this._roundingInsideMinSuffix : ticks.indexOf(d) === maxTick ? _this._roundingInsideMaxSuffix : "" : "";
|
|
587
|
+
return "".concat(prefix).concat(formatAbbreviate(d, _this._locale)).concat(suffix);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* (Re)calculates the internal d3 scale
|
|
592
|
+
* @param {} newRange
|
|
593
|
+
*/ function setScale() {
|
|
594
|
+
var _this = this;
|
|
595
|
+
var newRange = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this._range;
|
|
596
|
+
/**
|
|
597
|
+
* Calculates the internal "range" array to use, including
|
|
598
|
+
* fallbacks if not specified with the "range" method.
|
|
599
|
+
*/ range = newRange ? newRange.slice() : [
|
|
600
|
+
undefined,
|
|
601
|
+
undefined
|
|
602
|
+
];
|
|
603
|
+
var _rangeOuter = _sliced_to_array(rangeOuter, 2), minRange = _rangeOuter[0], maxRange = _rangeOuter[1];
|
|
604
|
+
if (this._range) {
|
|
605
|
+
if (this._range[0] !== undefined) minRange = this._range[0];
|
|
606
|
+
if (this._range[this._range.length - 1] !== undefined) maxRange = this._range[this._range.length - 1];
|
|
607
|
+
}
|
|
608
|
+
if (range[0] === undefined || range[0] < minRange) range[0] = minRange;
|
|
609
|
+
if (range[1] === undefined || range[1] > maxRange) range[1] = maxRange;
|
|
610
|
+
var sizeInner = maxRange - minRange;
|
|
611
|
+
if (this._scale === "ordinal" && this._domain.length > range.length) {
|
|
612
|
+
if (newRange === this._range) {
|
|
613
|
+
var buckets = this._domain.length + 1;
|
|
614
|
+
range = d3Range(buckets).map(function(d) {
|
|
615
|
+
return range[0] + sizeInner * (d / (buckets - 1));
|
|
616
|
+
}).slice(1, buckets);
|
|
617
|
+
range = range.map(function(d) {
|
|
618
|
+
return d - range[0] / 2;
|
|
619
|
+
});
|
|
620
|
+
} else {
|
|
621
|
+
var buckets1 = this._domain.length;
|
|
622
|
+
var size = range[1] - range[0];
|
|
623
|
+
range = d3Range(buckets1).map(function(d) {
|
|
624
|
+
return range[0] + size * (d / (buckets1 - 1));
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
// else if (newRange === this._range) {
|
|
629
|
+
// const tickScale = scales.scaleSqrt().domain([10, 400]).range([10, 50]);
|
|
630
|
+
// const domain = this._scale === "time" ? this._domain.map(date) : this._domain;
|
|
631
|
+
// const scaleTicks = d3Ticks(domain[0], domain[1], Math.floor(sizeInner / tickScale(sizeInner)));
|
|
632
|
+
// // labels = (this._labels
|
|
633
|
+
// // ? this._scale === "time" ? this._labels.map(date) : this._labels
|
|
634
|
+
// // : scaleTicks).slice();
|
|
635
|
+
// // const buckets = labels.length;
|
|
636
|
+
// // if (buckets) {
|
|
637
|
+
// // const pad = Math.ceil(sizeInner / buckets / 2);
|
|
638
|
+
// // range = [range[0] + pad, range[1] - pad];
|
|
639
|
+
// // }
|
|
640
|
+
// }
|
|
641
|
+
/**
|
|
642
|
+
* Sets up the initial d3 scale, using this._domain and the
|
|
643
|
+
* previously defined range variable.
|
|
644
|
+
*/ var scale = "scale".concat(this._scale.charAt(0).toUpperCase()).concat(this._scale.slice(1));
|
|
645
|
+
var initialDomain = this._domain.slice();
|
|
646
|
+
this._d3Scale = scales[scale]().domain(this._scale === "time" ? initialDomain.map(date) : initialDomain).range(range);
|
|
647
|
+
if (this._rounding !== "none") {
|
|
648
|
+
var roundDomain = function() {
|
|
649
|
+
var zeroLength = function(d) {
|
|
650
|
+
if (smallScale) {
|
|
651
|
+
if (!d) return 0;
|
|
652
|
+
var m = "".concat(d).match(/0\.(0*)/);
|
|
653
|
+
if (m) return +"0.".concat(Array(m[1].length + 1).fill(0).join(""), "1");
|
|
654
|
+
}
|
|
655
|
+
return "".concat(Math.round(Math.abs(d))).length;
|
|
656
|
+
};
|
|
657
|
+
var smallScale = initialDomain.every(function(d) {
|
|
658
|
+
return Math.abs(d) < 1;
|
|
659
|
+
});
|
|
660
|
+
var zeroArray = [
|
|
661
|
+
zeroLength(initialDomain[0]),
|
|
662
|
+
zeroLength(initialDomain[1])
|
|
663
|
+
].filter(Boolean).sort();
|
|
664
|
+
var diverging = initialDomain.some(function(d) {
|
|
665
|
+
return isNegative(d);
|
|
666
|
+
}) && initialDomain.some(function(d) {
|
|
667
|
+
return d > 0;
|
|
668
|
+
});
|
|
669
|
+
var zeros = zeroArray.length === 1 ? zeroArray[0] : zeroArray[0] > 1 && zeroArray[0] === zeroArray[1] ? zeroArray[0] - 1 : _this._rounding === "outside" || !diverging ? zeroArray[0] + (zeroArray[1] - zeroArray[0]) / 2 : max(zeroArray);
|
|
670
|
+
var factor = zeros < 1 ? fixFloat(zeros) : +"1".concat(Array(Math.floor(fixFloat(zeros)) - 1).fill(0).join(""));
|
|
671
|
+
if (factor >= Math.abs(initialDomain[1] - initialDomain[0])) factor /= 2;
|
|
672
|
+
var inverted = initialDomain[1] < initialDomain[0];
|
|
673
|
+
var newDomain = [
|
|
674
|
+
Math[_this._rounding === "outside" ? inverted ? "ceil" : "floor" : inverted ? "floor" : "ceil"](initialDomain[0] / factor) * factor,
|
|
675
|
+
Math[_this._rounding === "outside" ? inverted ? "floor" : "ceil" : inverted ? "ceil" : "floor"](initialDomain[1] / factor) * factor
|
|
676
|
+
];
|
|
677
|
+
if (_this._scale === "log") {
|
|
678
|
+
if (newDomain[0] === 0) newDomain[0] = initialDomain[0];
|
|
679
|
+
if (newDomain[1] === 0) newDomain[1] = initialDomain[1];
|
|
680
|
+
}
|
|
681
|
+
_this._d3Scale.domain(newDomain.map(fixFloat));
|
|
682
|
+
};
|
|
683
|
+
if (this._scale === "linear") {
|
|
684
|
+
roundDomain.bind(this)();
|
|
685
|
+
} else if (this._scale === "log") {
|
|
686
|
+
var powDomain = [];
|
|
687
|
+
var inverted = initialDomain[1] < initialDomain[0];
|
|
688
|
+
powDomain[0] = (this._rounding === "outside" ? isNegative(initialDomain[0]) ? inverted ? floorPow : ceilPow : inverted ? ceilPow : floorPow : isNegative(initialDomain[0]) ? inverted ? ceilPow : floorPow : inverted ? floorPow : ceilPow)(initialDomain[0]);
|
|
689
|
+
powDomain[1] = (this._rounding === "inside" ? isNegative(initialDomain[1]) ? inverted ? floorPow : ceilPow : inverted ? ceilPow : floorPow : isNegative(initialDomain[1]) ? inverted ? ceilPow : floorPow : inverted ? floorPow : ceilPow)(initialDomain[1]);
|
|
690
|
+
var powInverted = powDomain[1] < powDomain[0];
|
|
691
|
+
if (powDomain[0] !== powDomain[1] && powDomain.some(function(d) {
|
|
692
|
+
return Math.abs(d) > 10;
|
|
693
|
+
}) && powInverted === inverted) {
|
|
694
|
+
this._d3Scale.domain(powDomain);
|
|
695
|
+
} else {
|
|
696
|
+
roundDomain.bind(this)();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (this._d3Scale.padding) this._d3Scale.padding(this._scalePadding);
|
|
701
|
+
if (this._d3Scale.paddingInner) this._d3Scale.paddingInner(this._paddingInner);
|
|
702
|
+
if (this._d3Scale.paddingOuter) this._d3Scale.paddingOuter(this._paddingOuter);
|
|
703
|
+
/**
|
|
704
|
+
* Constructs a separate "negative only" scale for logarithmic
|
|
705
|
+
* domains, as they cannot pass zero.
|
|
706
|
+
*/ this._d3ScaleNegative = null;
|
|
707
|
+
if (this._scale === "log") {
|
|
708
|
+
var domain = this._d3Scale.domain();
|
|
709
|
+
if (domain[0] === 0) {
|
|
710
|
+
var smallestNumber = min([
|
|
711
|
+
min(this._data),
|
|
712
|
+
Math.abs(domain[1])
|
|
713
|
+
]);
|
|
714
|
+
domain[0] = smallestNumber === 0 || smallestNumber === 1 ? 1e-6 : smallestNumber <= 1 ? floorPow(smallestNumber) : 1;
|
|
715
|
+
if (isNegative(domain[1])) domain[0] *= -1;
|
|
716
|
+
} else if (domain[domain.length - 1] === 0) {
|
|
717
|
+
var smallestNumber1 = min([
|
|
718
|
+
min(this._data),
|
|
719
|
+
Math.abs(domain[0])
|
|
720
|
+
]);
|
|
721
|
+
domain[domain.length - 1] = smallestNumber1 === 0 || smallestNumber1 === 1 ? 1e-6 : smallestNumber1 <= 1 ? floorPow(smallestNumber1) : 1;
|
|
722
|
+
if (isNegative(domain[0])) domain[domain.length - 1] *= -1;
|
|
723
|
+
}
|
|
724
|
+
var range1 = this._d3Scale.range();
|
|
725
|
+
// all negatives
|
|
726
|
+
if (isNegative(domain[0]) && isNegative(domain[domain.length - 1])) {
|
|
727
|
+
this._d3ScaleNegative = this._d3Scale.copy().domain(domain).range(range1);
|
|
728
|
+
this._d3Scale = null;
|
|
729
|
+
} else if (domain[0] > 0 && domain[domain.length - 1] > 0) {
|
|
730
|
+
this._d3Scale.domain(domain).range(range1);
|
|
731
|
+
} else {
|
|
732
|
+
var powers = domain.map(function(d) {
|
|
733
|
+
return Math.log10(Math.abs(d));
|
|
734
|
+
}).map(function(d) {
|
|
735
|
+
return d || -1e-6;
|
|
736
|
+
});
|
|
737
|
+
var leftPercentage = powers[0] / sum(powers);
|
|
738
|
+
var zero = leftPercentage * (range1[1] - range1[0]);
|
|
739
|
+
var minPositive = min([
|
|
740
|
+
min(this._data.filter(function(d) {
|
|
741
|
+
return d >= 0;
|
|
742
|
+
})),
|
|
743
|
+
Math.abs(domain[1])
|
|
744
|
+
]);
|
|
745
|
+
if (minPositive === 1) minPositive = 1e-6;
|
|
746
|
+
var minNegative = min([
|
|
747
|
+
min(this._data.filter(isNegative)),
|
|
748
|
+
Math.abs(domain[0])
|
|
749
|
+
]);
|
|
750
|
+
if (minNegative === 1) minNegative = 1e-6;
|
|
751
|
+
var minPosPow = minPositive === 0 ? 1e-6 : minPositive <= 1 ? floorPow(minPositive) : 1;
|
|
752
|
+
var minNegPow = minNegative === 0 ? -1e-6 : minNegative <= 1 ? floorPow(minNegative) : 1;
|
|
753
|
+
var minValue = min([
|
|
754
|
+
Math.abs(minPosPow),
|
|
755
|
+
Math.abs(minNegPow)
|
|
756
|
+
]);
|
|
757
|
+
this._d3ScaleNegative = this._d3Scale.copy();
|
|
758
|
+
(isNegative(domain[0]) ? this._d3Scale : this._d3ScaleNegative).domain([
|
|
759
|
+
isNegative(domain[0]) ? minValue : -minValue,
|
|
760
|
+
domain[1]
|
|
761
|
+
]).range([
|
|
762
|
+
range1[0] + zero,
|
|
763
|
+
range1[1]
|
|
764
|
+
]);
|
|
765
|
+
(isNegative(domain[0]) ? this._d3ScaleNegative : this._d3Scale).domain([
|
|
766
|
+
domain[0],
|
|
767
|
+
isNegative(domain[0]) ? -minValue : minValue
|
|
768
|
+
]).range([
|
|
769
|
+
range1[0],
|
|
770
|
+
range1[0] + zero
|
|
771
|
+
]);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Determines the of values array to use
|
|
776
|
+
* for the "ticks" and the "labels"
|
|
777
|
+
*/ ticks = (this._ticks ? this._scale === "time" ? this._ticks.map(date) : this._ticks : (this._d3Scale ? this._d3Scale.ticks : this._d3ScaleNegative.ticks) ? this._getTicks() : this._domain).slice();
|
|
778
|
+
labels = (this._labels ? this._scale === "time" ? this._labels.map(date) : this._labels : (this._d3Scale ? this._d3Scale.ticks : this._d3ScaleNegative.ticks) ? this._getLabels() : ticks).slice();
|
|
779
|
+
if (this._scale === "time") {
|
|
780
|
+
ticks = ticks.map(Number);
|
|
781
|
+
labels = labels.map(Number);
|
|
782
|
+
}
|
|
783
|
+
ticks = ticks.sort(function(a, b) {
|
|
784
|
+
return _this._getPosition(a) - _this._getPosition(b);
|
|
785
|
+
});
|
|
786
|
+
labels = labels.sort(function(a, b) {
|
|
787
|
+
return _this._getPosition(a) - _this._getPosition(b);
|
|
788
|
+
});
|
|
789
|
+
/**
|
|
790
|
+
* Get the smallest suffix.
|
|
791
|
+
*/ if (this._scale === "linear" && this._tickSuffix === "smallest") {
|
|
792
|
+
var suffixes = labels.filter(function(d) {
|
|
793
|
+
return d >= 1000;
|
|
794
|
+
});
|
|
795
|
+
if (suffixes.length > 0) {
|
|
796
|
+
var _Math;
|
|
797
|
+
var _$min = (_Math = Math).min.apply(_Math, _to_consumable_array(suffixes));
|
|
798
|
+
var i = 1;
|
|
799
|
+
while(i && i < 7){
|
|
800
|
+
var n = Math.pow(10, 3 * i);
|
|
801
|
+
if (_$min / n >= 1) {
|
|
802
|
+
this._tickUnit = i;
|
|
803
|
+
i += 1;
|
|
804
|
+
} else {
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Removes ticks when they overlap other ticks.
|
|
812
|
+
*/ var pixels = [];
|
|
813
|
+
this._availableTicks = ticks;
|
|
814
|
+
ticks.forEach(function(d, i) {
|
|
815
|
+
var s = tickGet({
|
|
816
|
+
id: d,
|
|
817
|
+
tick: true
|
|
818
|
+
}, i);
|
|
819
|
+
if (_this._shape === "Circle") s *= 2;
|
|
820
|
+
var t = _this._getPosition(d);
|
|
821
|
+
if (!pixels.length || Math.abs(closest(t, pixels) - t) > s * 2) pixels.push(t);
|
|
822
|
+
else pixels.push(false);
|
|
823
|
+
});
|
|
824
|
+
ticks = ticks.filter(function(d, i) {
|
|
825
|
+
return pixels[i] !== false;
|
|
826
|
+
});
|
|
827
|
+
this._visibleTicks = ticks;
|
|
828
|
+
}
|
|
829
|
+
setScale.bind(this)();
|
|
830
|
+
/**
|
|
831
|
+
* Pre-calculates the size of the title, if defined, in order
|
|
832
|
+
* to adjust the internal margins.
|
|
833
|
+
*/ if (this._title) {
|
|
834
|
+
var _this__titleConfig = this._titleConfig, fontFamily = _this__titleConfig.fontFamily, fontSize = _this__titleConfig.fontSize, lineHeight = _this__titleConfig.lineHeight;
|
|
835
|
+
var titleWrap = textWrap().fontFamily(typeof fontFamily === "function" ? fontFamily() : fontFamily).fontSize(typeof fontSize === "function" ? fontSize() : fontSize).lineHeight(typeof lineHeight === "function" ? lineHeight() : lineHeight).width(range[range.length - 1] - range[0] - p * 2).height(this["_".concat(height)] - this._tickSize - p * 2);
|
|
836
|
+
var lines = titleWrap(this._title).lines.length;
|
|
837
|
+
margin[this._orient] = lines * titleWrap.lineHeight() + p;
|
|
838
|
+
}
|
|
839
|
+
var hBuff = this._shape === "Circle" ? typeof this._shapeConfig.r === "function" ? this._shapeConfig.r({
|
|
840
|
+
tick: true
|
|
841
|
+
}) : this._shapeConfig.r : this._shape === "Rect" ? typeof this._shapeConfig[height] === "function" ? this._shapeConfig[height]({
|
|
842
|
+
tick: true
|
|
843
|
+
}) : this._shapeConfig[height] : this._tickSize, wBuff = tickGet({
|
|
844
|
+
tick: true
|
|
845
|
+
});
|
|
846
|
+
if (typeof hBuff === "function") hBuff = max(ticks.map(hBuff));
|
|
847
|
+
if (this._shape === "Rect") hBuff /= 2;
|
|
848
|
+
if (typeof wBuff === "function") wBuff = max(ticks.map(wBuff));
|
|
849
|
+
if (this._shape !== "Circle") wBuff /= 2;
|
|
850
|
+
/**
|
|
851
|
+
* Calculates the text wrapping and size of a given textData object.
|
|
852
|
+
* @param {Object} datum
|
|
853
|
+
*/ function calculateLabelSize(datum) {
|
|
854
|
+
var d = datum.d, i = datum.i, fF = datum.fF, fP = datum.fP, fS = datum.fS, rotate = datum.rotate, space = datum.space;
|
|
855
|
+
var h = rotate ? "width" : "height", w = rotate ? "height" : "width";
|
|
856
|
+
var wSize = min([
|
|
857
|
+
this._maxSize,
|
|
858
|
+
this._width
|
|
859
|
+
]);
|
|
860
|
+
var hSize = min([
|
|
861
|
+
this._maxSize,
|
|
862
|
+
this._height
|
|
863
|
+
]);
|
|
864
|
+
var wrap = textWrap().fontFamily(fF).fontSize(fS).lineHeight(this._shapeConfig.lineHeight ? this._shapeConfig.lineHeight(d, i) : undefined);
|
|
865
|
+
wrap[w](horizontal ? space : wSize - hBuff - p - this._margin.left - this._margin.right);
|
|
866
|
+
wrap[h](horizontal ? hSize - hBuff - p - this._margin.top - this._margin.bottom : space);
|
|
867
|
+
var res = wrap(tickFormat(d));
|
|
868
|
+
res.lines = res.lines.filter(function(d) {
|
|
869
|
+
return d !== "";
|
|
870
|
+
});
|
|
871
|
+
res.width = res.lines.length ? Math.ceil(max(res.widths)) : 0;
|
|
872
|
+
res.height = res.lines.length ? Math.ceil(res.lines.length * wrap.lineHeight()) + fP : 0;
|
|
873
|
+
return res;
|
|
874
|
+
}
|
|
875
|
+
/** Calculates label offsets */ function calculateOffset() {
|
|
876
|
+
var arr = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
877
|
+
var offset = 0;
|
|
878
|
+
arr.forEach(function(datum) {
|
|
879
|
+
var prev = arr[datum.i - 1];
|
|
880
|
+
var h = datum.rotate && horizontal || !datum.rotate && !horizontal ? "width" : "height", w = datum.rotate && horizontal || !datum.rotate && !horizontal ? "height" : "width";
|
|
881
|
+
if (!prev) {
|
|
882
|
+
offset = 1;
|
|
883
|
+
} else if (prev.position + prev[w] / 2 > datum.position - datum[w] / 2) {
|
|
884
|
+
if (offset) {
|
|
885
|
+
datum.offset = prev[h];
|
|
886
|
+
offset = 0;
|
|
887
|
+
} else offset = 1;
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
var textData = [];
|
|
892
|
+
function createTextData() {
|
|
893
|
+
var _this = this;
|
|
894
|
+
var offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1;
|
|
895
|
+
var _this__shapeConfig_labelConfig = this._shapeConfig.labelConfig, fontFamily = _this__shapeConfig_labelConfig.fontFamily, fontSize = _this__shapeConfig_labelConfig.fontSize;
|
|
896
|
+
var fontPadding = this._shapeConfig.labelConfig.padding;
|
|
897
|
+
/**
|
|
898
|
+
* Calculates the space each label would take up, given
|
|
899
|
+
* the provided this._space size.
|
|
900
|
+
*/ textData = labels.map(function(d, i) {
|
|
901
|
+
var fF = typeof fontFamily === "function" ? fontFamily(d, i) : fontFamily, fP = typeof fontPadding === "function" ? fontPadding(d, i) : fontPadding, fS = typeof fontSize === "function" ? fontSize(d, i) : fontSize, position = _this._getPosition(d);
|
|
902
|
+
var lineHeight = _this._shapeConfig.lineHeight ? _this._shapeConfig.lineHeight(d, i) : fS * 1.4;
|
|
903
|
+
var datum = {
|
|
904
|
+
d: d,
|
|
905
|
+
i: i,
|
|
906
|
+
fF: fF,
|
|
907
|
+
fP: fP,
|
|
908
|
+
fS: fS,
|
|
909
|
+
lineHeight: lineHeight,
|
|
910
|
+
position: position,
|
|
911
|
+
rotate: _this._labelRotation
|
|
912
|
+
};
|
|
913
|
+
return datum;
|
|
914
|
+
});
|
|
915
|
+
var maxSpace = this._scale === "band" ? this._d3Scale.bandwidth() : textData.reduce(function(s, d, i) {
|
|
916
|
+
var position = d.position;
|
|
917
|
+
var prevPosition = !i ? textData.length === 1 ? rangeOuter[0] : position - (textData[i + 1].position - position) : position - (position - textData[i - 1].position);
|
|
918
|
+
var prevSpace = Math.abs(position - prevPosition);
|
|
919
|
+
var nextPosition = i == textData.length - 1 ? textData.length === 1 ? rangeOuter[1] : position + (position - textData[i - 1].position) : position - (position - textData[i + 1].position);
|
|
920
|
+
var nextSpace = Math.abs(position - nextPosition);
|
|
921
|
+
var mod = _this._scale === "point" ? 1 : 2;
|
|
922
|
+
return max([
|
|
923
|
+
max([
|
|
924
|
+
prevSpace,
|
|
925
|
+
nextSpace
|
|
926
|
+
]) * mod,
|
|
927
|
+
s
|
|
928
|
+
]);
|
|
929
|
+
}, 0);
|
|
930
|
+
textData = textData.map(function(datum) {
|
|
931
|
+
datum.space = maxSpace - datum.fP * 2;
|
|
932
|
+
var res = calculateLabelSize.bind(_this)(datum);
|
|
933
|
+
return Object.assign(res, datum);
|
|
934
|
+
});
|
|
935
|
+
var reverseTextData = textData.slice().reverse();
|
|
936
|
+
textData.forEach(function(datum) {
|
|
937
|
+
var fP = datum.fP, i = datum.i, position = datum.position;
|
|
938
|
+
var sizeName = horizontal ? "width" : "height";
|
|
939
|
+
var prev = i ? reverseTextData.find(function(t) {
|
|
940
|
+
return t.i < i && !t.truncated;
|
|
941
|
+
}) : false;
|
|
942
|
+
if (i === textData.length - 1) {
|
|
943
|
+
while(prev && position - datum[sizeName] / 2 - fP < prev.position + prev[sizeName] / 2){
|
|
944
|
+
prev.truncated = true;
|
|
945
|
+
prev = reverseTextData.find(function(t) {
|
|
946
|
+
return t.i < i && !t.truncated;
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
datum.truncated = prev ? position - datum[sizeName] / 2 - fP < prev.position + prev[sizeName] / 2 : false;
|
|
951
|
+
});
|
|
952
|
+
if (offset > 1) calculateOffset.bind(this)(textData);
|
|
953
|
+
}
|
|
954
|
+
createTextData.bind(this)();
|
|
955
|
+
var offsetEnabled = this._labelOffset && textData.some(function(d) {
|
|
956
|
+
return d.truncated;
|
|
957
|
+
});
|
|
958
|
+
if (offsetEnabled) createTextData.bind(this)(2);
|
|
959
|
+
/**
|
|
960
|
+
* "spillover" will contain the pixel spillover of the first and last label,
|
|
961
|
+
* and then adjust the scale range accordingly.
|
|
962
|
+
*/ var spillovers = [
|
|
963
|
+
0,
|
|
964
|
+
1
|
|
965
|
+
].map(function(index) {
|
|
966
|
+
var datum = textData[index ? textData.length - 1 : 0];
|
|
967
|
+
if (!datum) return 0;
|
|
968
|
+
var height = datum.height, position = datum.position, rotate = datum.rotate, width = datum.width;
|
|
969
|
+
var compPosition = index ? rangeOuter[1] : rangeOuter[0];
|
|
970
|
+
var halfSpace = (rotate || !horizontal ? height : width) / 2;
|
|
971
|
+
if (Math.abs(position - compPosition) >= halfSpace) return 0;
|
|
972
|
+
var spill = halfSpace - (position - compPosition);
|
|
973
|
+
return Math.abs(spill);
|
|
974
|
+
});
|
|
975
|
+
var _range = _sliced_to_array(range, 2), first = _range[0], last = _range[1];
|
|
976
|
+
var newRange = [
|
|
977
|
+
first + spillovers[0],
|
|
978
|
+
last - spillovers[1]
|
|
979
|
+
];
|
|
980
|
+
if (this._range) {
|
|
981
|
+
if (this._range[0] !== undefined) newRange[0] = this._range[0];
|
|
982
|
+
if (this._range[this._range.length - 1] !== undefined) newRange[1] = this._range[this._range.length - 1];
|
|
983
|
+
}
|
|
984
|
+
if (newRange[0] !== first || newRange[1] !== last) {
|
|
985
|
+
setScale.bind(this)(newRange);
|
|
986
|
+
createTextData.bind(this)(offsetEnabled ? 2 : 1);
|
|
987
|
+
}
|
|
988
|
+
var labelHeight = max(textData, function(t) {
|
|
989
|
+
return t.height;
|
|
990
|
+
}) || 0;
|
|
991
|
+
this._labelRotation = horizontal && this._labelRotation === undefined ? textData.some(function(datum) {
|
|
992
|
+
var i = datum.i, height = datum.height, position = datum.position, truncated = datum.truncated;
|
|
993
|
+
var prev = textData[i - 1];
|
|
994
|
+
return truncated || i && prev.position + prev.height / 2 > position - height / 2;
|
|
995
|
+
}) : this._labelRotation;
|
|
996
|
+
var globalOffset = this._labelOffset ? max(textData, function(d) {
|
|
997
|
+
return d.offset || 0;
|
|
998
|
+
}) : 0;
|
|
999
|
+
textData.forEach(function(datum) {
|
|
1000
|
+
return datum.offset = datum.offset ? globalOffset : 0;
|
|
1001
|
+
});
|
|
1002
|
+
var tBuff = this._shape === "Line" ? 0 : hBuff;
|
|
1003
|
+
var _obj;
|
|
1004
|
+
var bounds = this._outerBounds = (_obj = {}, _define_property(_obj, height, (max(textData, function(t) {
|
|
1005
|
+
return Math.ceil(t[t.rotate || !horizontal ? "width" : "height"] + t.offset);
|
|
1006
|
+
}) || 0) + (textData.length ? p : 0)), _define_property(_obj, width, rangeOuter[rangeOuter.length - 1] - rangeOuter[0]), _define_property(_obj, x, rangeOuter[0]), _obj);
|
|
1007
|
+
bounds[height] = max([
|
|
1008
|
+
this._minSize,
|
|
1009
|
+
bounds[height]
|
|
1010
|
+
]);
|
|
1011
|
+
margin[this._orient] += hBuff;
|
|
1012
|
+
margin[opposite] = this._gridSize !== undefined ? max([
|
|
1013
|
+
this._gridSize,
|
|
1014
|
+
tBuff
|
|
1015
|
+
]) : this["_".concat(height)] - margin[this._orient] - bounds[height] - p;
|
|
1016
|
+
bounds[height] += margin[opposite] + margin[this._orient];
|
|
1017
|
+
bounds[y] = this._align === "start" ? this._padding : this._align === "end" ? this["_".concat(height)] - bounds[height] - this._padding : this["_".concat(height)] / 2 - bounds[height] / 2;
|
|
1018
|
+
var group = elem("g#d3plus-Axis-".concat(this._uuid), {
|
|
1019
|
+
parent: parent
|
|
1020
|
+
});
|
|
1021
|
+
this._group = group;
|
|
1022
|
+
var grid = elem("g.grid", {
|
|
1023
|
+
parent: group
|
|
1024
|
+
}).selectAll("line").data((this._gridSize !== 0 ? this._grid || this._scale === "log" && !this._gridLog ? labels : ticks : []).map(function(d) {
|
|
1025
|
+
return {
|
|
1026
|
+
id: d
|
|
1027
|
+
};
|
|
1028
|
+
}), function(d) {
|
|
1029
|
+
return d.id;
|
|
1030
|
+
});
|
|
1031
|
+
grid.exit().transition(t).attr("opacity", 0).call(this._gridPosition.bind(this)).remove();
|
|
1032
|
+
grid.enter().append("line").attr("opacity", 0).attr("clip-path", "url(#".concat(clipId, ")")).call(this._gridPosition.bind(this), true).merge(grid).transition(t).attr("opacity", 1).call(this._gridPosition.bind(this));
|
|
1033
|
+
var labelOnly = labels.filter(function(d, i) {
|
|
1034
|
+
return textData[i].lines.length && !ticks.includes(d);
|
|
1035
|
+
});
|
|
1036
|
+
var rotated = textData.some(function(d) {
|
|
1037
|
+
return d.rotate;
|
|
1038
|
+
});
|
|
1039
|
+
var tickData = ticks.concat(labelOnly).map(function(d) {
|
|
1040
|
+
var data = textData.find(function(td) {
|
|
1041
|
+
return td.d === d;
|
|
1042
|
+
});
|
|
1043
|
+
var xPos = _this._getPosition(d);
|
|
1044
|
+
var space = data ? data.space : 0;
|
|
1045
|
+
var lines = data ? data.lines.length : 1;
|
|
1046
|
+
var lineHeight = data ? data.lineHeight : 1;
|
|
1047
|
+
var fP = data ? data.fP : 0;
|
|
1048
|
+
var labelOffset = data && _this._labelOffset ? data.offset : 0;
|
|
1049
|
+
var labelWidth = horizontal ? space : bounds.width - margin[_this._position.opposite] - hBuff - margin[_this._orient] + p;
|
|
1050
|
+
var offset = margin[opposite], size = (hBuff + labelOffset) * (flip ? -1 : 1), yPos = flip ? bounds[y] + bounds[height] - offset : bounds[y] + offset;
|
|
1051
|
+
var _obj;
|
|
1052
|
+
var tickConfig = (_obj = {
|
|
1053
|
+
id: d,
|
|
1054
|
+
labelBounds: rotated && data ? {
|
|
1055
|
+
x: -data.width / 2 + data.fS / 4,
|
|
1056
|
+
y: _this._orient === "bottom" ? size + (data.width - lineHeight * lines) / 2 + fP : size * 2 - (data.width + lineHeight * lines) / 2 + fP,
|
|
1057
|
+
width: data.width,
|
|
1058
|
+
height: data.height
|
|
1059
|
+
} : {
|
|
1060
|
+
x: horizontal ? -space / 2 : _this._orient === "left" ? -labelWidth - p + size : size + p,
|
|
1061
|
+
y: horizontal ? _this._orient === "bottom" ? size + fP : size - labelHeight - fP : -space / 2,
|
|
1062
|
+
width: horizontal ? space : labelWidth,
|
|
1063
|
+
height: horizontal ? labelHeight : space
|
|
1064
|
+
},
|
|
1065
|
+
rotate: data ? data.rotate : false,
|
|
1066
|
+
size: labels.includes(d) || _this._scale === "log" && Math.log10(Math.abs(d)) % 1 === 0 ? size : ticks.includes(d) ? Math.ceil(size / 2) : _this._data.find(function(t) {
|
|
1067
|
+
return +t === d;
|
|
1068
|
+
}) ? Math.ceil(size / 4) : 0,
|
|
1069
|
+
text: !(data || {}).truncated && labels.includes(d) ? tickFormat(d) : false,
|
|
1070
|
+
tick: ticks.includes(d)
|
|
1071
|
+
}, _define_property(_obj, x, xPos + (_this._scale === "band" ? _this._d3Scale.bandwidth() / 2 : 0)), _define_property(_obj, y, yPos), _obj);
|
|
1072
|
+
return tickConfig;
|
|
1073
|
+
});
|
|
1074
|
+
if (this._shape === "Line") {
|
|
1075
|
+
tickData = tickData.concat(tickData.map(function(d) {
|
|
1076
|
+
var dupe = Object.assign({}, d);
|
|
1077
|
+
dupe[y] += d.size;
|
|
1078
|
+
return dupe;
|
|
1079
|
+
}));
|
|
1080
|
+
}
|
|
1081
|
+
new shapes[this._shape]().data(tickData).duration(this._duration).labelConfig({
|
|
1082
|
+
ellipsis: function(d) {
|
|
1083
|
+
return d && d.length ? "".concat(d, "...") : "";
|
|
1084
|
+
},
|
|
1085
|
+
rotate: function(d) {
|
|
1086
|
+
return d.rotate ? -90 : 0;
|
|
1087
|
+
}
|
|
1088
|
+
}).select(elem("g.ticks", {
|
|
1089
|
+
parent: group
|
|
1090
|
+
}).node()).config(configPrep.bind(this)(this._shapeConfig)).labelConfig({
|
|
1091
|
+
padding: 0
|
|
1092
|
+
}).render();
|
|
1093
|
+
var bar = group.selectAll("line.bar").data([
|
|
1094
|
+
null
|
|
1095
|
+
]);
|
|
1096
|
+
bar.enter().append("line").attr("class", "bar").attr("opacity", 0).call(this._barPosition.bind(this)).merge(bar).transition(t).attr("opacity", 1).call(this._barPosition.bind(this));
|
|
1097
|
+
this._titleClass.data(this._title ? [
|
|
1098
|
+
{
|
|
1099
|
+
text: this._title
|
|
1100
|
+
}
|
|
1101
|
+
] : []).duration(this._duration).height(margin[this._orient]).rotate(this._orient === "left" ? -90 : this._orient === "right" ? 90 : 0).select(elem("g.d3plus-Axis-title", {
|
|
1102
|
+
parent: group
|
|
1103
|
+
}).node()).text(function(d) {
|
|
1104
|
+
return d.text;
|
|
1105
|
+
}).verticalAlign("middle").width(range[range.length - 1] - range[0]).x(horizontal ? range[0] : this._orient === "left" ? bounds.x + margin.left / 2 - (range[range.length - 1] - range[0]) / 2 : bounds.x + bounds.width - margin.right / 2 - (range[range.length - 1] - range[0]) / 2).y(horizontal ? this._orient === "bottom" ? bounds.y + bounds.height - margin.bottom : bounds.y : range[0] + (range[range.length - 1] - range[0]) / 2 - margin[this._orient] / 2).config(configPrep.bind(this)(this._titleConfig)).render();
|
|
1106
|
+
this._lastScale = this._getPosition.bind(this);
|
|
1107
|
+
if (callback) setTimeout(callback, this._duration + 100);
|
|
1108
|
+
return this;
|
|
1109
|
+
}
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
/**
|
|
1113
|
+
@memberof Axis
|
|
1114
|
+
@desc If *value* is specified, sets the horizontal alignment to the specified value and returns the current class instance.
|
|
1115
|
+
@param {String} [*value* = "center"] Supports `"left"` and `"center"` and `"right"`.
|
|
1116
|
+
@chainable
|
|
1117
|
+
*/ key: "align",
|
|
1118
|
+
value: function align(_) {
|
|
1119
|
+
return arguments.length ? (this._align = _, this) : this._align;
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
/**
|
|
1124
|
+
@memberof Axis
|
|
1125
|
+
@desc If *value* is specified, sets the axis line style and returns the current class instance.
|
|
1126
|
+
@param {Object} [*value*]
|
|
1127
|
+
@chainable
|
|
1128
|
+
*/ key: "barConfig",
|
|
1129
|
+
value: function barConfig(_) {
|
|
1130
|
+
return arguments.length ? (this._barConfig = Object.assign(this._barConfig, _), this) : this._barConfig;
|
|
1131
|
+
}
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
/**
|
|
1135
|
+
@memberof Axis
|
|
1136
|
+
@desc An array of data points, which helps determine which ticks should be shown and which time resolution should be displayed.
|
|
1137
|
+
@param {Array} [*value*]
|
|
1138
|
+
@chainable
|
|
1139
|
+
*/ key: "data",
|
|
1140
|
+
value: function data(_) {
|
|
1141
|
+
return arguments.length ? (this._data = _, this) : this._data;
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
/**
|
|
1146
|
+
@memberof Axis
|
|
1147
|
+
@desc If *value* is specified, sets the scale domain of the axis and returns the current class instance.
|
|
1148
|
+
@param {Array} [*value* = [0, 10]]
|
|
1149
|
+
@chainable
|
|
1150
|
+
*/ key: "domain",
|
|
1151
|
+
value: function domain(_) {
|
|
1152
|
+
return arguments.length ? (this._domain = _, this) : this._domain;
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
/**
|
|
1157
|
+
@memberof Axis
|
|
1158
|
+
@desc If *value* is specified, sets the transition duration of the axis and returns the current class instance.
|
|
1159
|
+
@param {Number} [*value* = 600]
|
|
1160
|
+
@chainable
|
|
1161
|
+
*/ key: "duration",
|
|
1162
|
+
value: function duration(_) {
|
|
1163
|
+
return arguments.length ? (this._duration = _, this) : this._duration;
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
/**
|
|
1168
|
+
@memberof Axis
|
|
1169
|
+
@desc If *value* is specified, sets the grid values of the axis and returns the current class instance.
|
|
1170
|
+
@param {Array} [*value*]
|
|
1171
|
+
@chainable
|
|
1172
|
+
*/ key: "grid",
|
|
1173
|
+
value: function grid(_) {
|
|
1174
|
+
return arguments.length ? (this._grid = _, this) : this._grid;
|
|
1175
|
+
}
|
|
1176
|
+
},
|
|
1177
|
+
{
|
|
1178
|
+
/**
|
|
1179
|
+
@memberof Axis
|
|
1180
|
+
@desc If *value* is specified, sets the grid config of the axis and returns the current class instance.
|
|
1181
|
+
@param {Object} [*value*]
|
|
1182
|
+
@chainable
|
|
1183
|
+
*/ key: "gridConfig",
|
|
1184
|
+
value: function gridConfig(_) {
|
|
1185
|
+
return arguments.length ? (this._gridConfig = Object.assign(this._gridConfig, _), this) : this._gridConfig;
|
|
1186
|
+
}
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
/**
|
|
1190
|
+
@memberof Axis
|
|
1191
|
+
@desc If *value* is specified, sets the grid behavior of the axis when scale is logarithmic and returns the current class instance.
|
|
1192
|
+
@param {Boolean} [*value* = false]
|
|
1193
|
+
@chainable
|
|
1194
|
+
*/ key: "gridLog",
|
|
1195
|
+
value: function gridLog(_) {
|
|
1196
|
+
return arguments.length ? (this._gridLog = _, this) : this._gridLog;
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
/**
|
|
1201
|
+
@memberof Axis
|
|
1202
|
+
@desc If *value* is specified, sets the grid size of the axis and returns the current class instance.
|
|
1203
|
+
@param {Number} [*value* = undefined]
|
|
1204
|
+
@chainable
|
|
1205
|
+
*/ key: "gridSize",
|
|
1206
|
+
value: function gridSize(_) {
|
|
1207
|
+
return arguments.length ? (this._gridSize = _, this) : this._gridSize;
|
|
1208
|
+
}
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
/**
|
|
1212
|
+
@memberof Axis
|
|
1213
|
+
@desc If *value* is specified, sets the overall height of the axis and returns the current class instance.
|
|
1214
|
+
@param {Number} [*value* = 100]
|
|
1215
|
+
@chainable
|
|
1216
|
+
*/ key: "height",
|
|
1217
|
+
value: function height(_) {
|
|
1218
|
+
return arguments.length ? (this._height = _, this) : this._height;
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
/**
|
|
1223
|
+
@memberof Axis
|
|
1224
|
+
@desc If *value* is specified, sets the visible tick labels of the axis and returns the current class instance.
|
|
1225
|
+
@param {Array} [*value*]
|
|
1226
|
+
@chainable
|
|
1227
|
+
*/ key: "labels",
|
|
1228
|
+
value: function labels(_) {
|
|
1229
|
+
return arguments.length ? (this._labels = _, this) : this._labels;
|
|
1230
|
+
}
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
/**
|
|
1234
|
+
@memberof Axis
|
|
1235
|
+
@desc If *value* is specified, sets whether offsets will be used to position some labels further away from the axis in order to allow space for the text.
|
|
1236
|
+
@param {Boolean} [*value* = false]
|
|
1237
|
+
@chainable
|
|
1238
|
+
*/ key: "labelOffset",
|
|
1239
|
+
value: function labelOffset(_) {
|
|
1240
|
+
return arguments.length ? (this._labelOffset = _, this) : this._labelOffset;
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
/**
|
|
1245
|
+
@memberof Axis
|
|
1246
|
+
@desc If *value* is specified, sets whether whether horizontal axis labels are rotated -90 degrees.
|
|
1247
|
+
@param {Boolean} [*value* = false]
|
|
1248
|
+
@chainable
|
|
1249
|
+
*/ key: "labelRotation",
|
|
1250
|
+
value: function labelRotation(_) {
|
|
1251
|
+
return arguments.length ? (this._labelRotation = _, this) : this._labelRotation;
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
{
|
|
1255
|
+
/**
|
|
1256
|
+
@memberof Axis
|
|
1257
|
+
@desc If *value* is specified, sets the maximum size allowed for the space that contains the axis tick labels and title.
|
|
1258
|
+
@param {Number}
|
|
1259
|
+
@chainable
|
|
1260
|
+
*/ key: "maxSize",
|
|
1261
|
+
value: function maxSize(_) {
|
|
1262
|
+
return arguments.length ? (this._maxSize = _, this) : this._maxSize;
|
|
1263
|
+
}
|
|
1264
|
+
},
|
|
1265
|
+
{
|
|
1266
|
+
/**
|
|
1267
|
+
@memberof Axis
|
|
1268
|
+
@desc If *value* is specified, sets the minimum size alloted for the space that contains the axis tick labels and title.
|
|
1269
|
+
@param {Number}
|
|
1270
|
+
@chainable
|
|
1271
|
+
*/ key: "minSize",
|
|
1272
|
+
value: function minSize(_) {
|
|
1273
|
+
return arguments.length ? (this._minSize = _, this) : this._minSize;
|
|
1274
|
+
}
|
|
1275
|
+
},
|
|
1276
|
+
{
|
|
1277
|
+
/**
|
|
1278
|
+
@memberof Axis
|
|
1279
|
+
@desc If *orient* is specified, sets the orientation of the shape and returns the current class instance. If *orient* is not specified, returns the current orientation.
|
|
1280
|
+
@param {String} [*orient* = "bottom"] Supports `"top"`, `"right"`, `"bottom"`, and `"left"` orientations.
|
|
1281
|
+
@chainable
|
|
1282
|
+
*/ key: "orient",
|
|
1283
|
+
value: function orient(_) {
|
|
1284
|
+
if (arguments.length) {
|
|
1285
|
+
var horizontal = [
|
|
1286
|
+
"top",
|
|
1287
|
+
"bottom"
|
|
1288
|
+
].includes(_), opps = {
|
|
1289
|
+
top: "bottom",
|
|
1290
|
+
right: "left",
|
|
1291
|
+
bottom: "top",
|
|
1292
|
+
left: "right"
|
|
1293
|
+
};
|
|
1294
|
+
this._position = {
|
|
1295
|
+
horizontal: horizontal,
|
|
1296
|
+
width: horizontal ? "width" : "height",
|
|
1297
|
+
height: horizontal ? "height" : "width",
|
|
1298
|
+
x: horizontal ? "x" : "y",
|
|
1299
|
+
y: horizontal ? "y" : "x",
|
|
1300
|
+
opposite: opps[_]
|
|
1301
|
+
};
|
|
1302
|
+
return this._orient = _, this;
|
|
1303
|
+
}
|
|
1304
|
+
return this._orient;
|
|
1305
|
+
}
|
|
1306
|
+
},
|
|
1307
|
+
{
|
|
1308
|
+
/**
|
|
1309
|
+
@memberof Axis
|
|
1310
|
+
@desc If called after the elements have been drawn to DOM, will returns the outer bounds of the axis content.
|
|
1311
|
+
@example
|
|
1312
|
+
{"width": 180, "height": 24, "x": 10, "y": 20}
|
|
1313
|
+
*/ key: "outerBounds",
|
|
1314
|
+
value: function outerBounds() {
|
|
1315
|
+
return this._outerBounds;
|
|
1316
|
+
}
|
|
1317
|
+
},
|
|
1318
|
+
{
|
|
1319
|
+
/**
|
|
1320
|
+
@memberof Axis
|
|
1321
|
+
@desc If *value* is specified, sets the padding between each tick label to the specified number and returns the current class instance.
|
|
1322
|
+
@param {Number} [*value* = 10]
|
|
1323
|
+
@chainable
|
|
1324
|
+
*/ key: "padding",
|
|
1325
|
+
value: function padding(_) {
|
|
1326
|
+
return arguments.length ? (this._padding = _, this) : this._padding;
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
/**
|
|
1331
|
+
@memberof Axis
|
|
1332
|
+
@desc If *value* is specified, sets the inner padding of band scale to the specified number and returns the current class instance.
|
|
1333
|
+
@param {Number} [*value* = 0.1]
|
|
1334
|
+
@chainable
|
|
1335
|
+
*/ key: "paddingInner",
|
|
1336
|
+
value: function paddingInner(_) {
|
|
1337
|
+
return arguments.length ? (this._paddingInner = _, this) : this._paddingInner;
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
/**
|
|
1342
|
+
@memberof Axis
|
|
1343
|
+
@desc If *value* is specified, sets the outer padding of band scales to the specified number and returns the current class instance.
|
|
1344
|
+
@param {Number} [*value* = 0.1]
|
|
1345
|
+
@chainable
|
|
1346
|
+
*/ key: "paddingOuter",
|
|
1347
|
+
value: function paddingOuter(_) {
|
|
1348
|
+
return arguments.length ? (this._paddingOuter = _, this) : this._paddingOuter;
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
{
|
|
1352
|
+
/**
|
|
1353
|
+
@memberof Axis
|
|
1354
|
+
@desc If *value* is specified, sets the scale range (in pixels) of the axis and returns the current class instance. The given array must have 2 values, but one may be `undefined` to allow the default behavior for that value.
|
|
1355
|
+
@param {Array} [*value*]
|
|
1356
|
+
@chainable
|
|
1357
|
+
*/ key: "range",
|
|
1358
|
+
value: function range(_) {
|
|
1359
|
+
return arguments.length ? (this._range = _, this) : this._range;
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
{
|
|
1363
|
+
/**
|
|
1364
|
+
@memberof Axis
|
|
1365
|
+
@desc Sets the rounding method, so that more evenly spaced ticks appear at the extents of the scale. Can be set to "none" (default), "outside", or "inside".
|
|
1366
|
+
@param {String} [*value* = "none"]
|
|
1367
|
+
@chainable
|
|
1368
|
+
*/ key: "rounding",
|
|
1369
|
+
value: function rounding(_) {
|
|
1370
|
+
return arguments.length ? (this._rounding = _, this) : this._rounding;
|
|
1371
|
+
}
|
|
1372
|
+
},
|
|
1373
|
+
{
|
|
1374
|
+
/**
|
|
1375
|
+
@memberof Axis
|
|
1376
|
+
@desc Sets the prefix used for the minimum value of "inside" rounding scales.
|
|
1377
|
+
@param {String} [*value* = "< "]
|
|
1378
|
+
@chainable
|
|
1379
|
+
*/ key: "roundingInsideMinPrefix",
|
|
1380
|
+
value: function roundingInsideMinPrefix(_) {
|
|
1381
|
+
return arguments.length ? (this._roundingInsideMinPrefix = _, this) : this._roundingInsideMinPrefix;
|
|
1382
|
+
}
|
|
1383
|
+
},
|
|
1384
|
+
{
|
|
1385
|
+
/**
|
|
1386
|
+
@memberof Axis
|
|
1387
|
+
@desc Sets the suffix used for the minimum value of "inside" rounding scales.
|
|
1388
|
+
@param {String} [*value* = ""]
|
|
1389
|
+
@chainable
|
|
1390
|
+
*/ key: "roundingInsideMinSuffix",
|
|
1391
|
+
value: function roundingInsideMinSuffix(_) {
|
|
1392
|
+
return arguments.length ? (this._roundingInsideMinSuffix = _, this) : this._roundingInsideMinSuffix;
|
|
1393
|
+
}
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
/**
|
|
1397
|
+
@memberof Axis
|
|
1398
|
+
@desc Sets the prefix used for the maximum value of "inside" rounding scales.
|
|
1399
|
+
@param {String} [*value* = ""]
|
|
1400
|
+
@chainable
|
|
1401
|
+
*/ key: "roundingInsideMaxPrefix",
|
|
1402
|
+
value: function roundingInsideMaxPrefix(_) {
|
|
1403
|
+
return arguments.length ? (this._roundingInsideMaxPrefix = _, this) : this._roundingInsideMaxPrefix;
|
|
1404
|
+
}
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
/**
|
|
1408
|
+
@memberof Axis
|
|
1409
|
+
@desc Sets the suffix used for the maximum value of "inside" rounding scales.
|
|
1410
|
+
@param {String} [*value* = ""]
|
|
1411
|
+
@chainable
|
|
1412
|
+
*/ key: "roundingInsideMaxSuffix",
|
|
1413
|
+
value: function roundingInsideMaxSuffix(_) {
|
|
1414
|
+
return arguments.length ? (this._roundingInsideMaxSuffix = _, this) : this._roundingInsideMaxSuffix;
|
|
1415
|
+
}
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
/**
|
|
1419
|
+
@memberof Axis
|
|
1420
|
+
@desc If *value* is specified, sets the scale of the axis and returns the current class instance.
|
|
1421
|
+
@param {String} [*value* = "linear"]
|
|
1422
|
+
@chainable
|
|
1423
|
+
*/ key: "scale",
|
|
1424
|
+
value: function scale(_) {
|
|
1425
|
+
return arguments.length ? (this._scale = _, this) : this._scale;
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
1428
|
+
{
|
|
1429
|
+
/**
|
|
1430
|
+
@memberof Axis
|
|
1431
|
+
@desc Sets the "padding" property of the scale, often used in point scales.
|
|
1432
|
+
@param {Number} [*value* = 0.5]
|
|
1433
|
+
@chainable
|
|
1434
|
+
*/ key: "scalePadding",
|
|
1435
|
+
value: function scalePadding(_) {
|
|
1436
|
+
return arguments.length ? (this._scalePadding = _, this) : this._scalePadding;
|
|
1437
|
+
}
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
/**
|
|
1441
|
+
@memberof Axis
|
|
1442
|
+
@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.
|
|
1443
|
+
@param {String|HTMLElement} [*selector* = d3.select("body").append("svg")]
|
|
1444
|
+
@chainable
|
|
1445
|
+
*/ key: "select",
|
|
1446
|
+
value: function select1(_) {
|
|
1447
|
+
return arguments.length ? (this._select = select(_), this) : this._select;
|
|
1448
|
+
}
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
/**
|
|
1452
|
+
@memberof Axis
|
|
1453
|
+
@desc If *value* is specified, sets the tick shape constructor and returns the current class instance.
|
|
1454
|
+
@param {String} [*value* = "Line"]
|
|
1455
|
+
@chainable
|
|
1456
|
+
*/ key: "shape",
|
|
1457
|
+
value: function shape(_) {
|
|
1458
|
+
return arguments.length ? (this._shape = _, this) : this._shape;
|
|
1459
|
+
}
|
|
1460
|
+
},
|
|
1461
|
+
{
|
|
1462
|
+
/**
|
|
1463
|
+
@memberof Axis
|
|
1464
|
+
@desc If *value* is specified, sets the tick style of the axis and returns the current class instance.
|
|
1465
|
+
@param {Object} [*value*]
|
|
1466
|
+
@chainable
|
|
1467
|
+
*/ key: "shapeConfig",
|
|
1468
|
+
value: function shapeConfig(_) {
|
|
1469
|
+
return arguments.length ? (this._shapeConfig = assign(this._shapeConfig, _), this) : this._shapeConfig;
|
|
1470
|
+
}
|
|
1471
|
+
},
|
|
1472
|
+
{
|
|
1473
|
+
/**
|
|
1474
|
+
@memberof Axis
|
|
1475
|
+
@desc If *value* is specified, sets the tick formatter and returns the current class instance.
|
|
1476
|
+
@param {Function} [*value*]
|
|
1477
|
+
@chainable
|
|
1478
|
+
*/ key: "tickFormat",
|
|
1479
|
+
value: function tickFormat(_) {
|
|
1480
|
+
return arguments.length ? (this._tickFormat = _, this) : this._tickFormat;
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
{
|
|
1484
|
+
/**
|
|
1485
|
+
@memberof Axis
|
|
1486
|
+
@desc If *value* is specified, sets the tick values of the axis and returns the current class instance.
|
|
1487
|
+
@param {Array} [*value*]
|
|
1488
|
+
@chainable
|
|
1489
|
+
*/ key: "ticks",
|
|
1490
|
+
value: function ticks(_) {
|
|
1491
|
+
return arguments.length ? (this._ticks = _, this) : this._ticks;
|
|
1492
|
+
}
|
|
1493
|
+
},
|
|
1494
|
+
{
|
|
1495
|
+
/**
|
|
1496
|
+
@memberof Axis
|
|
1497
|
+
@desc If *value* is specified, sets the tick size of the axis and returns the current class instance.
|
|
1498
|
+
@param {Number} [*value* = 5]
|
|
1499
|
+
@chainable
|
|
1500
|
+
*/ key: "tickSize",
|
|
1501
|
+
value: function tickSize(_) {
|
|
1502
|
+
return arguments.length ? (this._tickSize = _, this) : this._tickSize;
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
/**
|
|
1507
|
+
@memberof Axis
|
|
1508
|
+
@desc Sets the behavior of the abbreviations when you are using linear scale. This method accepts two options: "normal" (uses formatAbbreviate to determinate the abbreviation) and "smallest" (uses suffix from the smallest tick as reference in every tick).
|
|
1509
|
+
@param {String} [*value* = "normal"]
|
|
1510
|
+
@chainable
|
|
1511
|
+
*/ key: "tickSuffix",
|
|
1512
|
+
value: function tickSuffix(_) {
|
|
1513
|
+
return arguments.length ? (this._tickSuffix = _, this) : this._tickSuffix;
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
{
|
|
1517
|
+
/**
|
|
1518
|
+
@memberof Axis
|
|
1519
|
+
@desc Defines a custom locale object to be used in time scale. This object must include the following properties: dateTime, date, time, periods, days, shortDays, months, shortMonths. For more information, you can revise [d3p.d3-time-format](https://github.com/d3/d3-time-format/blob/master/README.md#timeFormatLocale).
|
|
1520
|
+
@param {Object} [*value* = undefined]
|
|
1521
|
+
@chainable
|
|
1522
|
+
*/ key: "timeLocale",
|
|
1523
|
+
value: function timeLocale(_) {
|
|
1524
|
+
return arguments.length ? (this._timeLocale = _, this) : this._timeLocale;
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
/**
|
|
1529
|
+
@memberof Axis
|
|
1530
|
+
@desc If *value* is specified, sets the title of the axis and returns the current class instance.
|
|
1531
|
+
@param {String} [*value*]
|
|
1532
|
+
@chainable
|
|
1533
|
+
*/ key: "title",
|
|
1534
|
+
value: function title(_) {
|
|
1535
|
+
return arguments.length ? (this._title = _, this) : this._title;
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
{
|
|
1539
|
+
/**
|
|
1540
|
+
@memberof Axis
|
|
1541
|
+
@desc If *value* is specified, sets the title configuration of the axis and returns the current class instance.
|
|
1542
|
+
@param {Object} [*value*]
|
|
1543
|
+
@chainable
|
|
1544
|
+
*/ key: "titleConfig",
|
|
1545
|
+
value: function titleConfig(_) {
|
|
1546
|
+
return arguments.length ? (this._titleConfig = Object.assign(this._titleConfig, _), this) : this._titleConfig;
|
|
1547
|
+
}
|
|
1548
|
+
},
|
|
1549
|
+
{
|
|
1550
|
+
/**
|
|
1551
|
+
@memberof Axis
|
|
1552
|
+
@desc If *value* is specified, sets the overall width of the axis and returns the current class instance.
|
|
1553
|
+
@param {Number} [*value* = 400]
|
|
1554
|
+
@chainable
|
|
1555
|
+
*/ key: "width",
|
|
1556
|
+
value: function width(_) {
|
|
1557
|
+
return arguments.length ? (this._width = _, this) : this._width;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
]);
|
|
1561
|
+
return Axis;
|
|
1562
|
+
}(BaseClass);
|
|
1563
|
+
/**
|
|
1564
|
+
@class Axis
|
|
1565
|
+
@extends BaseClass
|
|
1566
|
+
@desc Creates an SVG scale based on an array of data.
|
|
1567
|
+
*/ export { Axis as default };
|