charts-core 1.0.0 → 1.0.1
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/dist/charts-core.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
const
|
|
1
|
+
import * as w from "d3";
|
|
2
|
+
const G = (e) => {
|
|
3
3
|
const { svg: t, config: a, y: s } = e, { width: c, margin: i, yAxis: o } = a, { customTicks: d, tickFormat: n, tickValues: r, ticks: l, isShow: u } = o;
|
|
4
4
|
if (!u) return null;
|
|
5
5
|
t.append("g").attr("transform", `translate(${c - i.right},0)`).call((h) => {
|
|
6
|
-
let g =
|
|
6
|
+
let g = w.axisRight(s);
|
|
7
7
|
d ? (n && (g = g.tickFormat(n)), l && (g = Array.isArray(l) ? g.ticks(...l) : g.ticks(l)), r && (g = g.tickValues(r))) : g = g.tickFormat((m) => {
|
|
8
|
-
const x = Number(m),
|
|
9
|
-
return `${
|
|
8
|
+
const x = Number(m), y = x < 0 ? "-" : "", v = w.format(".0s")(Math.abs(x));
|
|
9
|
+
return `${y}${v}`;
|
|
10
10
|
}), h.call(g);
|
|
11
11
|
}).call((h) => {
|
|
12
12
|
let g = [];
|
|
13
13
|
h.selectAll(".tick").each((m) => g.push(m)), e.yTicks = g;
|
|
14
14
|
}).call((h) => h.select(".domain").remove()).call((h) => h.selectAll(".tick line").remove()).call((h) => h.selectAll(".tick text").classed("sc-charts__y-axis-tick", !0)).attr("font-family", "inherit");
|
|
15
|
-
},
|
|
15
|
+
}, V = (e) => {
|
|
16
16
|
const { svg: t, config: a, x: s } = e, { height: c, margin: i, xAxis: o } = a, { isShow: d, tickValues: n, tickFormat: r, customTicks: l, ticks: u } = o;
|
|
17
17
|
if (!d) return null;
|
|
18
18
|
t.append("g").attr("transform", `translate(0,${c - i.bottom})`).call((h) => {
|
|
19
|
-
let g =
|
|
19
|
+
let g = w.axisBottom(s);
|
|
20
20
|
l ? (r && (g = g.tickFormat(r)), u && (g = Array.isArray(u) ? g.ticks(...u) : g.ticks(u)), n && (g = g.tickValues(n))) : g.ticks(5), h.call(g);
|
|
21
21
|
}).call((h) => h.select(".domain").remove()).call((h) => {
|
|
22
22
|
let g = [];
|
|
23
23
|
h.selectAll(".tick").each((m) => g.push(m)), e.xTicks = g;
|
|
24
24
|
}).call((h) => h.selectAll(".tick line").remove()).call((h) => h.selectAll(".tick text").classed("sc-charts__x-axis-tick", !0)).attr("font-family", "inherit");
|
|
25
|
-
},
|
|
25
|
+
}, Z = (e) => {
|
|
26
26
|
const { svg: t, config: a, y: s } = e, {
|
|
27
27
|
width: c,
|
|
28
28
|
margin: i,
|
|
@@ -38,7 +38,7 @@ const z = (e) => {
|
|
|
38
38
|
o === "every-line-dashed" && r.attr("stroke-dasharray", "4 4");
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
},
|
|
41
|
+
}, E = (e) => {
|
|
42
42
|
const { svg: t, config: a, x: s } = e, {
|
|
43
43
|
height: c,
|
|
44
44
|
margin: i,
|
|
@@ -48,19 +48,19 @@ const z = (e) => {
|
|
|
48
48
|
const r = t.append("line").attr("x1", s(n)).attr("x2", s(n)).attr("y1", i.top).attr("y2", c - i.bottom).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
|
|
49
49
|
o === "every-line-dashed" && r.attr("stroke-dasharray", "4 4");
|
|
50
50
|
});
|
|
51
|
-
}, E = (e) => {
|
|
52
|
-
V(e), Z(e);
|
|
53
51
|
}, H = (e) => {
|
|
52
|
+
Z(e), E(e);
|
|
53
|
+
}, X = (e) => {
|
|
54
54
|
const { svg: t, config: a } = e, { width: s, height: c, margin: i, logo: o } = a;
|
|
55
|
-
|
|
55
|
+
V(e), G(e), o && t.append("image").attr("xlink:href", a.theme === "dark" ? o.picDarkTheme : o.picLightTheme).attr("width", o.width).attr("height", o.height).attr("x", o.x ?? (s - i.left - i.right) / 2 - o.width / 2 + i.left).attr("y", o.y ?? (c - i.top - i.bottom) / 2 - o.height / 2 + i.top), H(e);
|
|
56
56
|
}, C = (e, t, a) => {
|
|
57
57
|
let s = e.select(`#${t}`);
|
|
58
58
|
return s.empty() && (s = e.append("linearGradient").attr("gradientUnits", "userSpaceOnUse").attr("id", t)), s.attr("x1", a.x1).attr("y1", a.x2).attr("x2", a.y1).attr("y2", a.y2), a.stops.forEach(({ offset: c, stopColor: i }) => {
|
|
59
59
|
s.append("stop").attr("offset", c).attr("stop-color", i);
|
|
60
60
|
}), s;
|
|
61
61
|
}, k = (e) => {
|
|
62
|
-
const t =
|
|
63
|
-
return t.empty() ?
|
|
62
|
+
const t = w.select(e).select("defs");
|
|
63
|
+
return t.empty() ? w.select(e).append("defs") : t;
|
|
64
64
|
}, B = (e) => {
|
|
65
65
|
const {
|
|
66
66
|
y: t,
|
|
@@ -141,7 +141,7 @@ const z = (e) => {
|
|
|
141
141
|
a.remove();
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
|
-
},
|
|
144
|
+
}, j = (e, t = {}) => {
|
|
145
145
|
const a = "sc-charts__hover-line", s = e.append("line").style("display", t.hidden ? "none" : "block").classed(a, !0), c = e.node(), i = k(c);
|
|
146
146
|
return ((d, n) => C(i, d, {
|
|
147
147
|
x1: "0%",
|
|
@@ -165,9 +165,9 @@ const z = (e) => {
|
|
|
165
165
|
s.remove();
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
},
|
|
169
|
-
const t = "sc-charts__range-tooltip", a = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), s = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), c = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`), i = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`), o =
|
|
170
|
-
const r =
|
|
168
|
+
}, W = (e) => {
|
|
169
|
+
const t = "sc-charts__range-tooltip", a = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), s = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), c = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`), i = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`), o = w.timeFormat("%b %e, %I:%M %p"), d = (n) => {
|
|
170
|
+
const r = w.format(",.2f");
|
|
171
171
|
return `${n < 0 ? "-" : ""}$${r(Math.abs(n))}`;
|
|
172
172
|
};
|
|
173
173
|
return {
|
|
@@ -176,11 +176,11 @@ const z = (e) => {
|
|
|
176
176
|
},
|
|
177
177
|
update({ leftPoint: n, rightPoint: r, x: l, y: u, hidden: h, closest: g }) {
|
|
178
178
|
if (l !== void 0 && a.attr("x", l), u !== void 0 && a.attr("y", u), n && r && g && l !== void 0) {
|
|
179
|
-
const { comparisonValue: m } = e.config.selection,
|
|
180
|
-
let
|
|
181
|
-
m && m !== 0 &&
|
|
182
|
-
const
|
|
183
|
-
c.text(
|
|
179
|
+
const { comparisonValue: m, hidePercent: x } = e.config.selection, y = r.value - n.value, v = (e.x(r.date) + e.x(n.date)) / 2, f = e.x(g.date) < v ? n.value : r.value;
|
|
180
|
+
let p = null;
|
|
181
|
+
x || (m && m !== 0 && f !== 0 ? p = (f / m * 100).toFixed(2) : n.value && (p = (y / Math.abs(n.value) * 100).toFixed(2)));
|
|
182
|
+
const $ = p === null ? "" : `(${p}%)`, F = `${d(y)}${$}`, z = `${o(n.date)} to ${o(r.date)}`;
|
|
183
|
+
c.text(F).append("xhtml:div").html(Y).attr("class", `${t}-sum-icon`), i.text(z);
|
|
184
184
|
const A = e.x(e.data[e.data.length - 1].date), T = e.x(e.data[0].date), b = s.node().getBoundingClientRect();
|
|
185
185
|
b.x < T && a.attr("x", T + b.width / 2), b.x > A - b.width && a.attr("x", A - b.width / 2);
|
|
186
186
|
}
|
|
@@ -190,14 +190,14 @@ const z = (e) => {
|
|
|
190
190
|
a.remove();
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
|
-
},
|
|
193
|
+
}, Y = `
|
|
194
194
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
195
195
|
<path d="M7 0.5C5.71442 0.5 4.45772 0.881218 3.3888 1.59545C2.31988 2.30968 1.48676 3.32484 0.994786 4.51256C0.502816 5.70028 0.374095 7.00721 0.624899 8.26809C0.875703 9.52896 1.49477 10.6872 2.40381 11.5962C3.31285 12.5052 4.47104 13.1243 5.73192 13.3751C6.99279 13.6259 8.29973 13.4972 9.48744 13.0052C10.6752 12.5132 11.6903 11.6801 12.4046 10.6112C13.1188 9.54229 13.5 8.28558 13.5 7C13.4982 5.27665 12.8128 3.62441 11.5942 2.40582C10.3756 1.18722 8.72335 0.50182 7 0.5ZM9.35375 6.85375C9.30732 6.90024 9.25217 6.93712 9.19147 6.96228C9.13077 6.98744 9.06571 7.00039 9 7.00039C8.93429 7.00039 8.86923 6.98744 8.80853 6.96228C8.74783 6.93712 8.69269 6.90024 8.64625 6.85375L7.5 5.70687V9.5C7.5 9.63261 7.44732 9.75979 7.35356 9.85355C7.25979 9.94732 7.13261 10 7 10C6.86739 10 6.74022 9.94732 6.64645 9.85355C6.55268 9.75979 6.5 9.63261 6.5 9.5V5.70687L5.35375 6.85375C5.25993 6.94757 5.13268 7.00028 5 7.00028C4.86732 7.00028 4.74007 6.94757 4.64625 6.85375C4.55243 6.75993 4.49972 6.63268 4.49972 6.5C4.49972 6.36732 4.55243 6.24007 4.64625 6.14625L6.64625 4.14625C6.69269 4.09976 6.74783 4.06288 6.80853 4.03772C6.86923 4.01256 6.9343 3.99961 7 3.99961C7.06571 3.99961 7.13077 4.01256 7.19147 4.03772C7.25217 4.06288 7.30732 4.09976 7.35375 4.14625L9.35375 6.14625C9.40024 6.19269 9.43712 6.24783 9.46228 6.30853C9.48744 6.36923 9.5004 6.43429 9.5004 6.5C9.5004 6.56571 9.48744 6.63077 9.46228 6.69147C9.43712 6.75217 9.40024 6.80731 9.35375 6.85375Z"
|
|
196
196
|
fill="currentColor"/>
|
|
197
197
|
</svg>
|
|
198
|
-
`,
|
|
199
|
-
const t = "sc-charts__hover-tooltip", a = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), s = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), c = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`).html("$sum"), i = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`).html("Date"), o =
|
|
200
|
-
const r =
|
|
198
|
+
`, O = (e) => {
|
|
199
|
+
const t = "sc-charts__hover-tooltip", a = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), s = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), c = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`).html("$sum"), i = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`).html("Date"), o = w.timeFormat("%a, %b %d, %-I:%M %p"), d = (n) => {
|
|
200
|
+
const r = w.format(",.2f");
|
|
201
201
|
return `${n < 0 ? "-" : ""}$${r(Math.abs(n))}`;
|
|
202
202
|
};
|
|
203
203
|
return {
|
|
@@ -216,7 +216,7 @@ const z = (e) => {
|
|
|
216
216
|
a.remove();
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
|
-
},
|
|
219
|
+
}, P = {
|
|
220
220
|
margin: { top: 10, right: 30, bottom: 20, left: 10 },
|
|
221
221
|
theme: "light",
|
|
222
222
|
logo: {
|
|
@@ -236,7 +236,8 @@ const z = (e) => {
|
|
|
236
236
|
},
|
|
237
237
|
selection: {
|
|
238
238
|
enable: !0,
|
|
239
|
-
comparisonValue: null
|
|
239
|
+
comparisonValue: null,
|
|
240
|
+
hidePercent: !1
|
|
240
241
|
},
|
|
241
242
|
xAxis: {
|
|
242
243
|
customTicks: !1,
|
|
@@ -258,7 +259,7 @@ const z = (e) => {
|
|
|
258
259
|
},
|
|
259
260
|
enableBelowZeroLine: !1,
|
|
260
261
|
curveTension: 1
|
|
261
|
-
}, L = (e) =>
|
|
262
|
+
}, L = (e) => w.curveCardinal.tension(e.config.curveTension), U = (e) => {
|
|
262
263
|
const { svg: t, data: a, x: s, y: c, config: i } = e, o = t.node(), d = k(o);
|
|
263
264
|
C(d, "main-line-area-gradient", {
|
|
264
265
|
x1: "0%",
|
|
@@ -270,7 +271,7 @@ const z = (e) => {
|
|
|
270
271
|
{ offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
|
|
271
272
|
]
|
|
272
273
|
});
|
|
273
|
-
const r =
|
|
274
|
+
const r = w.area().x((h) => s(h.date)).y0(c.range()[0]).y1((h) => c(h.value)).curve(L(e)), l = "sc-charts__main-line-area", u = t.append("path").datum(a).attr("d", r).attr("class", l).classed(`${l}_hidden`, !i.hasMainLineArea);
|
|
274
275
|
return {
|
|
275
276
|
className(h, g) {
|
|
276
277
|
h === "remove" ? u.classed(`${l}${g}`, !1) : u.classed(`${l}${g}`, !0);
|
|
@@ -306,39 +307,39 @@ const z = (e) => {
|
|
|
306
307
|
{ offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
|
|
307
308
|
]
|
|
308
309
|
});
|
|
309
|
-
const g =
|
|
310
|
+
const g = w.area().x((f) => c(f.date)).y0(i.range()[0]).y1((f) => i(f.value)).curve(L(e)), m = `${n}-clip-${a}`, y = u.append("clipPath").attr("id", m).append("rect").attr("x", (r == null ? void 0 : r.x) || 0).attr("y", (r == null ? void 0 : r.y) || 0).attr("width", (r == null ? void 0 : r.width) || "100%").attr("height", (r == null ? void 0 : r.height) || "100%"), v = s.append("path").datum(d).attr("d", g).attr("class", a).classed(`${a}_hidden`, !o.hasMainLineArea).attr("clip-path", `url(#${m})`);
|
|
310
311
|
return {
|
|
311
|
-
className(f,
|
|
312
|
-
f === "remove" ? v.classed(`${a}${
|
|
312
|
+
className(f, p) {
|
|
313
|
+
f === "remove" ? v.classed(`${a}${p}`, !1) : v.classed(`${a}${p}`, !0);
|
|
313
314
|
},
|
|
314
|
-
update({ data: f, hidden:
|
|
315
|
-
f !== void 0 && v.datum(f).attr("d", g),
|
|
315
|
+
update({ data: f, hidden: p, clip: $ }) {
|
|
316
|
+
f !== void 0 && v.datum(f).attr("d", g), p !== void 0 && v.classed(`${a}_hidden`, p), $ !== void 0 && y.attr("x", $.x).attr("y", $.y).attr("width", $.width).attr("height", $.height);
|
|
316
317
|
},
|
|
317
318
|
destroy() {
|
|
318
319
|
v.remove();
|
|
319
320
|
}
|
|
320
321
|
};
|
|
321
322
|
}, N = (e, t) => {
|
|
322
|
-
const { svg: a, data: s, x: c, y: i, chartId: o } = e, { baseClassName: d, id: n, clip: r } = t, l = a.node(), u = k(l), h =
|
|
323
|
+
const { svg: a, data: s, x: c, y: i, chartId: o } = e, { baseClassName: d, id: n, clip: r } = t, l = a.node(), u = k(l), h = w.line().x((v) => c(v.date)).y((v) => i(v.value)).curve(L(e)), g = `${o}-clip-${d}`, x = u.append("clipPath").attr("id", g).append("rect").attr("x", (r == null ? void 0 : r.x) || 0).attr("y", (r == null ? void 0 : r.y) || 0).attr("width", (r == null ? void 0 : r.width) || "100%").attr("height", (r == null ? void 0 : r.height) || "100%"), y = a.append("path").classed(d, !0).datum(s).attr("d", h).attr("id", n).attr("clip-path", `url(#${g})`);
|
|
323
324
|
return {
|
|
324
325
|
className(v, f) {
|
|
325
|
-
v === "remove" ?
|
|
326
|
+
v === "remove" ? y.classed(`${d}${f}`, !1) : y.classed(`${d}${f}`, !0);
|
|
326
327
|
},
|
|
327
|
-
update({ data: v, clip: f, hidden:
|
|
328
|
-
v !== void 0 &&
|
|
328
|
+
update({ data: v, clip: f, hidden: p }) {
|
|
329
|
+
v !== void 0 && y.datum(v).attr("d", h), p !== void 0 && y.classed(`${d}_hidden`, p), f !== void 0 && x.attr("x", f.x).attr("y", f.y).attr("width", f.width).attr("height", f.height);
|
|
329
330
|
},
|
|
330
331
|
destroy() {
|
|
331
|
-
|
|
332
|
+
y.remove();
|
|
332
333
|
}
|
|
333
334
|
};
|
|
334
335
|
}, J = (e, t) => {
|
|
335
|
-
const { svg: a, data: s, x: c, y: i, chartId: o, config: d } = e, { baseClassName: n, id: r, clip: l } = t, u = a.node(), h = k(u), g =
|
|
336
|
+
const { svg: a, data: s, x: c, y: i, chartId: o, config: d } = e, { baseClassName: n, id: r, clip: l } = t, u = a.node(), h = k(u), g = w.line().x((f) => c(f.date)).y((f) => i(f.value)).curve(L(e)), m = `${o}-clip-${n}`, y = h.append("clipPath").attr("id", m).append("rect").attr("x", (l == null ? void 0 : l.x) || 0).attr("y", (l == null ? void 0 : l.y) || 0).attr("width", (l == null ? void 0 : l.width) || "100%").attr("height", (l == null ? void 0 : l.height) || "100%"), v = a.append("path").classed(n, !0).datum(s).attr("d", g).attr("id", r).attr("clip-path", `url(#${m})`);
|
|
336
337
|
return {
|
|
337
|
-
className(f,
|
|
338
|
-
f === "remove" ? v.classed(`${n}${
|
|
338
|
+
className(f, p) {
|
|
339
|
+
f === "remove" ? v.classed(`${n}${p}`, !1) : v.classed(`${n}${p}`, !0);
|
|
339
340
|
},
|
|
340
|
-
update({ data: f, clip:
|
|
341
|
-
f !== void 0 && v.datum(f).attr("d", g), $ !== void 0 && v.classed(`${n}_hidden`, $),
|
|
341
|
+
update({ data: f, clip: p, hidden: $ }) {
|
|
342
|
+
f !== void 0 && v.datum(f).attr("d", g), $ !== void 0 && v.classed(`${n}_hidden`, $), p !== void 0 && (d.hover.transitionName === "default" ? y.transition().duration(d.hover.transitionDuration).attr("x", p.x).attr("y", p.y).attr("width", p.width).attr("height", p.height).ease(w.easeLinear) : y.attr("x", p.x).attr("y", p.y).attr("width", p.width).attr("height", p.height));
|
|
342
343
|
},
|
|
343
344
|
destroy() {
|
|
344
345
|
v.remove();
|
|
@@ -348,7 +349,7 @@ const z = (e) => {
|
|
|
348
349
|
const t = N(e, {
|
|
349
350
|
baseClassName: "sc-charts__main-line",
|
|
350
351
|
id: `${e.chartId}-sc-charts__main-line`
|
|
351
|
-
}), a = U(e), s =
|
|
352
|
+
}), a = U(e), s = j(e.svg), c = J(e, {
|
|
352
353
|
baseClassName: "sc-charts__highlight-line",
|
|
353
354
|
id: `${e.chartId}-sc-charts__highlight-line`,
|
|
354
355
|
clip: { x: 0, y: 0, width: "0", height: "0" }
|
|
@@ -372,7 +373,7 @@ const z = (e) => {
|
|
|
372
373
|
}), u = _(e.svg, {
|
|
373
374
|
className: "sc-charts__range-circle-right",
|
|
374
375
|
hidden: !0
|
|
375
|
-
}), h =
|
|
376
|
+
}), h = W(e), g = O(e), m = q(e);
|
|
376
377
|
return {
|
|
377
378
|
hoverLine: s,
|
|
378
379
|
hoverCircle: o,
|
|
@@ -389,7 +390,7 @@ const z = (e) => {
|
|
|
389
390
|
mainLineArea: a,
|
|
390
391
|
belowZeroLine: i
|
|
391
392
|
};
|
|
392
|
-
},
|
|
393
|
+
}, Q = (e, t, a) => {
|
|
393
394
|
const s = e.match(/^(\d+)([dMhmw])$/);
|
|
394
395
|
if (!s)
|
|
395
396
|
return console.warn("Invalid hoverRange:", e), {
|
|
@@ -466,7 +467,7 @@ const z = (e) => {
|
|
|
466
467
|
y: 0,
|
|
467
468
|
hidden: !1
|
|
468
469
|
});
|
|
469
|
-
const n =
|
|
470
|
+
const n = Q(d.range, t.date, a);
|
|
470
471
|
c.highlightLine.update({
|
|
471
472
|
clip: n,
|
|
472
473
|
hidden: !1
|
|
@@ -483,7 +484,7 @@ const z = (e) => {
|
|
|
483
484
|
t.hoverLine.update({ hidden: !0 }), t.hoverCircle.update({ hidden: !0 }), t.highlightLine.update({ hidden: !0 }), t.mainLine.className("remove", "_muted"), t.hoverTooltip.update({ hidden: !0 }), e.action !== "selection" && ((a = t.belowZeroLine) == null || a.update({
|
|
484
485
|
clip: B(e)
|
|
485
486
|
}));
|
|
486
|
-
},
|
|
487
|
+
}, ee = (e, t) => {
|
|
487
488
|
[
|
|
488
489
|
"rangeBorderLeft",
|
|
489
490
|
"rangeBorderRight",
|
|
@@ -495,7 +496,7 @@ const z = (e) => {
|
|
|
495
496
|
].forEach((s) => {
|
|
496
497
|
t ? (e[s].className("remove", "_down"), e[s].className("add", "_up")) : (e[s].className("remove", "_up"), e[s].className("add", "_down"));
|
|
497
498
|
});
|
|
498
|
-
},
|
|
499
|
+
}, te = (e, t, a) => {
|
|
499
500
|
var m;
|
|
500
501
|
const {
|
|
501
502
|
x: s,
|
|
@@ -548,50 +549,50 @@ const z = (e) => {
|
|
|
548
549
|
hidden: !1
|
|
549
550
|
}), (m = d.belowZeroLine) == null || m.update({
|
|
550
551
|
hidden: !0
|
|
551
|
-
}), d.mainLineArea.update({ hidden: !0 }),
|
|
552
|
+
}), d.mainLineArea.update({ hidden: !0 }), ee(d, l), d.mainLine.className("add", "_selected-muted");
|
|
552
553
|
}, S = (e) => {
|
|
553
554
|
var a;
|
|
554
555
|
const { elements: t } = e;
|
|
555
556
|
t.rangeLine.update({ hidden: !0 }), t.rangeLineArea.update({ hidden: !0 }), t.rangeBorderLeft.update({ hidden: !0 }), t.rangeBorderRight.update({ hidden: !0 }), t.rangeCircleLeft.update({ hidden: !0 }), t.rangeCircleRight.update({ hidden: !0 }), t.rangeTooltip.update({ hidden: !0 }), t.mainLine.className("remove", "_selected-muted"), t.mainLineArea.update({ hidden: !1 }), (a = t.belowZeroLine) == null || a.update({ hidden: !1 });
|
|
556
|
-
},
|
|
557
|
+
}, ae = (e) => {
|
|
557
558
|
const { svg: t, data: a, x: s, config: c } = e, { height: i, margin: o, width: d, hover: n, selection: r } = c;
|
|
558
559
|
let l = null, u = !1;
|
|
559
560
|
const h = (m) => a.reduce(
|
|
560
|
-
(x,
|
|
561
|
+
(x, y) => Math.abs(s(x.date) - m) < Math.abs(s(y.date) - m) ? x : y
|
|
561
562
|
);
|
|
562
563
|
t.append("rect").attr("width", d - o.left - o.right).attr("height", i - o.top - o.bottom).attr("x", o.left).attr("y", o.top).attr("fill", "transparent").on("mousemove", function(m) {
|
|
563
|
-
const [x] =
|
|
564
|
-
!u && n.enable ? (e.action = "hover", D(e,
|
|
564
|
+
const [x] = w.pointer(m, this), y = h(x);
|
|
565
|
+
!u && n.enable ? (e.action = "hover", D(e, y)) : (e.action = u ? "selection" : "none", R(e)), l && r.enable && (e.action = "selection", te(e, l, y));
|
|
565
566
|
}).on("mouseleave", () => {
|
|
566
567
|
e.action = "none", u = !1, l = null, R(e), S(e);
|
|
567
568
|
}).on("mousedown", function(m) {
|
|
568
569
|
if (r.enable) {
|
|
569
570
|
u = !0, e.action = "selection";
|
|
570
|
-
const [x] =
|
|
571
|
+
const [x] = w.pointer(m, this);
|
|
571
572
|
l = h(x);
|
|
572
573
|
}
|
|
573
574
|
}).on("mouseup", function(m) {
|
|
574
|
-
const [x] =
|
|
575
|
-
u = !1, l = null, e.action = "hover", r.enable && S(e), n.enable && D(e,
|
|
575
|
+
const [x] = w.pointer(m, this), y = h(x);
|
|
576
|
+
u = !1, l = null, e.action = "hover", r.enable && S(e), n.enable && D(e, y);
|
|
576
577
|
});
|
|
577
|
-
}, ae = (e, t) => {
|
|
578
|
-
const { width: a, margin: s } = t, c = y.scaleTime(), i = y.extent(e, (o) => new Date(o.date));
|
|
579
|
-
return i[0] == null || i[1] == null ? c : c.domain([i[0], i[1]]).range([s.left, a - s.right]);
|
|
580
578
|
}, re = (e, t) => {
|
|
581
|
-
const {
|
|
582
|
-
return
|
|
579
|
+
const { width: a, margin: s } = t, c = w.scaleTime(), i = w.extent(e, (o) => new Date(o.date));
|
|
580
|
+
return i[0] == null || i[1] == null ? c : c.domain([i[0], i[1]]).range([s.left, a - s.right]);
|
|
583
581
|
}, se = (e, t) => {
|
|
584
|
-
const a =
|
|
582
|
+
const { height: a, margin: s } = t, c = w.max(e, (o) => o.value) ?? 0, i = w.min(e, (o) => o.value) ?? 0;
|
|
583
|
+
return w.scaleLinear().domain([i, c]).range([a - s.bottom, s.top]);
|
|
584
|
+
}, ne = (e, t) => {
|
|
585
|
+
const a = w.select(e);
|
|
585
586
|
if (a.empty())
|
|
586
587
|
return console.error(`Element with selector ${e} not found!`), null;
|
|
587
588
|
if (!t.chartId || !/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.chartId))
|
|
588
589
|
return console.error(`chartId is required and must be a valid id
|
|
589
590
|
(only letters, numbers or underscores. The first character must be a letter)`), null;
|
|
590
591
|
const s = a.append("svg"), i = a.node().getBoundingClientRect(), o = i.width, d = i.height;
|
|
591
|
-
let n = I({ ...
|
|
592
|
+
let n = I({ ...P, width: o, height: d }, t.config);
|
|
592
593
|
const r = (l, u = !1) => {
|
|
593
594
|
u && l.config && (n = I(n, l.config));
|
|
594
|
-
const h = l.data.map((v) => ({ date: new Date(v.date), value: v.value })).sort((v, f) => v.date.getTime() - f.date.getTime()), g =
|
|
595
|
+
const h = l.data.map((v) => ({ date: new Date(v.date), value: v.value })).sort((v, f) => v.date.getTime() - f.date.getTime()), g = re(h, n), m = se(h, n);
|
|
595
596
|
s.attr("class", `sc-charts sc-charts__${n.theme}`).attr("preserveAspectRatio", "xMinYMin meet").attr("viewBox", `0 0 ${o} ${d}`).style("width", "100%").style("height", "100%").selectAll("*").remove();
|
|
596
597
|
const x = {
|
|
597
598
|
chartId: t.chartId,
|
|
@@ -602,12 +603,12 @@ const z = (e) => {
|
|
|
602
603
|
config: n,
|
|
603
604
|
action: "none"
|
|
604
605
|
};
|
|
605
|
-
|
|
606
|
-
const
|
|
606
|
+
X(x);
|
|
607
|
+
const y = {
|
|
607
608
|
...x,
|
|
608
609
|
elements: K(x)
|
|
609
610
|
};
|
|
610
|
-
|
|
611
|
+
ae(y);
|
|
611
612
|
};
|
|
612
613
|
return r(t), {
|
|
613
614
|
update: (l) => r(l, !0),
|
|
@@ -615,6 +616,6 @@ const z = (e) => {
|
|
|
615
616
|
};
|
|
616
617
|
};
|
|
617
618
|
export {
|
|
618
|
-
|
|
619
|
+
ne as createLineChart
|
|
619
620
|
};
|
|
620
621
|
//# sourceMappingURL=charts-core.js.map
|