ngx-trend 7.0.0 → 8.0.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 +8 -7
- package/{esm2015/helpers/DOM.helpers.js → esm2020/helpers/DOM.helpers.mjs} +0 -0
- package/{esm2015/helpers/math.helpers.js → esm2020/helpers/math.helpers.mjs} +0 -0
- package/{esm2015/helpers/misc.helpers.js → esm2020/helpers/misc.helpers.mjs} +0 -0
- package/{esm2015/ngx-trend.js → esm2020/ngx-trend.mjs} +0 -0
- package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
- package/esm2020/trend/trend.component.mjs +255 -0
- package/{esm2015/trend/trend.helpers.js → esm2020/trend/trend.helpers.mjs} +0 -0
- package/esm2020/trend/trend.module.mjs +18 -0
- package/fesm2015/{ngx-trend.js → ngx-trend.mjs} +148 -60
- package/fesm2015/ngx-trend.mjs.map +1 -0
- package/fesm2020/ngx-trend.mjs +402 -0
- package/fesm2020/ngx-trend.mjs.map +1 -0
- package/ngx-trend.d.ts +1 -0
- package/package.json +23 -11
- package/trend/trend.component.d.ts +3 -0
- package/trend/trend.module.d.ts +6 -0
- package/bundles/ngx-trend.umd.js +0 -604
- package/bundles/ngx-trend.umd.js.map +0 -1
- package/esm2015/trend/trend.component.js +0 -171
- package/esm2015/trend/trend.module.js +0 -13
- package/fesm2015/ngx-trend.js.map +0 -1
- package/ngx-trend.metadata.json +0 -1
package/bundles/ngx-trend.umd.js
DELETED
@@ -1,604 +0,0 @@
|
|
1
|
-
(function (global, factory) {
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('@angular/core'), require('@angular/common')) :
|
3
|
-
typeof define === 'function' && define.amd ? define('ngx-trend', ['exports', '@angular/animations', '@angular/core', '@angular/common'], factory) :
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-trend'] = {}, global.ng.animations, global.ng.core, global.ng.common));
|
5
|
-
}(this, (function (exports, animations, core, common) { 'use strict';
|
6
|
-
|
7
|
-
/*! *****************************************************************************
|
8
|
-
Copyright (c) Microsoft Corporation.
|
9
|
-
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
11
|
-
purpose with or without fee is hereby granted.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
20
|
-
***************************************************************************** */
|
21
|
-
/* global Reflect, Promise */
|
22
|
-
var extendStatics = function (d, b) {
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
25
|
-
function (d, b) { for (var p in b)
|
26
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
27
|
-
d[p] = b[p]; };
|
28
|
-
return extendStatics(d, b);
|
29
|
-
};
|
30
|
-
function __extends(d, b) {
|
31
|
-
if (typeof b !== "function" && b !== null)
|
32
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
33
|
-
extendStatics(d, b);
|
34
|
-
function __() { this.constructor = d; }
|
35
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
36
|
-
}
|
37
|
-
var __assign = function () {
|
38
|
-
__assign = Object.assign || function __assign(t) {
|
39
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
40
|
-
s = arguments[i];
|
41
|
-
for (var p in s)
|
42
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
43
|
-
t[p] = s[p];
|
44
|
-
}
|
45
|
-
return t;
|
46
|
-
};
|
47
|
-
return __assign.apply(this, arguments);
|
48
|
-
};
|
49
|
-
function __rest(s, e) {
|
50
|
-
var t = {};
|
51
|
-
for (var p in s)
|
52
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
53
|
-
t[p] = s[p];
|
54
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
55
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
56
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
57
|
-
t[p[i]] = s[p[i]];
|
58
|
-
}
|
59
|
-
return t;
|
60
|
-
}
|
61
|
-
function __decorate(decorators, target, key, desc) {
|
62
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
63
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
64
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
65
|
-
else
|
66
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
67
|
-
if (d = decorators[i])
|
68
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
69
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
70
|
-
}
|
71
|
-
function __param(paramIndex, decorator) {
|
72
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
73
|
-
}
|
74
|
-
function __metadata(metadataKey, metadataValue) {
|
75
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
76
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
77
|
-
}
|
78
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
79
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
80
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
81
|
-
function fulfilled(value) { try {
|
82
|
-
step(generator.next(value));
|
83
|
-
}
|
84
|
-
catch (e) {
|
85
|
-
reject(e);
|
86
|
-
} }
|
87
|
-
function rejected(value) { try {
|
88
|
-
step(generator["throw"](value));
|
89
|
-
}
|
90
|
-
catch (e) {
|
91
|
-
reject(e);
|
92
|
-
} }
|
93
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
94
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
95
|
-
});
|
96
|
-
}
|
97
|
-
function __generator(thisArg, body) {
|
98
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
99
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
100
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
101
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
102
|
-
function step(op) {
|
103
|
-
if (f)
|
104
|
-
throw new TypeError("Generator is already executing.");
|
105
|
-
while (_)
|
106
|
-
try {
|
107
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
108
|
-
return t;
|
109
|
-
if (y = 0, t)
|
110
|
-
op = [op[0] & 2, t.value];
|
111
|
-
switch (op[0]) {
|
112
|
-
case 0:
|
113
|
-
case 1:
|
114
|
-
t = op;
|
115
|
-
break;
|
116
|
-
case 4:
|
117
|
-
_.label++;
|
118
|
-
return { value: op[1], done: false };
|
119
|
-
case 5:
|
120
|
-
_.label++;
|
121
|
-
y = op[1];
|
122
|
-
op = [0];
|
123
|
-
continue;
|
124
|
-
case 7:
|
125
|
-
op = _.ops.pop();
|
126
|
-
_.trys.pop();
|
127
|
-
continue;
|
128
|
-
default:
|
129
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
130
|
-
_ = 0;
|
131
|
-
continue;
|
132
|
-
}
|
133
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
134
|
-
_.label = op[1];
|
135
|
-
break;
|
136
|
-
}
|
137
|
-
if (op[0] === 6 && _.label < t[1]) {
|
138
|
-
_.label = t[1];
|
139
|
-
t = op;
|
140
|
-
break;
|
141
|
-
}
|
142
|
-
if (t && _.label < t[2]) {
|
143
|
-
_.label = t[2];
|
144
|
-
_.ops.push(op);
|
145
|
-
break;
|
146
|
-
}
|
147
|
-
if (t[2])
|
148
|
-
_.ops.pop();
|
149
|
-
_.trys.pop();
|
150
|
-
continue;
|
151
|
-
}
|
152
|
-
op = body.call(thisArg, _);
|
153
|
-
}
|
154
|
-
catch (e) {
|
155
|
-
op = [6, e];
|
156
|
-
y = 0;
|
157
|
-
}
|
158
|
-
finally {
|
159
|
-
f = t = 0;
|
160
|
-
}
|
161
|
-
if (op[0] & 5)
|
162
|
-
throw op[1];
|
163
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
164
|
-
}
|
165
|
-
}
|
166
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
167
|
-
if (k2 === undefined)
|
168
|
-
k2 = k;
|
169
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
170
|
-
}) : (function (o, m, k, k2) {
|
171
|
-
if (k2 === undefined)
|
172
|
-
k2 = k;
|
173
|
-
o[k2] = m[k];
|
174
|
-
});
|
175
|
-
function __exportStar(m, o) {
|
176
|
-
for (var p in m)
|
177
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
178
|
-
__createBinding(o, m, p);
|
179
|
-
}
|
180
|
-
function __values(o) {
|
181
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
182
|
-
if (m)
|
183
|
-
return m.call(o);
|
184
|
-
if (o && typeof o.length === "number")
|
185
|
-
return {
|
186
|
-
next: function () {
|
187
|
-
if (o && i >= o.length)
|
188
|
-
o = void 0;
|
189
|
-
return { value: o && o[i++], done: !o };
|
190
|
-
}
|
191
|
-
};
|
192
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
193
|
-
}
|
194
|
-
function __read(o, n) {
|
195
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
196
|
-
if (!m)
|
197
|
-
return o;
|
198
|
-
var i = m.call(o), r, ar = [], e;
|
199
|
-
try {
|
200
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
201
|
-
ar.push(r.value);
|
202
|
-
}
|
203
|
-
catch (error) {
|
204
|
-
e = { error: error };
|
205
|
-
}
|
206
|
-
finally {
|
207
|
-
try {
|
208
|
-
if (r && !r.done && (m = i["return"]))
|
209
|
-
m.call(i);
|
210
|
-
}
|
211
|
-
finally {
|
212
|
-
if (e)
|
213
|
-
throw e.error;
|
214
|
-
}
|
215
|
-
}
|
216
|
-
return ar;
|
217
|
-
}
|
218
|
-
/** @deprecated */
|
219
|
-
function __spread() {
|
220
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
221
|
-
ar = ar.concat(__read(arguments[i]));
|
222
|
-
return ar;
|
223
|
-
}
|
224
|
-
/** @deprecated */
|
225
|
-
function __spreadArrays() {
|
226
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
227
|
-
s += arguments[i].length;
|
228
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
229
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
230
|
-
r[k] = a[j];
|
231
|
-
return r;
|
232
|
-
}
|
233
|
-
function __spreadArray(to, from) {
|
234
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
235
|
-
to[j] = from[i];
|
236
|
-
return to;
|
237
|
-
}
|
238
|
-
function __await(v) {
|
239
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
240
|
-
}
|
241
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
242
|
-
if (!Symbol.asyncIterator)
|
243
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
244
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
245
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
246
|
-
function verb(n) { if (g[n])
|
247
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
248
|
-
function resume(n, v) { try {
|
249
|
-
step(g[n](v));
|
250
|
-
}
|
251
|
-
catch (e) {
|
252
|
-
settle(q[0][3], e);
|
253
|
-
} }
|
254
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
255
|
-
function fulfill(value) { resume("next", value); }
|
256
|
-
function reject(value) { resume("throw", value); }
|
257
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
258
|
-
resume(q[0][0], q[0][1]); }
|
259
|
-
}
|
260
|
-
function __asyncDelegator(o) {
|
261
|
-
var i, p;
|
262
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
263
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
264
|
-
}
|
265
|
-
function __asyncValues(o) {
|
266
|
-
if (!Symbol.asyncIterator)
|
267
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
268
|
-
var m = o[Symbol.asyncIterator], i;
|
269
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
270
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
271
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
272
|
-
}
|
273
|
-
function __makeTemplateObject(cooked, raw) {
|
274
|
-
if (Object.defineProperty) {
|
275
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
276
|
-
}
|
277
|
-
else {
|
278
|
-
cooked.raw = raw;
|
279
|
-
}
|
280
|
-
return cooked;
|
281
|
-
}
|
282
|
-
;
|
283
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
284
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
285
|
-
}) : function (o, v) {
|
286
|
-
o["default"] = v;
|
287
|
-
};
|
288
|
-
function __importStar(mod) {
|
289
|
-
if (mod && mod.__esModule)
|
290
|
-
return mod;
|
291
|
-
var result = {};
|
292
|
-
if (mod != null)
|
293
|
-
for (var k in mod)
|
294
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
295
|
-
__createBinding(result, mod, k);
|
296
|
-
__setModuleDefault(result, mod);
|
297
|
-
return result;
|
298
|
-
}
|
299
|
-
function __importDefault(mod) {
|
300
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
301
|
-
}
|
302
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
303
|
-
if (kind === "a" && !f)
|
304
|
-
throw new TypeError("Private accessor was defined without a getter");
|
305
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
306
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
307
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
308
|
-
}
|
309
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
310
|
-
if (kind === "m")
|
311
|
-
throw new TypeError("Private method is not writable");
|
312
|
-
if (kind === "a" && !f)
|
313
|
-
throw new TypeError("Private accessor was defined without a setter");
|
314
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
315
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
316
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
317
|
-
}
|
318
|
-
|
319
|
-
/* eslint-disable no-restricted-properties */
|
320
|
-
/** normalize
|
321
|
-
* This lets us translate a value from one scale to another.
|
322
|
-
*
|
323
|
-
* @param value - Our initial value to translate
|
324
|
-
* @param min - the current minimum value possible
|
325
|
-
* @param max - the current maximum value possible
|
326
|
-
* @param scaleMin - the min value of the scale we're translating to
|
327
|
-
* @param scaleMax - the max value of the scale we're translating to
|
328
|
-
* @returns the value on its new scale
|
329
|
-
*/
|
330
|
-
function normalize(value, min, max, scaleMin, scaleMax) {
|
331
|
-
if (scaleMin === void 0) { scaleMin = 0; }
|
332
|
-
if (scaleMax === void 0) { scaleMax = 1; }
|
333
|
-
// If the `min` and `max` are the same value, it means our dataset is flat.
|
334
|
-
// For now, let's assume that flat data should be aligned to the bottom.
|
335
|
-
if (min === max) {
|
336
|
-
return scaleMin;
|
337
|
-
}
|
338
|
-
return scaleMin + (value - min) * (scaleMax - scaleMin) / (max - min);
|
339
|
-
}
|
340
|
-
/** moveTo
|
341
|
-
* the coordinate that lies at a midpoint between 2 lines, based on the radius
|
342
|
-
*
|
343
|
-
* @param to - Our initial point
|
344
|
-
* @param to.x - The x value of our initial point
|
345
|
-
* @param to.y - The y value of our initial point
|
346
|
-
* @param from - Our final point
|
347
|
-
* @param from.x - The x value of our final point
|
348
|
-
* @param from.y - The y value of our final point
|
349
|
-
* @param radius - The distance away from the final point
|
350
|
-
* @returns an object holding the x/y coordinates of the midpoint.
|
351
|
-
*/
|
352
|
-
function moveTo(to, from, radius) {
|
353
|
-
var length = Math.sqrt((to.x - from.x) * (to.x - from.x) + (to.y - from.y) * (to.y - from.y));
|
354
|
-
var unitVector = { x: (to.x - from.x) / length, y: (to.y - from.y) / length };
|
355
|
-
return {
|
356
|
-
x: from.x + unitVector.x * radius,
|
357
|
-
y: from.y + unitVector.y * radius,
|
358
|
-
};
|
359
|
-
}
|
360
|
-
/** getDistanceBetween
|
361
|
-
* Simple formula derived from pythagoras to calculate the distance between
|
362
|
-
* 2 points on a plane.
|
363
|
-
*
|
364
|
-
* @param p1 - Our initial point
|
365
|
-
* @param p1.x - The x value of our initial point
|
366
|
-
* @param p1.y - The y value of our initial point
|
367
|
-
* @param p2 - Our final point
|
368
|
-
* @param p2.x - The x value of our final point
|
369
|
-
* @param p2.y - The y value of our final point
|
370
|
-
* @returns the distance between the points.
|
371
|
-
*/
|
372
|
-
var getDistanceBetween = function (p1, p2) { return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); };
|
373
|
-
/** checkForCollinearPoints
|
374
|
-
* Figure out if the midpoint fits perfectly on a line between the two others.
|
375
|
-
*
|
376
|
-
* @param p1 - Our initial point
|
377
|
-
* @param p1.x - The x value of our initial point
|
378
|
-
* @param p1.y - The y value of our initial point
|
379
|
-
* @param p2 - Our mid-point
|
380
|
-
* @param p2.x - The x value of our mid-point
|
381
|
-
* @param p2.y - The y value of our mid-point
|
382
|
-
* @param p3 - Our final point
|
383
|
-
* @param p3.x - The x value of our final point
|
384
|
-
* @param p3.y - The y value of our final point
|
385
|
-
* @returns whether or not p2 sits on the line between p1 and p3.
|
386
|
-
*/
|
387
|
-
var checkForCollinearPoints = function (p1, p2, p3) { return (p1.y - p2.y) * (p1.x - p3.x) === (p1.y - p3.y) * (p1.x - p2.x); };
|
388
|
-
|
389
|
-
var buildLinearPath = function (data) { return data.reduce(function (path, point, index) {
|
390
|
-
// The very first instruction needs to be a "move".
|
391
|
-
// The rest will be a "line".
|
392
|
-
var isFirstInstruction = index === 0;
|
393
|
-
var instruction = isFirstInstruction ? 'M' : 'L';
|
394
|
-
return "" + path + instruction + " " + point.x + "," + point.y + "\n";
|
395
|
-
}, ''); };
|
396
|
-
function buildSmoothPath(data, radius) {
|
397
|
-
var _a = __read(data), firstPoint = _a[0], otherPoints = _a.slice(1);
|
398
|
-
return otherPoints.reduce(function (path, point, index) {
|
399
|
-
var next = otherPoints[index + 1];
|
400
|
-
var prev = otherPoints[index - 1] || firstPoint;
|
401
|
-
var isCollinear = next && checkForCollinearPoints(prev, point, next);
|
402
|
-
if (!next || isCollinear) {
|
403
|
-
// The very last line in the sequence can just be a regular line.
|
404
|
-
return path + "\nL " + point.x + "," + point.y;
|
405
|
-
}
|
406
|
-
var distanceFromPrev = getDistanceBetween(prev, point);
|
407
|
-
var distanceFromNext = getDistanceBetween(next, point);
|
408
|
-
var threshold = Math.min(distanceFromPrev, distanceFromNext);
|
409
|
-
var isTooCloseForRadius = threshold / 2 < radius;
|
410
|
-
var radiusForPoint = isTooCloseForRadius ? threshold / 2 : radius;
|
411
|
-
var before = moveTo(prev, point, radiusForPoint);
|
412
|
-
var after = moveTo(next, point, radiusForPoint);
|
413
|
-
return [
|
414
|
-
path,
|
415
|
-
"L " + before.x + "," + before.y,
|
416
|
-
"S " + point.x + "," + point.y + " " + after.x + "," + after.y,
|
417
|
-
].join('\n');
|
418
|
-
}, "M " + firstPoint.x + "," + firstPoint.y);
|
419
|
-
}
|
420
|
-
|
421
|
-
var generateId = function () { return Math.round(Math.random() * Math.pow(10, 16)); };
|
422
|
-
|
423
|
-
function normalizeDataset(data, minX, maxX, minY, maxY) {
|
424
|
-
// For the X axis, we want to normalize it based on its index in the array.
|
425
|
-
// For the Y axis, we want to normalize it based on the element's value.
|
426
|
-
//
|
427
|
-
// X axis is easy: just evenly-space each item in the array.
|
428
|
-
// For the Y axis, we first need to find the min and max of our array,
|
429
|
-
// and then normalize those values between 0 and 1.
|
430
|
-
var boundariesX = { min: 0, max: data.length - 1 };
|
431
|
-
var boundariesY = { min: Math.min.apply(Math, __spreadArray([], __read(data))), max: Math.max.apply(Math, __spreadArray([], __read(data))) };
|
432
|
-
var normalizedData = data.map(function (point, index) { return ({
|
433
|
-
x: normalize(index, boundariesX.min, boundariesX.max, minX, maxX),
|
434
|
-
y: normalize(point, boundariesY.min, boundariesY.max, minY, maxY),
|
435
|
-
}); });
|
436
|
-
// According to the SVG spec, paths with a height/width of `0` can't have
|
437
|
-
// linear gradients applied. This means that our lines are invisible when
|
438
|
-
// the dataset is flat (eg. [0, 0, 0, 0]).
|
439
|
-
//
|
440
|
-
// The hacky solution is to apply a very slight offset to the first point of
|
441
|
-
// the dataset. As ugly as it is, it's the best solution we can find (there
|
442
|
-
// are ways within the SVG spec of changing it, but not without causing
|
443
|
-
// breaking changes).
|
444
|
-
if (boundariesY.min === boundariesY.max) {
|
445
|
-
normalizedData[0].y += 0.0001;
|
446
|
-
}
|
447
|
-
return normalizedData;
|
448
|
-
}
|
449
|
-
|
450
|
-
var TrendComponent = /** @class */ (function () {
|
451
|
-
function TrendComponent() {
|
452
|
-
this.autoDraw = false;
|
453
|
-
this.autoDrawDuration = 2000;
|
454
|
-
this.autoDrawEasing = 'ease';
|
455
|
-
this.padding = 8;
|
456
|
-
this.radius = 10;
|
457
|
-
this.stroke = 'black';
|
458
|
-
this.strokeLinecap = '';
|
459
|
-
this.strokeWidth = 1;
|
460
|
-
this.gradient = [];
|
461
|
-
this.svgHeight = '25%';
|
462
|
-
this.svgWidth = '100%';
|
463
|
-
this.animationState = '';
|
464
|
-
this.id = generateId();
|
465
|
-
this.gradientId = "ngx-trend-vertical-gradient-" + this.id;
|
466
|
-
}
|
467
|
-
TrendComponent.prototype.ngOnChanges = function () {
|
468
|
-
var _this = this;
|
469
|
-
// We need at least 2 points to draw a graph.
|
470
|
-
if (!this.data || this.data.length < 2) {
|
471
|
-
return;
|
472
|
-
}
|
473
|
-
// `data` can either be an array of numbers:
|
474
|
-
// [1, 2, 3]
|
475
|
-
// or, an array of objects containing a value:
|
476
|
-
// [{ value: 1 }, { value: 2 }, { value: 3 }]
|
477
|
-
//
|
478
|
-
// For now, we're just going to convert the second form to the first.
|
479
|
-
// Later on, if/when we support tooltips, we may adjust.
|
480
|
-
var plainValues = this.data.map(function (point) {
|
481
|
-
if (typeof point === 'number') {
|
482
|
-
return point;
|
483
|
-
}
|
484
|
-
return point.value;
|
485
|
-
});
|
486
|
-
// Our viewbox needs to be in absolute units, so we'll default to 300x75
|
487
|
-
// Our SVG can be a %, though; this is what makes it scalable.
|
488
|
-
// By defaulting to percentages, the SVG will grow to fill its parent
|
489
|
-
// container, preserving a 1/4 aspect ratio.
|
490
|
-
var viewBoxWidth = this.width || 300;
|
491
|
-
var viewBoxHeight = this.height || 75;
|
492
|
-
this.svgWidth = this.width || '100%';
|
493
|
-
this.svgHeight = this.height || '25%';
|
494
|
-
this.viewBox = "0 0 " + viewBoxWidth + " " + viewBoxHeight;
|
495
|
-
var root = location.href.split(location.hash || '#')[0];
|
496
|
-
this.pathStroke =
|
497
|
-
this.gradient && this.gradient.length ? "url('" + root + "#" + this.gradientId + "')" : undefined;
|
498
|
-
this.gradientTrimmed = this.gradient
|
499
|
-
.slice()
|
500
|
-
.reverse()
|
501
|
-
.map(function (val, idx) {
|
502
|
-
return {
|
503
|
-
idx: idx,
|
504
|
-
stopColor: val,
|
505
|
-
offset: normalize(idx, 0, _this.gradient.length - 1 || 1),
|
506
|
-
};
|
507
|
-
});
|
508
|
-
var normalizedValues = normalizeDataset(plainValues, this.padding, viewBoxWidth - this.padding,
|
509
|
-
// NOTE: Because SVGs are indexed from the top left, but most data is
|
510
|
-
// indexed from the bottom left, we're inverting the Y min/max.
|
511
|
-
viewBoxHeight - this.padding, this.padding);
|
512
|
-
if (this.autoDraw && this.animationState !== 'active') {
|
513
|
-
this.animationState = 'inactive';
|
514
|
-
setTimeout(function () {
|
515
|
-
_this.lineLength = _this.pathEl.nativeElement.getTotalLength();
|
516
|
-
_this.animationState = 'active';
|
517
|
-
});
|
518
|
-
}
|
519
|
-
this.d = this.smooth
|
520
|
-
? buildSmoothPath(normalizedValues, this.radius)
|
521
|
-
: buildLinearPath(normalizedValues);
|
522
|
-
};
|
523
|
-
return TrendComponent;
|
524
|
-
}());
|
525
|
-
TrendComponent.decorators = [
|
526
|
-
{ type: core.Component, args: [{
|
527
|
-
selector: 'ngx-trend',
|
528
|
-
template: "\n <svg\n *ngIf=\"data && data.length >= 2\"\n [attr.width]=\"svgWidth\"\n [attr.height]=\"svgHeight\"\n [attr.stroke]=\"stroke\"\n [attr.stroke-width]=\"strokeWidth\"\n [attr.stroke-linecap]=\"strokeLinecap\"\n [attr.viewBox]=\"viewBox\"\n [attr.preserveAspectRatio]=\"preserveAspectRatio\"\n >\n <defs *ngIf=\"gradient && gradient.length\">\n <linearGradient [attr.id]=\"gradientId\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">\n <stop\n *ngFor=\"let g of gradientTrimmed\"\n [attr.key]=\"g.idx\"\n [attr.offset]=\"g.offset\"\n [attr.stop-color]=\"g.stopColor\"\n />\n </linearGradient>\n </defs>\n <path\n fill=\"none\"\n #pathEl\n [attr.stroke]=\"pathStroke\"\n [attr.d]=\"d\"\n [@pathAnimaiton]=\"{\n value: animationState,\n params: {\n autoDrawDuration: autoDrawDuration,\n autoDrawEasing: autoDrawEasing,\n lineLength: lineLength\n }\n }\"\n />\n </svg>\n ",
|
529
|
-
animations: [
|
530
|
-
animations.trigger('pathAnimaiton', [
|
531
|
-
animations.state('inactive', animations.style({ display: 'none' })),
|
532
|
-
animations.transition('* => active', [
|
533
|
-
animations.style({ display: 'initial' }),
|
534
|
-
// We do the animation using the dash array/offset trick
|
535
|
-
// https://css-tricks.com/svg-line-animation-works/
|
536
|
-
animations.animate('{{ autoDrawDuration }}ms {{ autoDrawEasing }}', animations.keyframes([
|
537
|
-
animations.style({
|
538
|
-
'stroke-dasharray': '{{ lineLength }}px',
|
539
|
-
'stroke-dashoffset': '{{ lineLength }}px',
|
540
|
-
}),
|
541
|
-
animations.style({
|
542
|
-
'stroke-dasharray': '{{ lineLength }}px',
|
543
|
-
'stroke-dashoffset': 0,
|
544
|
-
}),
|
545
|
-
])),
|
546
|
-
// One unfortunate side-effect of the auto-draw is that the line is
|
547
|
-
// actually 1 big dash, the same length as the line itself. If the
|
548
|
-
// line length changes (eg. radius change, new data), that dash won't
|
549
|
-
// be the same length anymore. We can fix that by removing those
|
550
|
-
// properties once the auto-draw is completed.
|
551
|
-
animations.style({
|
552
|
-
'stroke-dashoffset': '',
|
553
|
-
'stroke-dasharray': '',
|
554
|
-
}),
|
555
|
-
]),
|
556
|
-
]),
|
557
|
-
]
|
558
|
-
},] }
|
559
|
-
];
|
560
|
-
TrendComponent.ctorParameters = function () { return []; };
|
561
|
-
TrendComponent.propDecorators = {
|
562
|
-
data: [{ type: core.Input }],
|
563
|
-
smooth: [{ type: core.Input }],
|
564
|
-
autoDraw: [{ type: core.Input }],
|
565
|
-
autoDrawDuration: [{ type: core.Input }],
|
566
|
-
autoDrawEasing: [{ type: core.Input }],
|
567
|
-
width: [{ type: core.Input }],
|
568
|
-
height: [{ type: core.Input }],
|
569
|
-
padding: [{ type: core.Input }],
|
570
|
-
radius: [{ type: core.Input }],
|
571
|
-
stroke: [{ type: core.Input }],
|
572
|
-
strokeLinecap: [{ type: core.Input }],
|
573
|
-
strokeWidth: [{ type: core.Input }],
|
574
|
-
gradient: [{ type: core.Input }],
|
575
|
-
preserveAspectRatio: [{ type: core.Input }],
|
576
|
-
svgHeight: [{ type: core.Input }],
|
577
|
-
svgWidth: [{ type: core.Input }],
|
578
|
-
pathEl: [{ type: core.ViewChild, args: ['pathEl',] }]
|
579
|
-
};
|
580
|
-
|
581
|
-
var TrendModule = /** @class */ (function () {
|
582
|
-
function TrendModule() {
|
583
|
-
}
|
584
|
-
return TrendModule;
|
585
|
-
}());
|
586
|
-
TrendModule.decorators = [
|
587
|
-
{ type: core.NgModule, args: [{
|
588
|
-
imports: [common.CommonModule],
|
589
|
-
exports: [TrendComponent],
|
590
|
-
declarations: [TrendComponent],
|
591
|
-
},] }
|
592
|
-
];
|
593
|
-
|
594
|
-
/**
|
595
|
-
* Generated bundle index. Do not edit.
|
596
|
-
*/
|
597
|
-
|
598
|
-
exports.TrendComponent = TrendComponent;
|
599
|
-
exports.TrendModule = TrendModule;
|
600
|
-
|
601
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
602
|
-
|
603
|
-
})));
|
604
|
-
//# sourceMappingURL=ngx-trend.umd.js.map
|