@plotdb/chart 3.5.0 → 3.7.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/CHANGELOG.md +36 -0
- package/bundle.css +59 -0
- package/bundle.js +5644 -0
- package/bundle.min.css +1 -0
- package/bundle.min.js +1 -0
- package/index.js +32 -10
- package/index.min.js +1 -1
- package/package.json +1 -1
- package/utils/anim.js +483 -0
- package/utils/anim.min.js +1 -0
- package/utils/brush.js +306 -0
- package/utils/brush.min.js +1 -0
- package/utils/color.js +37 -0
- package/utils/color.min.js +1 -0
- package/utils/debounce.js +86 -0
- package/utils/debounce.min.js +1 -0
- package/utils/format.js +266 -5
- package/utils/format.min.js +1 -1
- package/utils/scale.js +434 -0
- package/utils/scale.min.js +1 -0
- package/utils/shape.js +799 -0
- package/utils/shape.min.js +1 -0
package/utils/shape.js
ADDED
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
var abs, atan2, cos, sin, sqrt, min, max, pi, halfPi, tau, eps, pEps, tauEps, acos, asin, constant, accessor, Path, intersect, cornerTangents, arc, Linear, curveLinear, cardinalPoint, Cardinal, catmullPoint, CatmullRom, catmullRom, custom, curve, asArray, line, area, shape;
|
|
3
|
+
abs = Math.abs, atan2 = Math.atan2, cos = Math.cos, sin = Math.sin, sqrt = Math.sqrt, min = Math.min, max = Math.max;
|
|
4
|
+
pi = Math.PI;
|
|
5
|
+
halfPi = pi / 2;
|
|
6
|
+
tau = 2 * pi;
|
|
7
|
+
eps = 1e-12;
|
|
8
|
+
pEps = 1e-6;
|
|
9
|
+
tauEps = tau - pEps;
|
|
10
|
+
acos = function(x){
|
|
11
|
+
if (x > 1) {
|
|
12
|
+
return 0;
|
|
13
|
+
} else if (x < -1) {
|
|
14
|
+
return pi;
|
|
15
|
+
} else {
|
|
16
|
+
return Math.acos(x);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
asin = function(x){
|
|
20
|
+
if (x >= 1) {
|
|
21
|
+
return halfPi;
|
|
22
|
+
} else if (x <= -1) {
|
|
23
|
+
return -halfPi;
|
|
24
|
+
} else {
|
|
25
|
+
return Math.asin(x);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
constant = function(x){
|
|
29
|
+
return function(){
|
|
30
|
+
return x;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
accessor = function(v){
|
|
34
|
+
if (typeof v === 'function') {
|
|
35
|
+
return v;
|
|
36
|
+
} else {
|
|
37
|
+
return constant(+v);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
Path = function(digits){
|
|
41
|
+
this._x0 = this._y0 = this._x1 = this._y1 = null;
|
|
42
|
+
this._ = '';
|
|
43
|
+
this._k = digits != null && Math.floor(digits) <= 15 ? Math.pow(10, Math.floor(digits)) : null;
|
|
44
|
+
return this;
|
|
45
|
+
};
|
|
46
|
+
Path.prototype = {
|
|
47
|
+
_a: function(cmd){
|
|
48
|
+
var vs, res$, i$, to$, k;
|
|
49
|
+
res$ = [];
|
|
50
|
+
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
|
|
51
|
+
res$.push(arguments[i$]);
|
|
52
|
+
}
|
|
53
|
+
vs = res$;
|
|
54
|
+
k = this._k;
|
|
55
|
+
return this._ += cmd + (k != null ? vs.map(function(it){
|
|
56
|
+
return Math.round(it * k) / k;
|
|
57
|
+
}) : vs).join(',');
|
|
58
|
+
},
|
|
59
|
+
moveTo: function(x, y){
|
|
60
|
+
this._x0 = this._x1 = +x;
|
|
61
|
+
this._y0 = this._y1 = +y;
|
|
62
|
+
return this._a('M', this._x0, this._y0);
|
|
63
|
+
},
|
|
64
|
+
closePath: function(){
|
|
65
|
+
if (this._x1 !== null) {
|
|
66
|
+
this._x1 = this._x0;
|
|
67
|
+
this._y1 = this._y0;
|
|
68
|
+
return this._ += 'Z';
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
lineTo: function(x, y){
|
|
72
|
+
this._x1 = +x;
|
|
73
|
+
this._y1 = +y;
|
|
74
|
+
return this._a('L', this._x1, this._y1);
|
|
75
|
+
},
|
|
76
|
+
bezierCurveTo: function(x1, y1, x2, y2, x, y){
|
|
77
|
+
this._x1 = +x;
|
|
78
|
+
this._y1 = +y;
|
|
79
|
+
return this._a('C', +x1, +y1, +x2, +y2, this._x1, this._y1);
|
|
80
|
+
},
|
|
81
|
+
arc: function(x, y, r, a0, a1, ccw){
|
|
82
|
+
var ref$, dx, dy, x0, y0, cw, da;
|
|
83
|
+
ref$ = [+x, +y, +r, !!ccw], x = ref$[0], y = ref$[1], r = ref$[2], ccw = ref$[3];
|
|
84
|
+
if (r < 0) {
|
|
85
|
+
throw new Error("negative radius: " + r);
|
|
86
|
+
}
|
|
87
|
+
dx = r * cos(a0);
|
|
88
|
+
dy = r * sin(a0);
|
|
89
|
+
x0 = x + dx;
|
|
90
|
+
y0 = y + dy;
|
|
91
|
+
cw = ccw ? 0 : 1;
|
|
92
|
+
da = ccw
|
|
93
|
+
? a0 - a1
|
|
94
|
+
: a1 - a0;
|
|
95
|
+
if (this._x1 === null) {
|
|
96
|
+
this._a('M', x0, y0);
|
|
97
|
+
} else if (abs(this._x1 - x0) > pEps || abs(this._y1 - y0) > pEps) {
|
|
98
|
+
this._a('L', x0, y0);
|
|
99
|
+
}
|
|
100
|
+
if (!r) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (da < 0) {
|
|
104
|
+
da = da % tau + tau;
|
|
105
|
+
}
|
|
106
|
+
if (da > tauEps) {
|
|
107
|
+
this._a('A', r, r, 0, 1, cw, x - dx, y - dy);
|
|
108
|
+
this._x1 = x0;
|
|
109
|
+
this._y1 = y0;
|
|
110
|
+
return this._a('A', r, r, 0, 1, cw, this._x1, this._y1);
|
|
111
|
+
} else if (da > pEps) {
|
|
112
|
+
this._x1 = x + r * cos(a1);
|
|
113
|
+
this._y1 = y + r * sin(a1);
|
|
114
|
+
return this._a('A', r, r, 0, da >= pi ? 1 : 0, cw, this._x1, this._y1);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
toString: function(){
|
|
118
|
+
return this._;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
intersect = function(x0, y0, x1, y1, x2, y2, x3, y3){
|
|
122
|
+
var ref$, x10, y10, x32, y32, t;
|
|
123
|
+
ref$ = [x1 - x0, y1 - y0, x3 - x2, y3 - y2], x10 = ref$[0], y10 = ref$[1], x32 = ref$[2], y32 = ref$[3];
|
|
124
|
+
t = y32 * x10 - x32 * y10;
|
|
125
|
+
if (t * t < eps) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
|
129
|
+
return [x0 + t * x10, y0 + t * y10];
|
|
130
|
+
};
|
|
131
|
+
cornerTangents = function(x0, y0, x1, y1, r1, rc, cw){
|
|
132
|
+
var x01, y01, lo, ox, oy, x11, y11, x10, y10, x00, y00, dx, dy, d2, r, D, d, cx0, cy0, cx1, cy1, dx0, dy0, dx1, dy1;
|
|
133
|
+
x01 = x0 - x1;
|
|
134
|
+
y01 = y0 - y1;
|
|
135
|
+
lo = (cw
|
|
136
|
+
? rc
|
|
137
|
+
: -rc) / sqrt(x01 * x01 + y01 * y01);
|
|
138
|
+
ox = lo * y01;
|
|
139
|
+
oy = -lo * x01;
|
|
140
|
+
x11 = x0 + ox;
|
|
141
|
+
y11 = y0 + oy;
|
|
142
|
+
x10 = x1 + ox;
|
|
143
|
+
y10 = y1 + oy;
|
|
144
|
+
x00 = (x11 + x10) / 2;
|
|
145
|
+
y00 = (y11 + y10) / 2;
|
|
146
|
+
dx = x10 - x11;
|
|
147
|
+
dy = y10 - y11;
|
|
148
|
+
d2 = dx * dx + dy * dy;
|
|
149
|
+
r = r1 - rc;
|
|
150
|
+
D = x11 * y10 - x10 * y11;
|
|
151
|
+
d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D));
|
|
152
|
+
cx0 = (D * dy - dx * d) / d2;
|
|
153
|
+
cy0 = (-D * dx - dy * d) / d2;
|
|
154
|
+
cx1 = (D * dy + dx * d) / d2;
|
|
155
|
+
cy1 = (-D * dx + dy * d) / d2;
|
|
156
|
+
dx0 = cx0 - x00;
|
|
157
|
+
dy0 = cy0 - y00;
|
|
158
|
+
dx1 = cx1 - x00;
|
|
159
|
+
dy1 = cy1 - y00;
|
|
160
|
+
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
|
|
161
|
+
cx0 = cx1;
|
|
162
|
+
cy0 = cy1;
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
cx: cx0,
|
|
166
|
+
cy: cy0,
|
|
167
|
+
x01: -ox,
|
|
168
|
+
y01: -oy,
|
|
169
|
+
x11: cx0 * (r1 / r - 1),
|
|
170
|
+
y11: cy0 * (r1 / r - 1)
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
arc = function(){
|
|
174
|
+
var inner, outer, corner, padRadius, start, end, pad, digits, shape;
|
|
175
|
+
inner = function(d){
|
|
176
|
+
return d.innerRadius;
|
|
177
|
+
};
|
|
178
|
+
outer = function(d){
|
|
179
|
+
return d.outerRadius;
|
|
180
|
+
};
|
|
181
|
+
corner = constant(0);
|
|
182
|
+
padRadius = null;
|
|
183
|
+
start = function(d){
|
|
184
|
+
return d.startAngle;
|
|
185
|
+
};
|
|
186
|
+
end = function(d){
|
|
187
|
+
return d.endAngle;
|
|
188
|
+
};
|
|
189
|
+
pad = function(d){
|
|
190
|
+
return d && d.padAngle;
|
|
191
|
+
};
|
|
192
|
+
digits = 3;
|
|
193
|
+
shape = function(){
|
|
194
|
+
var args, ctx, r0, r1, a0, a1, da, cw, ref$, a01, a11, a00, a10, da0, da1, ap, rp, rc, rc0, rc1, p0, p1, x01, y01, x10, y10, x11, y11, x00, y00, oc, ax, ay, bx, by, kc, lc, t0, t1;
|
|
195
|
+
args = arguments;
|
|
196
|
+
ctx = new Path(digits);
|
|
197
|
+
r0 = +inner.apply(this, args);
|
|
198
|
+
r1 = +outer.apply(this, args);
|
|
199
|
+
a0 = start.apply(this, args) - halfPi;
|
|
200
|
+
a1 = end.apply(this, args) - halfPi;
|
|
201
|
+
da = abs(a1 - a0);
|
|
202
|
+
cw = a1 > a0;
|
|
203
|
+
if (r1 < r0) {
|
|
204
|
+
ref$ = [r1, r0], r0 = ref$[0], r1 = ref$[1];
|
|
205
|
+
}
|
|
206
|
+
if (!(r1 > eps)) {
|
|
207
|
+
ctx.moveTo(0, 0);
|
|
208
|
+
} else if (da > tau - eps) {
|
|
209
|
+
ctx.moveTo(r1 * cos(a0), r1 * sin(a0));
|
|
210
|
+
ctx.arc(0, 0, r1, a0, a1, !cw);
|
|
211
|
+
if (r0 > eps) {
|
|
212
|
+
ctx.moveTo(r0 * cos(a1), r0 * sin(a1));
|
|
213
|
+
ctx.arc(0, 0, r0, a1, a0, cw);
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
ref$ = [a0, a1, a0, a1, da, da], a01 = ref$[0], a11 = ref$[1], a00 = ref$[2], a10 = ref$[3], da0 = ref$[4], da1 = ref$[5];
|
|
217
|
+
ap = pad.apply(this, args) / 2;
|
|
218
|
+
rp = ap > eps && (padRadius
|
|
219
|
+
? +padRadius.apply(this, args)
|
|
220
|
+
: sqrt(r0 * r0 + r1 * r1));
|
|
221
|
+
rc = min(abs(r1 - r0) / 2, +corner.apply(this, args));
|
|
222
|
+
rc0 = rc;
|
|
223
|
+
rc1 = rc;
|
|
224
|
+
if (rp > eps) {
|
|
225
|
+
p0 = asin(rp / r0 * sin(ap));
|
|
226
|
+
p1 = asin(rp / r1 * sin(ap));
|
|
227
|
+
if ((da0 -= p0 * 2) > eps) {
|
|
228
|
+
p0 *= cw
|
|
229
|
+
? 1
|
|
230
|
+
: -1;
|
|
231
|
+
a00 += p0;
|
|
232
|
+
a10 -= p0;
|
|
233
|
+
} else {
|
|
234
|
+
da0 = 0;
|
|
235
|
+
a00 = a10 = (a0 + a1) / 2;
|
|
236
|
+
}
|
|
237
|
+
if ((da1 -= p1 * 2) > eps) {
|
|
238
|
+
p1 *= cw
|
|
239
|
+
? 1
|
|
240
|
+
: -1;
|
|
241
|
+
a01 += p1;
|
|
242
|
+
a11 -= p1;
|
|
243
|
+
} else {
|
|
244
|
+
da1 = 0;
|
|
245
|
+
a01 = a11 = (a0 + a1) / 2;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
x01 = r1 * cos(a01);
|
|
249
|
+
y01 = r1 * sin(a01);
|
|
250
|
+
x10 = r0 * cos(a10);
|
|
251
|
+
y10 = r0 * sin(a10);
|
|
252
|
+
if (rc > eps) {
|
|
253
|
+
x11 = r1 * cos(a11);
|
|
254
|
+
y11 = r1 * sin(a11);
|
|
255
|
+
x00 = r0 * cos(a00);
|
|
256
|
+
y00 = r0 * sin(a00);
|
|
257
|
+
if (da < pi) {
|
|
258
|
+
if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
|
|
259
|
+
ax = x01 - oc[0];
|
|
260
|
+
ay = y01 - oc[1];
|
|
261
|
+
bx = x11 - oc[0];
|
|
262
|
+
by = y11 - oc[1];
|
|
263
|
+
kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2);
|
|
264
|
+
lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
|
265
|
+
rc0 = min(rc, (r0 - lc) / (kc - 1));
|
|
266
|
+
rc1 = min(rc, (r1 - lc) / (kc + 1));
|
|
267
|
+
} else {
|
|
268
|
+
rc0 = rc1 = 0;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!(da1 > eps)) {
|
|
273
|
+
ctx.moveTo(x01, y01);
|
|
274
|
+
} else if (rc1 > eps) {
|
|
275
|
+
t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
|
276
|
+
t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
|
277
|
+
ctx.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
278
|
+
if (rc1 < rc) {
|
|
279
|
+
ctx.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
|
280
|
+
} else {
|
|
281
|
+
ctx.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
|
282
|
+
ctx.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
|
|
283
|
+
ctx.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
ctx.moveTo(x01, y01);
|
|
287
|
+
ctx.arc(0, 0, r1, a01, a11, !cw);
|
|
288
|
+
}
|
|
289
|
+
if (!(r0 > eps) || !(da0 > eps)) {
|
|
290
|
+
ctx.lineTo(x10, y10);
|
|
291
|
+
} else if (rc0 > eps) {
|
|
292
|
+
t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
|
293
|
+
t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
|
294
|
+
ctx.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
295
|
+
if (rc0 < rc) {
|
|
296
|
+
ctx.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
|
297
|
+
} else {
|
|
298
|
+
ctx.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
|
299
|
+
ctx.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
|
|
300
|
+
ctx.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
ctx.arc(0, 0, r0, a10, a00, cw);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
ctx.closePath();
|
|
307
|
+
return ctx.toString() || null;
|
|
308
|
+
};
|
|
309
|
+
shape.centroid = function(){
|
|
310
|
+
var r, a;
|
|
311
|
+
r = (+inner.apply(this, arguments) + +outer.apply(this, arguments)) / 2;
|
|
312
|
+
a = (+start.apply(this, arguments) + +end.apply(this, arguments)) / 2 - pi / 2;
|
|
313
|
+
return [cos(a) * r, sin(a) * r];
|
|
314
|
+
};
|
|
315
|
+
shape.innerRadius = function(it){
|
|
316
|
+
if (!arguments.length) {
|
|
317
|
+
return inner;
|
|
318
|
+
}
|
|
319
|
+
inner = accessor(it);
|
|
320
|
+
return shape;
|
|
321
|
+
};
|
|
322
|
+
shape.outerRadius = function(it){
|
|
323
|
+
if (!arguments.length) {
|
|
324
|
+
return outer;
|
|
325
|
+
}
|
|
326
|
+
outer = accessor(it);
|
|
327
|
+
return shape;
|
|
328
|
+
};
|
|
329
|
+
shape.cornerRadius = function(it){
|
|
330
|
+
if (!arguments.length) {
|
|
331
|
+
return corner;
|
|
332
|
+
}
|
|
333
|
+
corner = accessor(it);
|
|
334
|
+
return shape;
|
|
335
|
+
};
|
|
336
|
+
shape.padRadius = function(it){
|
|
337
|
+
if (!arguments.length) {
|
|
338
|
+
return padRadius;
|
|
339
|
+
}
|
|
340
|
+
padRadius = it != null ? accessor(it) : null;
|
|
341
|
+
return shape;
|
|
342
|
+
};
|
|
343
|
+
shape.startAngle = function(it){
|
|
344
|
+
if (!arguments.length) {
|
|
345
|
+
return start;
|
|
346
|
+
}
|
|
347
|
+
start = accessor(it);
|
|
348
|
+
return shape;
|
|
349
|
+
};
|
|
350
|
+
shape.endAngle = function(it){
|
|
351
|
+
if (!arguments.length) {
|
|
352
|
+
return end;
|
|
353
|
+
}
|
|
354
|
+
end = accessor(it);
|
|
355
|
+
return shape;
|
|
356
|
+
};
|
|
357
|
+
shape.padAngle = function(it){
|
|
358
|
+
if (!arguments.length) {
|
|
359
|
+
return pad;
|
|
360
|
+
}
|
|
361
|
+
pad = accessor(it);
|
|
362
|
+
return shape;
|
|
363
|
+
};
|
|
364
|
+
shape.digits = function(it){
|
|
365
|
+
if (!arguments.length) {
|
|
366
|
+
return digits;
|
|
367
|
+
}
|
|
368
|
+
digits = it != null ? Math.floor(it) : null;
|
|
369
|
+
return shape;
|
|
370
|
+
};
|
|
371
|
+
return shape;
|
|
372
|
+
};
|
|
373
|
+
Linear = function(ctx){
|
|
374
|
+
this._context = ctx;
|
|
375
|
+
return this;
|
|
376
|
+
};
|
|
377
|
+
Linear.prototype = {
|
|
378
|
+
areaStart: function(){
|
|
379
|
+
return this._line = 0;
|
|
380
|
+
},
|
|
381
|
+
areaEnd: function(){
|
|
382
|
+
return this._line = NaN;
|
|
383
|
+
},
|
|
384
|
+
lineStart: function(){
|
|
385
|
+
return this._point = 0;
|
|
386
|
+
},
|
|
387
|
+
lineEnd: function(){
|
|
388
|
+
if (this._line || (this._line !== 0 && this._point === 1)) {
|
|
389
|
+
this._context.closePath();
|
|
390
|
+
}
|
|
391
|
+
return this._line = 1 - this._line;
|
|
392
|
+
},
|
|
393
|
+
point: function(x, y){
|
|
394
|
+
var ref$;
|
|
395
|
+
ref$ = [+x, +y], x = ref$[0], y = ref$[1];
|
|
396
|
+
if (this._point === 0) {
|
|
397
|
+
this._point = 1;
|
|
398
|
+
if (this._line) {
|
|
399
|
+
return this._context.lineTo(x, y);
|
|
400
|
+
} else {
|
|
401
|
+
return this._context.moveTo(x, y);
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
this._point = 2;
|
|
405
|
+
return this._context.lineTo(x, y);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
curveLinear = function(ctx){
|
|
410
|
+
return new Linear(ctx);
|
|
411
|
+
};
|
|
412
|
+
cardinalPoint = function(o, x, y){
|
|
413
|
+
var k;
|
|
414
|
+
k = o._k;
|
|
415
|
+
return o._context.bezierCurveTo(o._x1 + k * (o._x2 - o._x0), o._y1 + k * (o._y2 - o._y0), o._x2 + k * (o._x1 - x), o._y2 + k * (o._y1 - y), o._x2, o._y2);
|
|
416
|
+
};
|
|
417
|
+
Cardinal = function(ctx, tension){
|
|
418
|
+
this._context = ctx;
|
|
419
|
+
this._k = (1 - tension) / 6;
|
|
420
|
+
return this;
|
|
421
|
+
};
|
|
422
|
+
Cardinal.prototype = {
|
|
423
|
+
areaStart: function(){
|
|
424
|
+
return this._line = 0;
|
|
425
|
+
},
|
|
426
|
+
areaEnd: function(){
|
|
427
|
+
return this._line = NaN;
|
|
428
|
+
},
|
|
429
|
+
lineStart: function(){
|
|
430
|
+
this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
|
|
431
|
+
return this._point = 0;
|
|
432
|
+
},
|
|
433
|
+
lineEnd: function(){
|
|
434
|
+
if (this._point === 2) {
|
|
435
|
+
this._context.lineTo(this._x2, this._y2);
|
|
436
|
+
} else if (this._point === 3) {
|
|
437
|
+
cardinalPoint(this, this._x1, this._y1);
|
|
438
|
+
}
|
|
439
|
+
if (this._line || (this._line !== 0 && this._point === 1)) {
|
|
440
|
+
this._context.closePath();
|
|
441
|
+
}
|
|
442
|
+
return this._line = 1 - this._line;
|
|
443
|
+
},
|
|
444
|
+
point: function(x, y){
|
|
445
|
+
var ref$;
|
|
446
|
+
ref$ = [+x, +y], x = ref$[0], y = ref$[1];
|
|
447
|
+
if (this._point === 0) {
|
|
448
|
+
this._point = 1;
|
|
449
|
+
if (this._line) {
|
|
450
|
+
this._context.lineTo(x, y);
|
|
451
|
+
} else {
|
|
452
|
+
this._context.moveTo(x, y);
|
|
453
|
+
}
|
|
454
|
+
} else if (this._point === 1) {
|
|
455
|
+
this._point = 2;
|
|
456
|
+
this._x1 = x;
|
|
457
|
+
this._y1 = y;
|
|
458
|
+
} else {
|
|
459
|
+
this._point = 3;
|
|
460
|
+
cardinalPoint(this, x, y);
|
|
461
|
+
}
|
|
462
|
+
ref$ = [this._x1, this._x2, x], this._x0 = ref$[0], this._x1 = ref$[1], this._x2 = ref$[2];
|
|
463
|
+
return ref$ = [this._y1, this._y2, y], this._y0 = ref$[0], this._y1 = ref$[1], this._y2 = ref$[2], ref$;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
catmullPoint = function(o, x, y){
|
|
467
|
+
var ref$, x1, y1, x2, y2, a, n, b, m;
|
|
468
|
+
ref$ = [o._x1, o._y1, o._x2, o._y2], x1 = ref$[0], y1 = ref$[1], x2 = ref$[2], y2 = ref$[3];
|
|
469
|
+
if (o._l01_a > eps) {
|
|
470
|
+
a = 2 * o._l01_2a + 3 * o._l01_a * o._l12_a + o._l12_2a;
|
|
471
|
+
n = 3 * o._l01_a * (o._l01_a + o._l12_a);
|
|
472
|
+
x1 = (x1 * a - o._x0 * o._l12_2a + o._x2 * o._l01_2a) / n;
|
|
473
|
+
y1 = (y1 * a - o._y0 * o._l12_2a + o._y2 * o._l01_2a) / n;
|
|
474
|
+
}
|
|
475
|
+
if (o._l23_a > eps) {
|
|
476
|
+
b = 2 * o._l23_2a + 3 * o._l23_a * o._l12_a + o._l12_2a;
|
|
477
|
+
m = 3 * o._l23_a * (o._l23_a + o._l12_a);
|
|
478
|
+
x2 = (x2 * b + o._x1 * o._l23_2a - x * o._l12_2a) / m;
|
|
479
|
+
y2 = (y2 * b + o._y1 * o._l23_2a - y * o._l12_2a) / m;
|
|
480
|
+
}
|
|
481
|
+
return o._context.bezierCurveTo(x1, y1, x2, y2, o._x2, o._y2);
|
|
482
|
+
};
|
|
483
|
+
CatmullRom = function(ctx, alpha){
|
|
484
|
+
this._context = ctx;
|
|
485
|
+
this._alpha = alpha;
|
|
486
|
+
return this;
|
|
487
|
+
};
|
|
488
|
+
CatmullRom.prototype = {
|
|
489
|
+
areaStart: function(){
|
|
490
|
+
return this._line = 0;
|
|
491
|
+
},
|
|
492
|
+
areaEnd: function(){
|
|
493
|
+
return this._line = NaN;
|
|
494
|
+
},
|
|
495
|
+
lineStart: function(){
|
|
496
|
+
this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
|
|
497
|
+
return this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
|
|
498
|
+
},
|
|
499
|
+
lineEnd: function(){
|
|
500
|
+
if (this._point === 2) {
|
|
501
|
+
this._context.lineTo(this._x2, this._y2);
|
|
502
|
+
} else if (this._point === 3) {
|
|
503
|
+
this.point(this._x2, this._y2);
|
|
504
|
+
}
|
|
505
|
+
if (this._line || (this._line !== 0 && this._point === 1)) {
|
|
506
|
+
this._context.closePath();
|
|
507
|
+
}
|
|
508
|
+
return this._line = 1 - this._line;
|
|
509
|
+
},
|
|
510
|
+
point: function(x, y){
|
|
511
|
+
var ref$, x23, y23;
|
|
512
|
+
ref$ = [+x, +y], x = ref$[0], y = ref$[1];
|
|
513
|
+
if (this._point) {
|
|
514
|
+
x23 = this._x2 - x;
|
|
515
|
+
y23 = this._y2 - y;
|
|
516
|
+
this._l23_a = sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
|
517
|
+
}
|
|
518
|
+
if (this._point === 0) {
|
|
519
|
+
this._point = 1;
|
|
520
|
+
if (this._line) {
|
|
521
|
+
this._context.lineTo(x, y);
|
|
522
|
+
} else {
|
|
523
|
+
this._context.moveTo(x, y);
|
|
524
|
+
}
|
|
525
|
+
} else if (this._point === 1) {
|
|
526
|
+
this._point = 2;
|
|
527
|
+
} else {
|
|
528
|
+
this._point = 3;
|
|
529
|
+
catmullPoint(this, x, y);
|
|
530
|
+
}
|
|
531
|
+
ref$ = [this._l12_a, this._l23_a], this._l01_a = ref$[0], this._l12_a = ref$[1];
|
|
532
|
+
ref$ = [this._l12_2a, this._l23_2a], this._l01_2a = ref$[0], this._l12_2a = ref$[1];
|
|
533
|
+
ref$ = [this._x1, this._x2, x], this._x0 = ref$[0], this._x1 = ref$[1], this._x2 = ref$[2];
|
|
534
|
+
return ref$ = [this._y1, this._y2, y], this._y0 = ref$[0], this._y1 = ref$[1], this._y2 = ref$[2], ref$;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
catmullRom = (custom = function(alpha){
|
|
538
|
+
var f;
|
|
539
|
+
f = function(ctx){
|
|
540
|
+
if (alpha) {
|
|
541
|
+
return new CatmullRom(ctx, alpha);
|
|
542
|
+
} else {
|
|
543
|
+
return new Cardinal(ctx, 0);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
f.alpha = function(a){
|
|
547
|
+
return custom(+a);
|
|
548
|
+
};
|
|
549
|
+
return f;
|
|
550
|
+
}, custom(0.5));
|
|
551
|
+
curve = {
|
|
552
|
+
linear: curveLinear,
|
|
553
|
+
catmullRom: catmullRom
|
|
554
|
+
};
|
|
555
|
+
asArray = function(x){
|
|
556
|
+
if (typeof x === 'object' && 'length' in x) {
|
|
557
|
+
return x;
|
|
558
|
+
} else {
|
|
559
|
+
return Array.from(x);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
line = function(x, y){
|
|
563
|
+
var defined, cv, digits, fx, fy, shape;
|
|
564
|
+
defined = constant(true);
|
|
565
|
+
cv = curveLinear;
|
|
566
|
+
digits = 3;
|
|
567
|
+
fx = typeof x === 'function'
|
|
568
|
+
? x
|
|
569
|
+
: x === undefined
|
|
570
|
+
? function(p){
|
|
571
|
+
return p[0];
|
|
572
|
+
}
|
|
573
|
+
: constant(x);
|
|
574
|
+
fy = typeof y === 'function'
|
|
575
|
+
? y
|
|
576
|
+
: y === undefined
|
|
577
|
+
? function(p){
|
|
578
|
+
return p[1];
|
|
579
|
+
}
|
|
580
|
+
: constant(y);
|
|
581
|
+
shape = function(data){
|
|
582
|
+
var n, defined0, out, buf, i$, i, ok, d;
|
|
583
|
+
data = asArray(data);
|
|
584
|
+
n = data.length;
|
|
585
|
+
defined0 = false;
|
|
586
|
+
out = cv(buf = new Path(digits));
|
|
587
|
+
for (i$ = 0; i$ <= n; ++i$) {
|
|
588
|
+
i = i$;
|
|
589
|
+
ok = false;
|
|
590
|
+
if (i < n) {
|
|
591
|
+
d = data[i];
|
|
592
|
+
ok = !!defined(d, i, data);
|
|
593
|
+
}
|
|
594
|
+
if (!ok === defined0) {
|
|
595
|
+
defined0 = !defined0;
|
|
596
|
+
if (defined0) {
|
|
597
|
+
out.lineStart();
|
|
598
|
+
} else {
|
|
599
|
+
out.lineEnd();
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (defined0) {
|
|
603
|
+
out.point(+fx(d, i, data), +fy(d, i, data));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return buf.toString() || null;
|
|
607
|
+
};
|
|
608
|
+
shape.x = function(it){
|
|
609
|
+
if (!arguments.length) {
|
|
610
|
+
return fx;
|
|
611
|
+
}
|
|
612
|
+
fx = accessor(it);
|
|
613
|
+
return shape;
|
|
614
|
+
};
|
|
615
|
+
shape.y = function(it){
|
|
616
|
+
if (!arguments.length) {
|
|
617
|
+
return fy;
|
|
618
|
+
}
|
|
619
|
+
fy = accessor(it);
|
|
620
|
+
return shape;
|
|
621
|
+
};
|
|
622
|
+
shape.defined = function(it){
|
|
623
|
+
if (!arguments.length) {
|
|
624
|
+
return defined;
|
|
625
|
+
}
|
|
626
|
+
defined = typeof it === 'function'
|
|
627
|
+
? it
|
|
628
|
+
: constant(!!it);
|
|
629
|
+
return shape;
|
|
630
|
+
};
|
|
631
|
+
shape.curve = function(it){
|
|
632
|
+
if (!arguments.length) {
|
|
633
|
+
return cv;
|
|
634
|
+
}
|
|
635
|
+
cv = it;
|
|
636
|
+
return shape;
|
|
637
|
+
};
|
|
638
|
+
shape.digits = function(it){
|
|
639
|
+
if (!arguments.length) {
|
|
640
|
+
return digits;
|
|
641
|
+
}
|
|
642
|
+
digits = it != null ? Math.floor(it) : null;
|
|
643
|
+
return shape;
|
|
644
|
+
};
|
|
645
|
+
return shape;
|
|
646
|
+
};
|
|
647
|
+
area = function(x0, y0, y1){
|
|
648
|
+
var x1, defined, cv, digits, shape;
|
|
649
|
+
x1 = null;
|
|
650
|
+
defined = constant(true);
|
|
651
|
+
cv = curveLinear;
|
|
652
|
+
digits = 3;
|
|
653
|
+
x0 = typeof x0 === 'function'
|
|
654
|
+
? x0
|
|
655
|
+
: x0 === undefined
|
|
656
|
+
? function(p){
|
|
657
|
+
return p[0];
|
|
658
|
+
}
|
|
659
|
+
: constant(+x0);
|
|
660
|
+
y0 = typeof y0 === 'function'
|
|
661
|
+
? y0
|
|
662
|
+
: y0 === undefined
|
|
663
|
+
? constant(0)
|
|
664
|
+
: constant(+y0);
|
|
665
|
+
y1 = typeof y1 === 'function'
|
|
666
|
+
? y1
|
|
667
|
+
: y1 === undefined
|
|
668
|
+
? function(p){
|
|
669
|
+
return p[1];
|
|
670
|
+
}
|
|
671
|
+
: constant(+y1);
|
|
672
|
+
shape = function(data){
|
|
673
|
+
var n, defined0, x0z, y0z, j, out, buf, i$, i, ok, d, k;
|
|
674
|
+
data = asArray(data);
|
|
675
|
+
n = data.length;
|
|
676
|
+
defined0 = false;
|
|
677
|
+
x0z = new Array(n);
|
|
678
|
+
y0z = new Array(n);
|
|
679
|
+
j = 0;
|
|
680
|
+
out = cv(buf = new Path(digits));
|
|
681
|
+
for (i$ = 0; i$ <= n; ++i$) {
|
|
682
|
+
i = i$;
|
|
683
|
+
ok = false;
|
|
684
|
+
if (i < n) {
|
|
685
|
+
d = data[i];
|
|
686
|
+
ok = !!defined(d, i, data);
|
|
687
|
+
}
|
|
688
|
+
if (!ok === defined0) {
|
|
689
|
+
defined0 = !defined0;
|
|
690
|
+
if (defined0) {
|
|
691
|
+
j = i;
|
|
692
|
+
out.areaStart();
|
|
693
|
+
out.lineStart();
|
|
694
|
+
} else {
|
|
695
|
+
out.lineEnd();
|
|
696
|
+
out.lineStart();
|
|
697
|
+
k = i - 1;
|
|
698
|
+
while (k >= j) {
|
|
699
|
+
out.point(x0z[k], y0z[k]);
|
|
700
|
+
k--;
|
|
701
|
+
}
|
|
702
|
+
out.lineEnd();
|
|
703
|
+
out.areaEnd();
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (defined0) {
|
|
707
|
+
x0z[i] = +x0(d, i, data);
|
|
708
|
+
y0z[i] = +y0(d, i, data);
|
|
709
|
+
out.point(x1
|
|
710
|
+
? +x1(d, i, data)
|
|
711
|
+
: x0z[i], y1
|
|
712
|
+
? +y1(d, i, data)
|
|
713
|
+
: y0z[i]);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return buf.toString() || null;
|
|
717
|
+
};
|
|
718
|
+
shape.x = function(it){
|
|
719
|
+
if (!arguments.length) {
|
|
720
|
+
return x0;
|
|
721
|
+
}
|
|
722
|
+
x0 = accessor(it);
|
|
723
|
+
x1 = null;
|
|
724
|
+
return shape;
|
|
725
|
+
};
|
|
726
|
+
shape.x0 = function(it){
|
|
727
|
+
if (!arguments.length) {
|
|
728
|
+
return x0;
|
|
729
|
+
}
|
|
730
|
+
x0 = accessor(it);
|
|
731
|
+
return shape;
|
|
732
|
+
};
|
|
733
|
+
shape.x1 = function(it){
|
|
734
|
+
if (!arguments.length) {
|
|
735
|
+
return x1;
|
|
736
|
+
}
|
|
737
|
+
x1 = it != null ? accessor(it) : null;
|
|
738
|
+
return shape;
|
|
739
|
+
};
|
|
740
|
+
shape.y = function(it){
|
|
741
|
+
if (!arguments.length) {
|
|
742
|
+
return y0;
|
|
743
|
+
}
|
|
744
|
+
y0 = accessor(it);
|
|
745
|
+
y1 = null;
|
|
746
|
+
return shape;
|
|
747
|
+
};
|
|
748
|
+
shape.y0 = function(it){
|
|
749
|
+
if (!arguments.length) {
|
|
750
|
+
return y0;
|
|
751
|
+
}
|
|
752
|
+
y0 = accessor(it);
|
|
753
|
+
return shape;
|
|
754
|
+
};
|
|
755
|
+
shape.y1 = function(it){
|
|
756
|
+
if (!arguments.length) {
|
|
757
|
+
return y1;
|
|
758
|
+
}
|
|
759
|
+
y1 = it != null ? accessor(it) : null;
|
|
760
|
+
return shape;
|
|
761
|
+
};
|
|
762
|
+
shape.defined = function(it){
|
|
763
|
+
if (!arguments.length) {
|
|
764
|
+
return defined;
|
|
765
|
+
}
|
|
766
|
+
defined = typeof it === 'function'
|
|
767
|
+
? it
|
|
768
|
+
: constant(!!it);
|
|
769
|
+
return shape;
|
|
770
|
+
};
|
|
771
|
+
shape.curve = function(it){
|
|
772
|
+
if (!arguments.length) {
|
|
773
|
+
return cv;
|
|
774
|
+
}
|
|
775
|
+
cv = it;
|
|
776
|
+
return shape;
|
|
777
|
+
};
|
|
778
|
+
shape.digits = function(it){
|
|
779
|
+
if (!arguments.length) {
|
|
780
|
+
return digits;
|
|
781
|
+
}
|
|
782
|
+
digits = it != null ? Math.floor(it) : null;
|
|
783
|
+
return shape;
|
|
784
|
+
};
|
|
785
|
+
return shape;
|
|
786
|
+
};
|
|
787
|
+
shape = {
|
|
788
|
+
arc: arc,
|
|
789
|
+
line: line,
|
|
790
|
+
area: area,
|
|
791
|
+
curve: curve,
|
|
792
|
+
path: function(digits){
|
|
793
|
+
return new Path(digits);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
if (typeof chart != 'undefined' && chart !== null) {
|
|
797
|
+
(chart.utils || (chart.utils = {})).shape = shape;
|
|
798
|
+
}
|
|
799
|
+
}).call(this);
|