charts-core 0.0.20 → 0.0.21

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.
@@ -1,72 +1,72 @@
1
1
  import * as v from "d3";
2
2
  const M = (e) => {
3
- const { svg: t, config: s, y: a } = e, { width: l, margin: n, yAxis: o } = s, { customTicks: i, tickFormat: r, tickValues: d, ticks: f, isShow: g } = o;
3
+ const { svg: t, config: a, y: s } = e, { width: l, margin: o, yAxis: n } = a, { customTicks: i, tickFormat: r, tickValues: c, ticks: u, isShow: g } = n;
4
4
  if (!g) return null;
5
- t.append("g").attr("transform", `translate(${l - n.right},0)`).call((c) => {
6
- let h = v.axisRight(a);
7
- i ? (r && (h = h.tickFormat(r)), f && (h = Array.isArray(f) ? h.ticks(...f) : h.ticks(f)), d && (h = h.tickValues(d))) : h = h.tickFormat((u) => {
8
- const m = Number(u), p = m < 0 ? "-" : "", y = v.format(".0s")(Math.abs(m));
5
+ t.append("g").attr("transform", `translate(${l - o.right},0)`).call((d) => {
6
+ let h = v.axisRight(s);
7
+ i ? (r && (h = h.tickFormat(r)), u && (h = Array.isArray(u) ? h.ticks(...u) : h.ticks(u)), c && (h = h.tickValues(c))) : h = h.tickFormat((m) => {
8
+ const f = Number(m), p = f < 0 ? "-" : "", y = v.format(".0s")(Math.abs(f));
9
9
  return `${p}${y}`;
10
- }), c.call(h);
11
- }).call((c) => {
10
+ }), d.call(h);
11
+ }).call((d) => {
12
12
  let h = [];
13
- c.selectAll(".tick").each((u) => h.push(u)), e.yTicks = h;
14
- }).call((c) => c.select(".domain").remove()).call((c) => c.selectAll(".tick line").remove()).call((c) => c.selectAll(".tick text").classed("sc-charts__y-axis-tick", !0)).attr("font-family", "inherit");
13
+ d.selectAll(".tick").each((m) => h.push(m)), e.yTicks = h;
14
+ }).call((d) => d.select(".domain").remove()).call((d) => d.selectAll(".tick line").remove()).call((d) => d.selectAll(".tick text").classed("sc-charts__y-axis-tick", !0)).attr("font-family", "inherit");
15
15
  }, S = (e) => {
16
- const { svg: t, config: s, x: a } = e, { height: l, margin: n, xAxis: o } = s, { isShow: i, tickValues: r, tickFormat: d, customTicks: f, ticks: g } = o;
16
+ const { svg: t, config: a, x: s } = e, { height: l, margin: o, xAxis: n } = a, { isShow: i, tickValues: r, tickFormat: c, customTicks: u, ticks: g } = n;
17
17
  if (!i) return null;
18
- t.append("g").attr("transform", `translate(0,${l - n.bottom})`).call((c) => {
19
- let h = v.axisBottom(a);
20
- f ? (d && (h = h.tickFormat(d)), g && (h = Array.isArray(g) ? h.ticks(...g) : h.ticks(g)), r && (h = h.tickValues(r))) : h.ticks(5), c.call(h);
21
- }).call((c) => c.select(".domain").remove()).call((c) => {
18
+ t.append("g").attr("transform", `translate(0,${l - o.bottom})`).call((d) => {
19
+ let h = v.axisBottom(s);
20
+ u ? (c && (h = h.tickFormat(c)), g && (h = Array.isArray(g) ? h.ticks(...g) : h.ticks(g)), r && (h = h.tickValues(r))) : h.ticks(5), d.call(h);
21
+ }).call((d) => d.select(".domain").remove()).call((d) => {
22
22
  let h = [];
23
- c.selectAll(".tick").each((u) => h.push(u)), e.xTicks = h;
24
- }).call((c) => c.selectAll(".tick line").remove()).call((c) => c.selectAll(".tick text").classed("sc-charts__x-axis-tick", !0)).attr("font-family", "inherit");
23
+ d.selectAll(".tick").each((m) => h.push(m)), e.xTicks = h;
24
+ }).call((d) => d.selectAll(".tick line").remove()).call((d) => d.selectAll(".tick text").classed("sc-charts__x-axis-tick", !0)).attr("font-family", "inherit");
25
25
  }, F = (e) => {
26
- const { svg: t, config: s, y: a } = e, {
26
+ const { svg: t, config: a, y: s } = e, {
27
27
  width: l,
28
- margin: n,
29
- grid: { horizontalStyle: o }
30
- } = s;
31
- if (o !== "none") {
32
- if (o.startsWith("zero-line")) {
33
- const i = t.append("line").attr("x1", 0 + n.left).attr("x2", l - n.right).attr("y1", a(0)).attr("y2", a(0)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
34
- o === "zero-line-dashed" && i.attr("stroke-dasharray", "4 4");
28
+ margin: o,
29
+ grid: { horizontalStyle: n }
30
+ } = a;
31
+ if (n !== "none") {
32
+ if (n.startsWith("zero-line")) {
33
+ const i = t.append("line").attr("x1", 0 + o.left).attr("x2", l - o.right).attr("y1", s(0)).attr("y2", s(0)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
34
+ n === "zero-line-dashed" && i.attr("stroke-dasharray", "4 4");
35
35
  }
36
- o.startsWith("every-line") && (e.yTicks || a.ticks()).forEach((r) => {
37
- const d = t.append("line").attr("x1", 0 + n.left).attr("x2", l - n.right).attr("y1", a(r)).attr("y2", a(r)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
38
- o === "every-line-dashed" && d.attr("stroke-dasharray", "4 4");
36
+ n.startsWith("every-line") && (e.yTicks || s.ticks()).forEach((r) => {
37
+ const c = t.append("line").attr("x1", 0 + o.left).attr("x2", l - o.right).attr("y1", s(r)).attr("y2", s(r)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
38
+ n === "every-line-dashed" && c.attr("stroke-dasharray", "4 4");
39
39
  });
40
40
  }
41
41
  }, I = (e) => {
42
- const { svg: t, config: s, x: a } = e, {
42
+ const { svg: t, config: a, x: s } = e, {
43
43
  height: l,
44
- margin: n,
45
- grid: { verticalStyle: o }
46
- } = s;
47
- o !== "none" && o.startsWith("every-line") && (e.xTicks || a.ticks()).forEach((r) => {
48
- const d = t.append("line").attr("x1", a(r)).attr("x2", a(r)).attr("y1", n.top).attr("y2", l - n.bottom).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
49
- o === "every-line-dashed" && d.attr("stroke-dasharray", "4 4");
44
+ margin: o,
45
+ grid: { verticalStyle: n }
46
+ } = a;
47
+ n !== "none" && n.startsWith("every-line") && (e.xTicks || s.ticks()).forEach((r) => {
48
+ const c = t.append("line").attr("x1", s(r)).attr("x2", s(r)).attr("y1", o.top).attr("y2", l - o.bottom).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
49
+ n === "every-line-dashed" && c.attr("stroke-dasharray", "4 4");
50
50
  });
51
51
  }, z = (e) => {
52
52
  F(e), I(e);
53
53
  }, Z = (e) => {
54
- const { svg: t, config: s } = e, { width: a, height: l, margin: n, logo: o } = s;
55
- S(e), M(e), o && t.append("image").attr("xlink:href", s.theme === "dark" ? o.picDarkTheme : o.picLightTheme).attr("width", o.width).attr("height", o.height).attr("x", o.x ?? (a - n.left - n.right) / 2 - o.width / 2 + n.left).attr("y", o.y ?? (l - n.top - n.bottom) / 2 - o.height / 2 + n.top), z(e);
56
- }, $ = (e, t, s) => {
57
- let a = e.select(`#${t}`);
58
- return a.empty() && (a = e.append("linearGradient").attr("gradientUnits", "userSpaceOnUse").attr("id", t)), a.attr("x1", s.x1).attr("y1", s.x2).attr("x2", s.y1).attr("y2", s.y2), s.stops.forEach(({ offset: l, stopColor: n }) => {
59
- a.append("stop").attr("offset", l).attr("stop-color", n);
60
- }), a;
54
+ const { svg: t, config: a } = e, { width: s, height: l, margin: o, logo: n } = a;
55
+ S(e), M(e), n && t.append("image").attr("xlink:href", a.theme === "dark" ? n.picDarkTheme : n.picLightTheme).attr("width", n.width).attr("height", n.height).attr("x", n.x ?? (s - o.left - o.right) / 2 - n.width / 2 + o.left).attr("y", n.y ?? (l - o.top - o.bottom) / 2 - n.height / 2 + o.top), z(e);
56
+ }, k = (e, t, a) => {
57
+ let s = e.select(`#${t}`);
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: l, stopColor: o }) => {
59
+ s.append("stop").attr("offset", l).attr("stop-color", o);
60
+ }), s;
61
61
  }, C = (e) => {
62
62
  const t = v.select(e).select("defs");
63
63
  return t.empty() ? v.select(e).append("defs") : t;
64
64
  }, B = (e) => {
65
65
  const {
66
66
  y: t,
67
- config: { margin: s }
68
- } = e, a = t.range()[0] - t(0);
69
- return { x: 0, y: t.range()[0] - a, width: "100%", height: a + s.bottom };
67
+ config: { margin: a }
68
+ } = e, s = t.range()[0] - t(0);
69
+ return { x: 0, y: t.range()[0] - s, width: "100%", height: s + a.bottom };
70
70
  }, A = (e, t) => ({
71
71
  ...e,
72
72
  ...t,
@@ -95,7 +95,7 @@ const M = (e) => {
95
95
  ...t == null ? void 0 : t.grid
96
96
  }
97
97
  }), N = (e, t = {}) => {
98
- const s = e.node(), a = C(s), l = (i, r) => $(a, i, {
98
+ const a = e.node(), s = C(a), l = (i, r) => k(s, i, {
99
99
  x1: "0%",
100
100
  y1: "0%",
101
101
  x2: "0%",
@@ -108,34 +108,34 @@ const M = (e) => {
108
108
  ]
109
109
  });
110
110
  l("gradient-range-borders-up", "var(--sc-color-selection-up)"), l("gradient-range-borders-down", "var(--sc-color-selection-down)");
111
- const n = "sc-charts__border-range-line", o = e.append("line").classed(n, !0).style("display", t.hidden ? "none" : "block");
111
+ const o = "sc-charts__border-range-line", n = e.append("line").classed(o, !0).style("display", t.hidden ? "none" : "block");
112
112
  return {
113
113
  className(i, r) {
114
- i === "remove" ? o.classed(`${n}${r}`, !1) : o.classed(`${n}${r}`, !0);
114
+ i === "remove" ? n.classed(`${o}${r}`, !1) : n.classed(`${o}${r}`, !0);
115
115
  },
116
- update({ x1: i, x2: r, y1: d, y2: f, hidden: g }) {
117
- i !== void 0 && o.attr("x1", i), r !== void 0 && o.attr("x2", r), d !== void 0 && o.attr("y1", d), f !== void 0 && o.attr("y2", f), g !== void 0 && o.style("display", g ? "none" : "block");
116
+ update({ x1: i, x2: r, y1: c, y2: u, hidden: g }) {
117
+ i !== void 0 && n.attr("x1", i), r !== void 0 && n.attr("x2", r), c !== void 0 && n.attr("y1", c), u !== void 0 && n.attr("y2", u), g !== void 0 && n.style("display", g ? "none" : "block");
118
118
  },
119
119
  destroy() {
120
- o.remove();
120
+ n.remove();
121
121
  }
122
122
  };
123
123
  }, L = (e, t = {}) => {
124
- const s = e.append("circle").attr("r", t.radius || 4).style("display", t.hidden ? "none" : "block"), a = t.className || "";
125
- return a && s.classed(a, !0), {
126
- className(l, n) {
127
- l === "remove" ? s.classed(`${a}${n}`, !1) : s.classed(`${a}${n}`, !0);
124
+ const a = e.append("circle").attr("r", t.radius || 4).style("display", t.hidden ? "none" : "block"), s = t.className || "";
125
+ return s && a.classed(s, !0), {
126
+ className(l, o) {
127
+ l === "remove" ? a.classed(`${s}${o}`, !1) : a.classed(`${s}${o}`, !0);
128
128
  },
129
- update({ cx: l, cy: n, hidden: o, fill: i }) {
130
- l !== void 0 && s.attr("cx", l), n !== void 0 && s.attr("cy", n), i !== void 0 && s.attr("fill", i), o !== void 0 && s.style("display", o ? "none" : "block");
129
+ update({ cx: l, cy: o, hidden: n, fill: i }) {
130
+ l !== void 0 && a.attr("cx", l), o !== void 0 && a.attr("cy", o), i !== void 0 && a.attr("fill", i), n !== void 0 && a.style("display", n ? "none" : "block");
131
131
  },
132
132
  destroy() {
133
- s.remove();
133
+ a.remove();
134
134
  }
135
135
  };
136
136
  }, G = (e, t = {}) => {
137
- const s = "sc-charts__hover-line", a = e.append("line").style("display", t.hidden ? "none" : "block").classed(s, !0), l = e.node(), n = C(l);
138
- return ((i, r) => $(n, i, {
137
+ const a = "sc-charts__hover-line", s = e.append("line").style("display", t.hidden ? "none" : "block").classed(a, !0), l = e.node(), o = C(l);
138
+ return ((i, r) => k(o, i, {
139
139
  x1: "0%",
140
140
  y1: "0%",
141
141
  x2: "0%",
@@ -148,32 +148,32 @@ const M = (e) => {
148
148
  ]
149
149
  }))("hover-line-gradient", "var(--sc-color-hover-line)"), {
150
150
  className(i, r) {
151
- i === "remove" ? a.classed(`${s}${r}`, !1) : a.classed(`${s}${r}`, !0);
151
+ i === "remove" ? s.classed(`${a}${r}`, !1) : s.classed(`${a}${r}`, !0);
152
152
  },
153
- update({ x1: i, x2: r, y1: d, y2: f, hidden: g }) {
154
- i !== void 0 && a.attr("x1", i), r !== void 0 && a.attr("x2", r), d !== void 0 && a.attr("y1", d), f !== void 0 && a.attr("y2", f), g !== void 0 && a.style("display", g ? "none" : "block");
153
+ update({ x1: i, x2: r, y1: c, y2: u, hidden: g }) {
154
+ i !== void 0 && s.attr("x1", i), r !== void 0 && s.attr("x2", r), c !== void 0 && s.attr("y1", c), u !== void 0 && s.attr("y2", u), g !== void 0 && s.style("display", g ? "none" : "block");
155
155
  },
156
156
  destroy() {
157
- a.remove();
157
+ s.remove();
158
158
  }
159
159
  };
160
160
  }, H = (e) => {
161
- const t = "sc-charts__range-tooltip", s = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), a = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), l = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`), n = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`), o = v.timeFormat("%b %e, %I:%M %p");
161
+ 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`), l = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`), o = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`), n = v.timeFormat("%b %e, %I:%M %p");
162
162
  return {
163
163
  className(i, r) {
164
- i === "remove" ? s.classed(`${t}${r}`, !1) : s.classed(`${t}${r}`, !0);
164
+ i === "remove" ? a.classed(`${t}${r}`, !1) : a.classed(`${t}${r}`, !0);
165
165
  },
166
- update({ leftPoint: i, rightPoint: r, x: d, y: f, hidden: g }) {
167
- if (d !== void 0 && s.attr("x", d), f !== void 0 && s.attr("y", f), i && r) {
168
- const c = r.value - i.value, h = (c / i.value * 100).toFixed(2), u = `${c < 0 ? "-" : ""}$${Math.abs(c).toFixed(2)} (${h}%)`, m = `${o(i.date)} to ${o(r.date)}`;
169
- l.text(u).append("xhtml:div").html(V).attr("class", `${t}-sum-icon`), n.text(m);
170
- const p = e.x(e.data[e.data.length - 1].date), y = e.x(e.data[0].date), w = a.node().getBoundingClientRect();
171
- w.x < y && s.attr("x", y + w.width / 2), w.x > p - w.width && s.attr("x", p - w.width / 2);
166
+ update({ leftPoint: i, rightPoint: r, x: c, y: u, hidden: g }) {
167
+ if (c !== void 0 && a.attr("x", c), u !== void 0 && a.attr("y", u), i && r) {
168
+ const d = r.value - i.value, h = (d / i.value * 100).toFixed(2), m = `${d < 0 ? "-" : ""}$${Math.abs(d).toFixed(2)} (${h}%)`, f = `${n(i.date)} to ${n(r.date)}`;
169
+ l.text(m).append("xhtml:div").html(V).attr("class", `${t}-sum-icon`), o.text(f);
170
+ const p = e.x(e.data[e.data.length - 1].date), y = e.x(e.data[0].date), w = s.node().getBoundingClientRect();
171
+ w.x < y && a.attr("x", y + w.width / 2), w.x > p - w.width && a.attr("x", p - w.width / 2);
172
172
  }
173
- g !== void 0 && s.style("display", g ? "none" : "block");
173
+ g !== void 0 && a.style("display", g ? "none" : "block");
174
174
  },
175
175
  destroy() {
176
- s.remove();
176
+ a.remove();
177
177
  }
178
178
  };
179
179
  }, V = `
@@ -182,21 +182,21 @@ const M = (e) => {
182
182
  fill="currentColor"/>
183
183
  </svg>
184
184
  `, E = (e) => {
185
- const t = "sc-charts__hover-tooltip", s = e.svg.append("foreignObject").classed(t, !0).style("display", "none"), a = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-container`), l = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`).html("fdsfsd"), n = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`).html("fdsfsd fdsfsd fdsfsd fdsfsd"), o = v.timeFormat("%a, %b %d, %-I:%M %p"), i = (r) => `${r < 0 ? "-" : ""}$${Math.abs(r).toFixed(2)}`;
185
+ 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`), l = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-sum`).html("$sum"), o = s.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${t}-time`).html("Date"), n = v.timeFormat("%a, %b %d, %-I:%M %p"), i = (r) => `${r < 0 ? "-" : ""}$${Math.abs(r).toFixed(2)}`;
186
186
  return {
187
- className(r, d) {
188
- r === "remove" ? s.classed(`${t}${d}`, !1) : s.classed(`${t}${d}`, !0);
187
+ className(r, c) {
188
+ r === "remove" ? a.classed(`${t}${c}`, !1) : a.classed(`${t}${c}`, !0);
189
189
  },
190
- update({ x: r, y: d, hidden: f, dataItem: g }) {
191
- if (r !== void 0 && s.attr("x", r), d !== void 0 && s.attr("y", d), g && r) {
192
- l.text(i(g.value)), n.text(o(g.date));
193
- const c = a.node().getBoundingClientRect(), h = 16, u = r + h + c.width > e.config.width - e.config.margin.right ? r - h - c.width : r + h;
194
- s.attr("x", u);
190
+ update({ x: r, y: c, hidden: u, dataItem: g }) {
191
+ if (r !== void 0 && a.attr("x", r), c !== void 0 && a.attr("y", c), g && r !== void 0) {
192
+ l.text(i(g.value)), o.text(n(g.date));
193
+ const d = s.node().getBoundingClientRect(), h = 16, m = r + h + d.width > e.config.width - e.config.margin.right ? r - h - d.width : r + h;
194
+ a.attr("x", m);
195
195
  }
196
- f !== void 0 && s.style("display", f ? "none" : "block");
196
+ u !== void 0 && a.style("display", u ? "none" : "block");
197
197
  },
198
198
  destroy() {
199
- s.remove();
199
+ a.remove();
200
200
  }
201
201
  };
202
202
  }, X = {
@@ -235,8 +235,8 @@ const M = (e) => {
235
235
  enableBelowZeroLine: !1,
236
236
  curveTension: 1
237
237
  }, _ = (e) => v.curveCardinal.tension(e.config.curveTension), Y = (e) => {
238
- const { svg: t, data: s, x: a, y: l, config: n } = e, o = t.node(), i = C(o);
239
- $(i, "main-line-area-gradient", {
238
+ const { svg: t, data: a, x: s, y: l, config: o } = e, n = t.node(), i = C(n);
239
+ k(i, "main-line-area-gradient", {
240
240
  x1: "0%",
241
241
  y1: "0%",
242
242
  x2: "0%",
@@ -246,15 +246,15 @@ const M = (e) => {
246
246
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
247
247
  ]
248
248
  });
249
- const d = v.area().x((c) => a(c.date)).y0(l.range()[0]).y1((c) => l(c.value)).curve(_(e)), f = "sc-charts__main-line-area", g = t.append("path").datum(s).attr("d", d).attr("class", f).classed(`${f}_hidden`, !n.hasMainLineArea);
249
+ const c = v.area().x((d) => s(d.date)).y0(l.range()[0]).y1((d) => l(d.value)).curve(_(e)), u = "sc-charts__main-line-area", g = t.append("path").datum(a).attr("d", c).attr("class", u).classed(`${u}_hidden`, !o.hasMainLineArea);
250
250
  return {
251
- className(c, h) {
252
- c === "remove" ? g.classed(`${f}${h}`, !1) : g.classed(`${f}${h}`, !0);
251
+ className(d, h) {
252
+ d === "remove" ? g.classed(`${u}${h}`, !1) : g.classed(`${u}${h}`, !0);
253
253
  },
254
- update({ data: c, hidden: h }) {
255
- if (c !== void 0 && g.datum(c).attr("d", d), h !== void 0) {
256
- if (!n.hasMainLineArea) return null;
257
- g.classed(`${f}_hidden`, h);
254
+ update({ data: d, hidden: h }) {
255
+ if (d !== void 0 && g.datum(d).attr("d", c), h !== void 0) {
256
+ if (!o.hasMainLineArea) return null;
257
+ g.classed(`${u}_hidden`, h);
258
258
  }
259
259
  },
260
260
  destroy() {
@@ -262,8 +262,8 @@ const M = (e) => {
262
262
  }
263
263
  };
264
264
  }, j = (e, t = {}) => {
265
- const s = "sc-charts__range-line-area", { svg: a, x: l, y: n, config: o, data: i, chartId: r } = e, { clip: d } = t, f = a.node(), g = C(f), c = "range-line-area-gradient";
266
- $(g, c + "_up", {
265
+ const a = "sc-charts__range-line-area", { svg: s, x: l, y: o, config: n, data: i, chartId: r } = e, { clip: c } = t, u = s.node(), g = C(u), d = "range-line-area-gradient";
266
+ k(g, d + "_up", {
267
267
  x1: "0%",
268
268
  y1: "0%",
269
269
  x2: "0%",
@@ -272,7 +272,7 @@ const M = (e) => {
272
272
  { offset: "0%", stopColor: "var(--sc-color-selection-up)" },
273
273
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
274
274
  ]
275
- }), $(g, c + "_down", {
275
+ }), k(g, d + "_down", {
276
276
  x1: "0%",
277
277
  y1: "0%",
278
278
  x2: "0%",
@@ -282,91 +282,89 @@ const M = (e) => {
282
282
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
283
283
  ]
284
284
  });
285
- const h = v.area().x((w) => l(w.date)).y0(n.range()[0]).y1((w) => n(w.value)).curve(_(e)), u = `${r}-clip-${s}`, p = g.append("clipPath").attr("id", u).append("rect").attr("x", (d == null ? void 0 : d.x) || 0).attr("y", (d == null ? void 0 : d.y) || 0).attr("width", (d == null ? void 0 : d.width) || "100%").attr("height", (d == null ? void 0 : d.height) || "100%"), y = a.append("path").datum(i).attr("d", h).attr("class", s).classed(`${s}_hidden`, !o.hasMainLineArea).attr("clip-path", `url(#${u})`);
285
+ const h = v.area().x((w) => l(w.date)).y0(o.range()[0]).y1((w) => o(w.value)).curve(_(e)), m = `${r}-clip-${a}`, p = g.append("clipPath").attr("id", m).append("rect").attr("x", (c == null ? void 0 : c.x) || 0).attr("y", (c == null ? void 0 : c.y) || 0).attr("width", (c == null ? void 0 : c.width) || "100%").attr("height", (c == null ? void 0 : c.height) || "100%"), y = s.append("path").datum(i).attr("d", h).attr("class", a).classed(`${a}_hidden`, !n.hasMainLineArea).attr("clip-path", `url(#${m})`);
286
286
  return {
287
287
  className(w, x) {
288
- w === "remove" ? y.classed(`${s}${x}`, !1) : y.classed(`${s}${x}`, !0);
288
+ w === "remove" ? y.classed(`${a}${x}`, !1) : y.classed(`${a}${x}`, !0);
289
289
  },
290
- update({ data: w, hidden: x, clip: k }) {
291
- w !== void 0 && y.datum(w).attr("d", h), x !== void 0 && y.classed(`${s}_hidden`, x), k !== void 0 && p.attr("x", k.x).attr("y", k.y).attr("width", k.width).attr("height", k.height);
290
+ update({ data: w, hidden: x, clip: $ }) {
291
+ w !== void 0 && y.datum(w).attr("d", h), x !== void 0 && y.classed(`${a}_hidden`, x), $ !== void 0 && p.attr("x", $.x).attr("y", $.y).attr("width", $.width).attr("height", $.height);
292
292
  },
293
293
  destroy() {
294
294
  y.remove();
295
295
  }
296
296
  };
297
297
  }, b = (e, t) => {
298
- const { svg: s, data: a, x: l, y: n } = e, { baseClassName: o, id: i, clip: r } = t, d = s.node(), f = C(d), g = v.line().x((m) => l(m.date)).y((m) => n(m.value)).curve(_(e)), h = f.append("clipPath").attr("id", `clip-${i}`).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%");
299
- console.log(a);
300
- const u = s.append("path").classed(o, !0).datum(a).attr("d", g).attr("id", i).attr("clip-path", `url(#clip-${i})`);
298
+ const { svg: a, data: s, x: l, y: o } = e, { baseClassName: n, id: i, clip: r } = t, c = a.node(), u = C(c), g = v.line().x((f) => l(f.date)).y((f) => o(f.value)).curve(_(e)), h = u.append("clipPath").attr("id", `clip-${i}`).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%"), m = a.append("path").classed(n, !0).datum(s).attr("d", g).attr("id", i).attr("clip-path", `url(#clip-${i})`);
301
299
  return {
302
- className(m, p) {
303
- m === "remove" ? u.classed(`${o}${p}`, !1) : u.classed(`${o}${p}`, !0);
300
+ className(f, p) {
301
+ f === "remove" ? m.classed(`${n}${p}`, !1) : m.classed(`${n}${p}`, !0);
304
302
  },
305
- update({ data: m, clip: p, hidden: y }) {
306
- m !== void 0 && u.datum(m).attr("d", g), y !== void 0 && u.classed(`${o}_hidden`, y), p !== void 0 && h.attr("x", p.x).attr("y", p.y).attr("width", p.width).attr("height", p.height);
303
+ update({ data: f, clip: p, hidden: y }) {
304
+ f !== void 0 && m.datum(f).attr("d", g), y !== void 0 && m.classed(`${n}_hidden`, y), p !== void 0 && h.attr("x", p.x).attr("y", p.y).attr("width", p.width).attr("height", p.height);
307
305
  },
308
306
  destroy() {
309
- u.remove();
307
+ m.remove();
310
308
  }
311
309
  };
312
310
  }, W = (e) => {
313
311
  const t = b(e, {
314
312
  baseClassName: "sc-charts__main-line",
315
313
  id: `${e.chartId}-sc-charts__main-line`
316
- }), s = Y(e), a = G(e.svg), l = b(e, {
314
+ }), a = Y(e), s = G(e.svg), l = b(e, {
317
315
  baseClassName: "sc-charts__highlight-line",
318
316
  id: `${e.chartId}-sc-charts__highlight-line`,
319
317
  clip: { x: 0, y: 0, width: "0", height: "0" }
320
318
  });
321
- let n = null;
322
- e.config.enableBelowZeroLine && (n = b(e, {
319
+ let o = null;
320
+ e.config.enableBelowZeroLine && (o = b(e, {
323
321
  baseClassName: "sc-charts__below-zero-line",
324
322
  id: `${e.chartId}-sc-charts__below-zero-line`,
325
323
  clip: B(e)
326
324
  }));
327
- const o = L(e.svg, {
325
+ const n = L(e.svg, {
328
326
  className: "sc-charts__hover-circle",
329
327
  hidden: !0
330
- }), i = N(e.svg), r = N(e.svg), d = b(e, {
328
+ }), i = N(e.svg), r = N(e.svg), c = b(e, {
331
329
  baseClassName: "sc-charts__range-line",
332
330
  id: `${e.chartId}-sc-charts__range-line`,
333
331
  clip: { x: 0, y: 0, width: "0", height: "0" }
334
- }), f = L(e.svg, {
332
+ }), u = L(e.svg, {
335
333
  className: "sc-charts__range-circle-left",
336
334
  hidden: !0
337
335
  }), g = L(e.svg, {
338
336
  className: "sc-charts__range-circle-right",
339
337
  hidden: !0
340
- }), c = H(e), h = E(e), u = j(e);
338
+ }), d = H(e), h = E(e), m = j(e);
341
339
  return {
342
- hoverLine: a,
343
- hoverCircle: o,
340
+ hoverLine: s,
341
+ hoverCircle: n,
344
342
  rangeBorderLeft: i,
345
343
  rangeBorderRight: r,
346
- rangeLine: d,
347
- rangeLineArea: u,
348
- rangeCircleLeft: f,
344
+ rangeLine: c,
345
+ rangeLineArea: m,
346
+ rangeCircleLeft: u,
349
347
  rangeCircleRight: g,
350
348
  mainLine: t,
351
- rangeTooltip: c,
349
+ rangeTooltip: d,
352
350
  highlightLine: l,
353
351
  hoverTooltip: h,
354
- mainLineArea: s,
355
- belowZeroLine: n
352
+ mainLineArea: a,
353
+ belowZeroLine: o
356
354
  };
357
- }, O = (e, t, s) => {
358
- let a, l;
355
+ }, O = (e, t, a) => {
356
+ let s, l;
359
357
  switch (e) {
360
358
  case "day":
361
- a = new Date(t), a.setHours(0, 0, 0, 0), l = new Date(a), l.setDate(a.getDate() + 1);
359
+ s = new Date(t), s.setHours(0, 0, 0, 0), l = new Date(s), l.setDate(s.getDate() + 1);
362
360
  break;
363
361
  case "week": {
364
362
  const i = t.getDay(), r = t.getDate() - i + (i === 0 ? -6 : 1);
365
- a = new Date(t.getFullYear(), t.getMonth(), r), a.setHours(0, 0, 0, 0), l = new Date(a), l.setDate(a.getDate() + 7);
363
+ s = new Date(t.getFullYear(), t.getMonth(), r), s.setHours(0, 0, 0, 0), l = new Date(s), l.setDate(s.getDate() + 7);
366
364
  break;
367
365
  }
368
366
  case "month":
369
- a = new Date(t.getFullYear(), t.getMonth(), 1), l = new Date(t.getFullYear(), t.getMonth() + 1, 1);
367
+ s = new Date(t.getFullYear(), t.getMonth(), 1), l = new Date(t.getFullYear(), t.getMonth() + 1, 1);
370
368
  break;
371
369
  default:
372
370
  return {
@@ -376,52 +374,52 @@ const M = (e) => {
376
374
  height: "100%"
377
375
  };
378
376
  }
379
- const n = s(a), o = s(l);
377
+ const o = a(s), n = a(l);
380
378
  return {
381
- x: n,
379
+ x: o,
382
380
  y: 0,
383
- width: o - n,
381
+ width: n - o,
384
382
  height: "100%"
385
383
  };
386
384
  }, T = (e, t) => {
387
- var d;
385
+ var c;
388
386
  const {
389
- x: s,
390
- y: a,
387
+ x: a,
388
+ y: s,
391
389
  elements: l,
392
- config: { margin: n, height: o, hoverRange: i }
390
+ config: { margin: o, height: n, hoverRange: i }
393
391
  } = e;
394
392
  l.hoverLine.update({
395
- x1: s(t.date),
396
- x2: s(t.date),
397
- y1: n.top,
398
- y2: o - n.bottom,
393
+ x1: a(t.date),
394
+ x2: a(t.date),
395
+ y1: o.top,
396
+ y2: n - o.bottom,
399
397
  hidden: !1
400
398
  }), l.hoverCircle.update({
401
- cx: s(t.date),
402
- cy: a(t.value),
399
+ cx: a(t.date),
400
+ cy: s(t.value),
403
401
  hidden: !1
404
402
  }), l.hoverTooltip.update({
405
403
  dataItem: t,
406
- x: s(t.date),
404
+ x: a(t.date),
407
405
  y: 0,
408
406
  hidden: !1
409
407
  });
410
- const r = O(i, t.date, s);
408
+ const r = O(i, t.date, a);
411
409
  l.highlightLine.update({
412
410
  clip: r,
413
411
  hidden: !1
414
- }), (d = l.belowZeroLine) == null || d.update({
412
+ }), (c = l.belowZeroLine) == null || c.update({
415
413
  clip: {
416
414
  ...r,
417
- y: a(0),
418
- height: a.range()[0] - a(0) + n.bottom
415
+ y: s(0),
416
+ height: s.range()[0] - s(0) + o.bottom
419
417
  }
420
418
  }), l.mainLine.className("add", "_muted");
421
419
  }, D = (e) => {
422
- var s;
420
+ var a;
423
421
  const { elements: t } = e;
424
- 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" && ((s = t.belowZeroLine) == null || s.update({
422
+ 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({
425
423
  clip: B(e)
426
424
  }));
427
425
  }, P = (e, t) => {
@@ -433,36 +431,36 @@ const M = (e) => {
433
431
  "rangeLine",
434
432
  "rangeLineArea",
435
433
  "rangeTooltip"
436
- ].forEach((a) => {
437
- t ? (e[a].className("remove", "_down"), e[a].className("add", "_up")) : (e[a].className("remove", "_up"), e[a].className("add", "_down"));
434
+ ].forEach((s) => {
435
+ t ? (e[s].className("remove", "_down"), e[s].className("add", "_up")) : (e[s].className("remove", "_up"), e[s].className("add", "_down"));
438
436
  });
439
- }, U = (e, t, s) => {
440
- var u;
437
+ }, U = (e, t, a) => {
438
+ var m;
441
439
  const {
442
- x: a,
440
+ x: s,
443
441
  y: l,
444
- config: { margin: n, height: o },
442
+ config: { margin: o, height: n },
445
443
  elements: i
446
- } = e, r = a(t.date) < a(s.date) ? t : s, d = a(t.date) >= a(s.date) ? t : s, f = d.value - r.value >= 0, g = a(r.date), c = a(d.date), h = c - g;
444
+ } = e, r = s(t.date) < s(a.date) ? t : a, c = s(t.date) >= s(a.date) ? t : a, u = c.value - r.value >= 0, g = s(r.date), d = s(c.date), h = d - g;
447
445
  i.rangeBorderLeft.update({
448
446
  x1: g,
449
447
  x2: g,
450
- y1: n.top,
451
- y2: o - n.bottom,
448
+ y1: o.top,
449
+ y2: n - o.bottom,
452
450
  hidden: !1
453
451
  }), i.rangeBorderRight.update({
454
- x1: c,
455
- x2: c,
456
- y1: n.top,
457
- y2: o - n.bottom,
452
+ x1: d,
453
+ x2: d,
454
+ y1: o.top,
455
+ y2: n - o.bottom,
458
456
  hidden: !1
459
457
  }), i.rangeCircleLeft.update({
460
458
  cx: g,
461
459
  cy: l(r.value),
462
460
  hidden: !1
463
461
  }), i.rangeCircleRight.update({
464
- cx: c,
465
- cy: l(d.value),
462
+ cx: d,
463
+ cy: l(c.value),
466
464
  hidden: !1
467
465
  }), i.rangeLine.update({
468
466
  clip: {
@@ -481,75 +479,77 @@ const M = (e) => {
481
479
  },
482
480
  hidden: !1
483
481
  }), i.rangeTooltip.update({
484
- rightPoint: d,
482
+ rightPoint: c,
485
483
  leftPoint: r,
486
484
  x: g + h / 2,
487
485
  y: 0,
488
486
  hidden: !1
489
- }), (u = i.belowZeroLine) == null || u.update({
487
+ }), (m = i.belowZeroLine) == null || m.update({
490
488
  hidden: !0
491
- }), i.mainLineArea.update({ hidden: !0 }), P(i, f), i.mainLine.className("add", "_selected-muted");
489
+ }), i.mainLineArea.update({ hidden: !0 }), P(i, u), i.mainLine.className("add", "_selected-muted");
492
490
  }, R = (e) => {
493
- var s;
491
+ var a;
494
492
  const { elements: t } = e;
495
- 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 }), (s = t.belowZeroLine) == null || s.update({ hidden: !1 });
493
+ 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 });
496
494
  }, q = (e) => {
497
- const { svg: t, data: s, x: a, config: l } = e, { height: n, margin: o, width: i, enableSelection: r, enableHover: d } = l;
498
- let f = null, g = !1;
499
- const c = (u) => s.reduce((m, p) => Math.abs(a(m.date) - u) < Math.abs(a(p.date) - u) ? m : p);
500
- t.append("rect").attr("width", i - o.left - o.right).attr("height", n - o.top - o.bottom).attr("x", o.left).attr("y", o.top).attr("fill", "transparent").on("mousemove", function(u) {
501
- const [m] = v.pointer(u, this), p = c(m);
502
- !g && d ? (e.action = "hover", T(e, p)) : (e.action = g ? "selection" : "none", D(e)), f && r && (e.action = "selection", U(e, f, p));
495
+ const { svg: t, data: a, x: s, config: l } = e, { height: o, margin: n, width: i, enableSelection: r, enableHover: c } = l;
496
+ let u = null, g = !1;
497
+ const d = (m) => a.reduce(
498
+ (f, p) => Math.abs(s(f.date) - m) < Math.abs(s(p.date) - m) ? f : p
499
+ );
500
+ t.append("rect").attr("width", i - n.left - n.right).attr("height", o - n.top - n.bottom).attr("x", n.left).attr("y", n.top).attr("fill", "transparent").on("mousemove", function(m) {
501
+ const [f] = v.pointer(m, this), p = d(f);
502
+ !g && c ? (e.action = "hover", T(e, p)) : (e.action = g ? "selection" : "none", D(e)), u && r && (e.action = "selection", U(e, u, p));
503
503
  }).on("mouseleave", () => {
504
- e.action = "none", g = !1, f = null, D(e), R(e);
505
- }).on("mousedown", function(u) {
504
+ e.action = "none", g = !1, u = null, D(e), R(e);
505
+ }).on("mousedown", function(m) {
506
506
  if (r) {
507
507
  g = !0, e.action = "selection";
508
- const [m] = v.pointer(u, this);
509
- f = c(m);
508
+ const [f] = v.pointer(m, this);
509
+ u = d(f);
510
510
  }
511
- }).on("mouseup", function(u) {
512
- const [m] = v.pointer(u, this), p = c(m);
513
- g = !1, f = null, e.action = "hover", r && R(e), d && T(e, p);
511
+ }).on("mouseup", function(m) {
512
+ const [f] = v.pointer(m, this), p = d(f);
513
+ g = !1, u = null, e.action = "hover", r && R(e), c && T(e, p);
514
514
  });
515
515
  }, J = (e, t) => {
516
- const { width: s, margin: a } = t, l = v.scaleTime(), n = v.extent(e, (o) => new Date(o.date));
517
- return n[0] == null || n[1] == null ? l : l.domain([n[0], n[1]]).range([a.left, s - a.right]);
516
+ const { width: a, margin: s } = t, l = v.scaleTime(), o = v.extent(e, (n) => new Date(n.date));
517
+ return o[0] == null || o[1] == null ? l : l.domain([o[0], o[1]]).range([s.left, a - s.right]);
518
518
  }, K = (e, t) => {
519
- const { height: s, margin: a } = t, l = v.max(e, (o) => o.value) ?? 0, n = v.min(e, (o) => o.value) ?? 0;
520
- return v.scaleLinear().domain([n, l]).range([s - a.bottom, a.top]);
519
+ const { height: a, margin: s } = t, l = v.max(e, (n) => n.value) ?? 0, o = v.min(e, (n) => n.value) ?? 0;
520
+ return v.scaleLinear().domain([o, l]).range([a - s.bottom, s.top]);
521
521
  }, Q = (e, t) => {
522
- const s = v.select(e);
523
- if (s.empty())
522
+ const a = v.select(e);
523
+ if (a.empty())
524
524
  return console.error(`Element with selector ${e} not found!`), null;
525
525
  if (!t.chartId || !/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.chartId))
526
526
  return console.error(`chartId is required and must be a valid id
527
527
  (only letters, numbers or underscores. The first character must be a letter)`), null;
528
- const a = s.append("svg"), n = s.node().getBoundingClientRect(), o = n.width, i = n.height;
529
- let r = A({ ...X, width: o, height: i }, t.config);
530
- const d = (f, g = !1) => {
531
- g && f.config && (r = A(r, f.config));
532
- const c = f.data.map((y) => ({ date: new Date(y.date), value: y.value })).sort((y, w) => y.date.getTime() - w.date.getTime()), h = J(c, r), u = K(c, r);
533
- a.attr("class", `sc-charts sc-charts__${r.theme}`).attr("preserveAspectRatio", "xMinYMin meet").attr("viewBox", `0 0 ${o} ${i}`).style("width", "100%").style("height", "100%").selectAll("*").remove();
534
- const m = {
528
+ const s = a.append("svg"), o = a.node().getBoundingClientRect(), n = o.width, i = o.height;
529
+ let r = A({ ...X, width: n, height: i }, t.config);
530
+ const c = (u, g = !1) => {
531
+ g && u.config && (r = A(r, u.config));
532
+ const d = u.data.map((y) => ({ date: new Date(y.date), value: y.value })).sort((y, w) => y.date.getTime() - w.date.getTime()), h = J(d, r), m = K(d, r);
533
+ s.attr("class", `sc-charts sc-charts__${r.theme}`).attr("preserveAspectRatio", "xMinYMin meet").attr("viewBox", `0 0 ${n} ${i}`).style("width", "100%").style("height", "100%").selectAll("*").remove();
534
+ const f = {
535
535
  chartId: t.chartId,
536
- svg: a,
537
- data: c,
536
+ svg: s,
537
+ data: d,
538
538
  x: h,
539
- y: u,
539
+ y: m,
540
540
  config: r,
541
541
  action: "none"
542
542
  };
543
- Z(m);
543
+ Z(f);
544
544
  const p = {
545
- ...m,
546
- elements: W(m)
545
+ ...f,
546
+ elements: W(f)
547
547
  };
548
548
  q(p);
549
549
  };
550
- return d(t), {
551
- update: (f) => d(f, !0),
552
- destroy: () => a.remove()
550
+ return c(t), {
551
+ update: (u) => c(u, !0),
552
+ destroy: () => s.remove()
553
553
  };
554
554
  };
555
555
  export {