charts-core 1.0.1 → 1.0.2

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,73 +1,73 @@
1
- import * as w from "d3";
1
+ import * as y from "d3";
2
2
  const G = (e) => {
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;
3
+ const { svg: t, config: a, y: r } = e, { width: d, margin: n, yAxis: s } = a, { customTicks: l, tickFormat: i, tickValues: o, ticks: c, isShow: u } = s;
4
4
  if (!u) return null;
5
- t.append("g").attr("transform", `translate(${c - i.right},0)`).call((h) => {
6
- let g = w.axisRight(s);
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), y = x < 0 ? "-" : "", v = w.format(".0s")(Math.abs(x));
9
- return `${y}${v}`;
5
+ t.append("g").attr("transform", `translate(${d - n.right},0)`).call((h) => {
6
+ let g = y.axisRight(r);
7
+ l ? (i && (g = g.tickFormat(i)), c && (g = Array.isArray(c) ? g.ticks(...c) : g.ticks(c)), o && (g = g.tickValues(o))) : g = g.tickFormat((m) => {
8
+ const x = Number(m), v = x < 0 ? "-" : "", p = y.format(".0s")(Math.abs(x));
9
+ return `${v}${p}`;
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
- 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
- if (!d) return null;
18
- t.append("g").attr("transform", `translate(0,${c - i.bottom})`).call((h) => {
19
- let g = w.axisBottom(s);
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);
16
+ const { svg: t, config: a, x: r } = e, { height: d, margin: n, xAxis: s } = a, { isShow: l, tickValues: i, tickFormat: o, customTicks: c, ticks: u } = s;
17
+ if (!l) return null;
18
+ t.append("g").attr("transform", `translate(0,${d - n.bottom})`).call((h) => {
19
+ let g = y.axisBottom(r);
20
+ c ? (o && (g = g.tickFormat(o)), u && (g = Array.isArray(u) ? g.ticks(...u) : g.ticks(u)), i && (g = g.tickValues(i))) : 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
- const { svg: t, config: a, y: s } = e, {
27
- width: c,
28
- margin: i,
29
- grid: { horizontalStyle: o }
26
+ const { svg: t, config: a, y: r } = e, {
27
+ width: d,
28
+ margin: n,
29
+ grid: { horizontalStyle: s }
30
30
  } = a;
31
- if (o !== "none") {
32
- if (o.startsWith("zero-line")) {
33
- const d = t.append("line").attr("x1", 0 + i.left).attr("x2", c - i.right).attr("y1", s(0)).attr("y2", s(0)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
34
- o === "zero-line-dashed" && d.attr("stroke-dasharray", "4 4");
31
+ if (s !== "none") {
32
+ if (s.startsWith("zero-line")) {
33
+ const l = t.append("line").attr("x1", 0 + n.left).attr("x2", d - n.right).attr("y1", r(0)).attr("y2", r(0)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
34
+ s === "zero-line-dashed" && l.attr("stroke-dasharray", "4 4");
35
35
  }
36
- o.startsWith("every-line") && (e.yTicks || s.ticks()).forEach((n) => {
37
- const r = t.append("line").attr("x1", 0 + i.left).attr("x2", c - i.right).attr("y1", s(n)).attr("y2", s(n)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
38
- o === "every-line-dashed" && r.attr("stroke-dasharray", "4 4");
36
+ s.startsWith("every-line") && (e.yTicks || r.ticks()).forEach((i) => {
37
+ const o = t.append("line").attr("x1", 0 + n.left).attr("x2", d - n.right).attr("y1", r(i)).attr("y2", r(i)).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
38
+ s === "every-line-dashed" && o.attr("stroke-dasharray", "4 4");
39
39
  });
40
40
  }
41
- }, E = (e) => {
42
- const { svg: t, config: a, x: s } = e, {
43
- height: c,
44
- margin: i,
45
- grid: { verticalStyle: o }
41
+ }, H = (e) => {
42
+ const { svg: t, config: a, x: r } = e, {
43
+ height: d,
44
+ margin: n,
45
+ grid: { verticalStyle: s }
46
46
  } = a;
47
- o !== "none" && o.startsWith("every-line") && (e.xTicks || s.ticks()).forEach((n) => {
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
- o === "every-line-dashed" && r.attr("stroke-dasharray", "4 4");
47
+ s !== "none" && s.startsWith("every-line") && (e.xTicks || r.ticks()).forEach((i) => {
48
+ const o = t.append("line").attr("x1", r(i)).attr("x2", r(i)).attr("y1", n.top).attr("y2", d - n.bottom).attr("stroke", "var(--sc-color-axis-zero-line)").attr("stroke-width", 1);
49
+ s === "every-line-dashed" && o.attr("stroke-dasharray", "4 4");
50
50
  });
51
- }, H = (e) => {
52
- Z(e), E(e);
53
51
  }, X = (e) => {
54
- const { svg: t, config: a } = e, { width: s, height: c, margin: i, logo: o } = a;
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
- }, C = (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: c, stopColor: i }) => {
59
- s.append("stop").attr("offset", c).attr("stop-color", i);
60
- }), s;
61
- }, k = (e) => {
62
- const t = w.select(e).select("defs");
63
- return t.empty() ? w.select(e).append("defs") : t;
64
- }, B = (e) => {
52
+ Z(e), H(e);
53
+ }, P = (e) => {
54
+ const { svg: t, config: a } = e, { width: r, height: d, margin: n, logo: s } = a;
55
+ V(e), G(e), s && t.append("image").attr("xlink:href", a.theme === "dark" ? s.picDarkTheme : s.picLightTheme).attr("width", s.width).attr("height", s.height).attr("x", s.x ?? (r - n.left - n.right) / 2 - s.width / 2 + n.left).attr("y", s.y ?? (d - n.top - n.bottom) / 2 - s.height / 2 + n.top), X(e);
56
+ }, _ = (e, t, a) => {
57
+ let r = e.select(`#${t}`);
58
+ return r.empty() && (r = e.append("linearGradient").attr("gradientUnits", "userSpaceOnUse").attr("id", t)), r.attr("x1", a.x1).attr("y1", a.x2).attr("x2", a.y1).attr("y2", a.y2), a.stops.forEach(({ offset: d, stopColor: n }) => {
59
+ r.append("stop").attr("offset", d).attr("stop-color", n);
60
+ }), r;
61
+ }, L = (e) => {
62
+ const t = y.select(e).select("defs");
63
+ return t.empty() ? y.select(e).append("defs") : t;
64
+ }, z = (e) => {
65
65
  const {
66
66
  y: t,
67
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
- }, I = (e, t) => ({
68
+ } = e, r = t.range()[0] - t(0);
69
+ return { x: 0, y: t.range()[0] - r, width: "100%", height: r + a.bottom };
70
+ }, M = (e, t) => ({
71
71
  ...e,
72
72
  ...t,
73
73
  margin: {
@@ -102,121 +102,139 @@ const G = (e) => {
102
102
  ...e.selection,
103
103
  ...t == null ? void 0 : t.selection
104
104
  }
105
- }), M = (e, t = {}) => {
106
- const a = e.node(), s = k(a), c = (d, n) => C(s, d, {
105
+ }), R = (e, t = {}) => {
106
+ const a = e.node(), r = L(a), d = (l, i) => _(r, l, {
107
107
  x1: "0%",
108
108
  y1: "0%",
109
109
  x2: "0%",
110
110
  y2: "100%",
111
111
  stops: [
112
112
  { offset: "0%", stopColor: "rgba(255, 255, 255, 0)" },
113
- { offset: "20%", stopColor: n },
114
- { offset: "60%", stopColor: n },
113
+ { offset: "20%", stopColor: i },
114
+ { offset: "60%", stopColor: i },
115
115
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
116
116
  ]
117
117
  });
118
- c("gradient-range-borders-up", "var(--sc-color-selection-up)"), c("gradient-range-borders-down", "var(--sc-color-selection-down)");
119
- const i = "sc-charts__border-range-line", o = e.append("line").classed(i, !0).style("display", t.hidden ? "none" : "block");
118
+ d("gradient-range-borders-up", "var(--sc-color-selection-up)"), d("gradient-range-borders-down", "var(--sc-color-selection-down)");
119
+ const n = "sc-charts__border-range-line", s = e.append("line").classed(n, !0).style("display", t.hidden ? "none" : "block");
120
120
  return {
121
- className(d, n) {
122
- d === "remove" ? o.classed(`${i}${n}`, !1) : o.classed(`${i}${n}`, !0);
121
+ className(l, i) {
122
+ l === "remove" ? s.classed(`${n}${i}`, !1) : s.classed(`${n}${i}`, !0);
123
123
  },
124
- update({ x1: d, x2: n, y1: r, y2: l, hidden: u }) {
125
- d !== void 0 && o.attr("x1", d), n !== void 0 && o.attr("x2", n), r !== void 0 && o.attr("y1", r), l !== void 0 && o.attr("y2", l), u !== void 0 && o.style("display", u ? "none" : "block");
124
+ update({ x1: l, x2: i, y1: o, y2: c, hidden: u }) {
125
+ l !== void 0 && s.attr("x1", l), i !== void 0 && s.attr("x2", i), o !== void 0 && s.attr("y1", o), c !== void 0 && s.attr("y2", c), u !== void 0 && s.style("display", u ? "none" : "block");
126
126
  },
127
127
  destroy() {
128
- o.remove();
128
+ s.remove();
129
129
  }
130
130
  };
131
- }, _ = (e, t = {}) => {
132
- const a = e.append("circle").attr("r", t.radius || 4).style("display", t.hidden ? "none" : "block"), s = t.className || "";
133
- return s && a.classed(s, !0), {
134
- className(c, i) {
135
- c === "remove" ? a.classed(`${s}${i}`, !1) : a.classed(`${s}${i}`, !0);
131
+ }, A = (e, t = {}) => {
132
+ const a = e.append("circle").attr("r", t.radius || 4).style("display", t.hidden ? "none" : "block"), r = t.className || "";
133
+ return r && a.classed(r, !0), {
134
+ className(d, n) {
135
+ d === "remove" ? a.classed(`${r}${n}`, !1) : a.classed(`${r}${n}`, !0);
136
136
  },
137
- update({ cx: c, cy: i, hidden: o, fill: d }) {
138
- c !== void 0 && a.attr("cx", c), i !== void 0 && a.attr("cy", i), d !== void 0 && a.attr("fill", d), o !== void 0 && a.style("display", o ? "none" : "block");
137
+ update({ cx: d, cy: n, hidden: s, fill: l }) {
138
+ d !== void 0 && a.attr("cx", d), n !== void 0 && a.attr("cy", n), l !== void 0 && a.attr("fill", l), s !== void 0 && a.style("display", s ? "none" : "block");
139
139
  },
140
140
  destroy() {
141
141
  a.remove();
142
142
  }
143
143
  };
144
- }, j = (e, t = {}) => {
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
- return ((d, n) => C(i, d, {
144
+ }, W = (e, t = {}) => {
145
+ const a = "sc-charts__hover-line", r = e.append("line").style("display", t.hidden ? "none" : "block").classed(a, !0), d = e.node(), n = L(d);
146
+ return ((l, i) => _(n, l, {
147
147
  x1: "0%",
148
148
  y1: "0%",
149
149
  x2: "0%",
150
150
  y2: "100%",
151
151
  stops: [
152
152
  { offset: "0%", stopColor: "rgba(255, 255, 255, 0)" },
153
- { offset: "15%", stopColor: n },
154
- { offset: "75%", stopColor: n },
153
+ { offset: "15%", stopColor: i },
154
+ { offset: "75%", stopColor: i },
155
155
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
156
156
  ]
157
157
  }))("hover-line-gradient", "var(--sc-color-hover-line)"), {
158
- className(d, n) {
159
- d === "remove" ? s.classed(`${a}${n}`, !1) : s.classed(`${a}${n}`, !0);
158
+ className(l, i) {
159
+ l === "remove" ? r.classed(`${a}${i}`, !1) : r.classed(`${a}${i}`, !0);
160
160
  },
161
- update({ x1: d, x2: n, y1: r, y2: l, hidden: u }) {
162
- d !== void 0 && s.attr("x1", d), n !== void 0 && s.attr("x2", n), r !== void 0 && s.attr("y1", r), l !== void 0 && s.attr("y2", l), u !== void 0 && s.style("display", u ? "none" : "block");
161
+ update({ x1: l, x2: i, y1: o, y2: c, hidden: u }) {
162
+ l !== void 0 && r.attr("x1", l), i !== void 0 && r.attr("x2", i), o !== void 0 && r.attr("y1", o), c !== void 0 && r.attr("y2", c), u !== void 0 && r.style("display", u ? "none" : "block");
163
163
  },
164
164
  destroy() {
165
- s.remove();
165
+ r.remove();
166
166
  }
167
167
  };
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
- return `${n < 0 ? "-" : ""}$${r(Math.abs(n))}`;
172
- };
168
+ }, k = "sc-charts__range-tooltip", B = y.timeFormat("%b %e, %I:%M %p"), Y = (e) => {
169
+ const t = y.format(",.2f");
170
+ return `${e < 0 ? "-" : ""}$${t(Math.abs(e))}`;
171
+ };
172
+ function q(e) {
173
+ const t = e.append("foreignObject").classed(k, !0).style("display", "none"), a = t.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${k}-container`), r = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${k}-sum`), d = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${k}-time`);
174
+ return r.text("").append("xhtml:div").html(O).attr("class", `${k}-sum-icon`), { wrapper: t, parent: a, sumNode: r, timeNode: d };
175
+ }
176
+ const j = (e) => {
177
+ const { wrapper: t, parent: a, sumNode: r, timeNode: d } = q(e.svg);
173
178
  return {
174
- className(n, r) {
175
- n === "remove" ? a.classed(`${t}${r}`, !1) : a.classed(`${t}${r}`, !0);
179
+ className(n, s) {
180
+ n === "remove" ? t.classed(`${k}${s}`, !1) : t.classed(`${k}${s}`, !0);
176
181
  },
177
- update({ leftPoint: n, rightPoint: r, x: l, y: u, hidden: h, closest: g }) {
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, 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
- const A = e.x(e.data[e.data.length - 1].date), T = e.x(e.data[0].date), b = s.node().getBoundingClientRect();
185
- b.x < T && a.attr("x", T + b.width / 2), b.x > A - b.width && a.attr("x", A - b.width / 2);
182
+ update({ leftPoint: n, rightPoint: s, x: l, y: i, hidden: o, closest: c }) {
183
+ if (l !== void 0 && t.attr("x", l), i !== void 0 && t.attr("y", i), n && s && c && l !== void 0) {
184
+ const { comparisonValue: u, hidePercent: h } = e.config.selection, g = s.value - n.value, m = (e.x(s.date) + e.x(n.date)) / 2, x = e.x(c.date) < m ? n.value : s.value;
185
+ let v = null;
186
+ h || (u && u !== 0 && x !== 0 ? v = (x / u * 100).toFixed(2) : n.value && (v = (g / Math.abs(n.value) * 100).toFixed(2)));
187
+ const p = v === null ? "" : `(${v}%)`, f = `${Y(g)}${p}`, w = `${B(n.date)} to ${B(s.date)}`;
188
+ r.text(f), d.text(w);
189
+ const $ = e.x(e.data[e.data.length - 1].date), I = e.x(e.data[0].date);
190
+ requestAnimationFrame(() => {
191
+ const b = a.node().getBoundingClientRect();
192
+ b.x < I && t.attr("x", I + b.width / 2), b.x > $ - b.width && t.attr("x", $ - b.width / 2);
193
+ });
186
194
  }
187
- h !== void 0 && a.style("display", h ? "none" : "block");
195
+ o !== void 0 && t.style("display", o ? "none" : "block");
188
196
  },
189
197
  destroy() {
190
- a.remove();
198
+ t.remove();
191
199
  }
192
200
  };
193
- }, Y = `
201
+ }, O = `
194
202
  <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
195
203
  <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
204
  fill="currentColor"/>
197
205
  </svg>
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
- return `${n < 0 ? "-" : ""}$${r(Math.abs(n))}`;
202
- };
206
+ `, C = "sc-charts__hover-tooltip", T = 16, U = y.timeFormat("%a, %b %d, %-I:%M %p"), J = (e) => {
207
+ const t = y.format(",.2f");
208
+ return `${e < 0 ? "-" : ""}$${t(Math.abs(e))}`;
209
+ };
210
+ function K(e) {
211
+ const t = e.append("foreignObject").classed(C, !0).style("display", "none"), a = t.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${C}-container`), r = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${C}-sum`), d = a.append("xhtml:div").attr("xmlns", "http://www.w3.org/1999/xhtml").attr("class", `${C}-time`);
212
+ return { wrapper: t, parent: a, sumNode: r, timeNode: d };
213
+ }
214
+ function Q(e, t, a) {
215
+ return e ? t + T + e.width < a ? t + T : t - T - e.width : null;
216
+ }
217
+ const ee = (e) => {
218
+ const { wrapper: t, parent: a, sumNode: r, timeNode: d } = K(e.svg);
203
219
  return {
204
- className(n, r) {
205
- n === "remove" ? a.classed(`${t}${r}`, !1) : a.classed(`${t}${r}`, !0);
220
+ className(n, s) {
221
+ t.classed(`${C}${s}`, n !== "remove");
206
222
  },
207
- update({ x: n, y: r, hidden: l, dataItem: u }) {
208
- if (n !== void 0 && a.attr("x", n), r !== void 0 && a.attr("y", r), u && n !== void 0) {
209
- c.text(d(u.value)), i.text(o(u.date));
210
- const h = s.node().getBoundingClientRect(), g = 16, m = n + g + h.width > e.config.width - e.config.margin.right ? n - g - h.width : n + g;
211
- a.attr("x", m);
212
- }
213
- l !== void 0 && a.style("display", l ? "none" : "block");
223
+ update({ hidden: n, dataItem: s }) {
224
+ s && (r.text(J(s.value)), d.text(U(s.date)), requestAnimationFrame(() => {
225
+ const l = a.node().getBoundingClientRect(), i = Q(
226
+ l,
227
+ e.x(s.date),
228
+ e.config.width - e.config.margin.right
229
+ );
230
+ i && t.attr("x", i);
231
+ })), n !== void 0 && t.style("display", n ? "none" : "block");
214
232
  },
215
233
  destroy() {
216
- a.remove();
234
+ t.remove();
217
235
  }
218
236
  };
219
- }, P = {
237
+ }, te = {
220
238
  margin: { top: 10, right: 30, bottom: 20, left: 10 },
221
239
  theme: "light",
222
240
  logo: {
@@ -259,9 +277,9 @@ const G = (e) => {
259
277
  },
260
278
  enableBelowZeroLine: !1,
261
279
  curveTension: 1
262
- }, L = (e) => w.curveCardinal.tension(e.config.curveTension), U = (e) => {
263
- const { svg: t, data: a, x: s, y: c, config: i } = e, o = t.node(), d = k(o);
264
- C(d, "main-line-area-gradient", {
280
+ }, N = (e) => y.curveCardinal.tension(e.config.curveTension), ae = (e) => {
281
+ const { svg: t, data: a, x: r, y: d, config: n } = e, s = t.node(), l = L(s);
282
+ _(l, "main-line-area-gradient", {
265
283
  x1: "0%",
266
284
  y1: "0%",
267
285
  x2: "0%",
@@ -271,24 +289,24 @@ const G = (e) => {
271
289
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
272
290
  ]
273
291
  });
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);
292
+ const o = y.area().x((h) => r(h.date)).y0(d.range()[0]).y1((h) => d(h.value)).curve(N(e)), c = "sc-charts__main-line-area", u = t.append("path").datum(a).attr("d", o).attr("class", c).classed(`${c}_hidden`, !n.hasMainLineArea);
275
293
  return {
276
294
  className(h, g) {
277
- h === "remove" ? u.classed(`${l}${g}`, !1) : u.classed(`${l}${g}`, !0);
295
+ h === "remove" ? u.classed(`${c}${g}`, !1) : u.classed(`${c}${g}`, !0);
278
296
  },
279
297
  update({ data: h, hidden: g }) {
280
- if (h !== void 0 && u.datum(h).attr("d", r), g !== void 0) {
281
- if (!i.hasMainLineArea) return null;
282
- u.classed(`${l}_hidden`, g);
298
+ if (h !== void 0 && u.datum(h).attr("d", o), g !== void 0) {
299
+ if (!n.hasMainLineArea) return null;
300
+ u.classed(`${c}_hidden`, g);
283
301
  }
284
302
  },
285
303
  destroy() {
286
304
  u.remove();
287
305
  }
288
306
  };
289
- }, q = (e, t = {}) => {
290
- const a = "sc-charts__range-line-area", { svg: s, x: c, y: i, config: o, data: d, chartId: n } = e, { clip: r } = t, l = s.node(), u = k(l), h = "range-line-area-gradient";
291
- C(u, h + "_up", {
307
+ }, re = (e, t = {}) => {
308
+ const a = "sc-charts__range-line-area", { svg: r, x: d, y: n, config: s, data: l, chartId: i } = e, { clip: o } = t, c = r.node(), u = L(c), h = "range-line-area-gradient";
309
+ _(u, h + "_up", {
292
310
  x1: "0%",
293
311
  y1: "0%",
294
312
  x2: "0%",
@@ -297,7 +315,7 @@ const G = (e) => {
297
315
  { offset: "0%", stopColor: "var(--sc-color-selection-up)" },
298
316
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
299
317
  ]
300
- }), C(u, h + "_down", {
318
+ }), _(u, h + "_down", {
301
319
  x1: "0%",
302
320
  y1: "0%",
303
321
  x2: "0%",
@@ -307,116 +325,116 @@ const G = (e) => {
307
325
  { offset: "100%", stopColor: "rgba(255, 255, 255, 0)" }
308
326
  ]
309
327
  });
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})`);
328
+ const g = y.area().x((f) => d(f.date)).y0(n.range()[0]).y1((f) => n(f.value)).curve(N(e)), m = `${i}-clip-${a}`, v = u.append("clipPath").attr("id", m).append("rect").attr("x", (o == null ? void 0 : o.x) || 0).attr("y", (o == null ? void 0 : o.y) || 0).attr("width", (o == null ? void 0 : o.width) || "100%").attr("height", (o == null ? void 0 : o.height) || "100%"), p = r.append("path").datum(l).attr("d", g).attr("class", a).classed(`${a}_hidden`, !s.hasMainLineArea).attr("clip-path", `url(#${m})`);
311
329
  return {
312
- className(f, p) {
313
- f === "remove" ? v.classed(`${a}${p}`, !1) : v.classed(`${a}${p}`, !0);
330
+ className(f, w) {
331
+ f === "remove" ? p.classed(`${a}${w}`, !1) : p.classed(`${a}${w}`, !0);
314
332
  },
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);
333
+ update({ data: f, hidden: w, clip: $ }) {
334
+ f !== void 0 && p.datum(f).attr("d", g), w !== void 0 && p.classed(`${a}_hidden`, w), $ !== void 0 && v.attr("x", $.x).attr("y", $.y).attr("width", $.width).attr("height", $.height);
317
335
  },
318
336
  destroy() {
319
- v.remove();
337
+ p.remove();
320
338
  }
321
339
  };
322
- }, N = (e, t) => {
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})`);
340
+ }, S = (e, t) => {
341
+ const { svg: a, data: r, x: d, y: n, chartId: s } = e, { baseClassName: l, id: i, clip: o } = t, c = a.node(), u = L(c), h = y.line().x((p) => d(p.date)).y((p) => n(p.value)).curve(N(e)), g = `${s}-clip-${l}`, x = u.append("clipPath").attr("id", g).append("rect").attr("x", (o == null ? void 0 : o.x) || 0).attr("y", (o == null ? void 0 : o.y) || 0).attr("width", (o == null ? void 0 : o.width) || "100%").attr("height", (o == null ? void 0 : o.height) || "100%"), v = a.append("path").classed(l, !0).datum(r).attr("d", h).attr("id", i).attr("clip-path", `url(#${g})`);
324
342
  return {
325
- className(v, f) {
326
- v === "remove" ? y.classed(`${d}${f}`, !1) : y.classed(`${d}${f}`, !0);
343
+ className(p, f) {
344
+ p === "remove" ? v.classed(`${l}${f}`, !1) : v.classed(`${l}${f}`, !0);
327
345
  },
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);
346
+ update({ data: p, clip: f, hidden: w }) {
347
+ p !== void 0 && v.datum(p).attr("d", h), w !== void 0 && v.classed(`${l}_hidden`, w), f !== void 0 && x.attr("x", f.x).attr("y", f.y).attr("width", f.width).attr("height", f.height);
330
348
  },
331
349
  destroy() {
332
- y.remove();
350
+ v.remove();
333
351
  }
334
352
  };
335
- }, J = (e, t) => {
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})`);
353
+ }, se = (e, t) => {
354
+ const { svg: a, data: r, x: d, y: n, chartId: s, config: l } = e, { baseClassName: i, id: o, clip: c } = t, u = a.node(), h = L(u), g = y.line().x((f) => d(f.date)).y((f) => n(f.value)).curve(N(e)), m = `${s}-clip-${i}`, v = h.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%"), p = a.append("path").classed(i, !0).datum(r).attr("d", g).attr("id", o).attr("clip-path", `url(#${m})`);
337
355
  return {
338
- className(f, p) {
339
- f === "remove" ? v.classed(`${n}${p}`, !1) : v.classed(`${n}${p}`, !0);
356
+ className(f, w) {
357
+ f === "remove" ? p.classed(`${i}${w}`, !1) : p.classed(`${i}${w}`, !0);
340
358
  },
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));
359
+ update({ data: f, clip: w, hidden: $ }) {
360
+ f !== void 0 && p.datum(f).attr("d", g), $ !== void 0 && p.classed(`${i}_hidden`, $), w !== void 0 && (l.hover.transitionName === "default" ? v.transition().duration(l.hover.transitionDuration).attr("x", w.x).attr("y", w.y).attr("width", w.width).attr("height", w.height).ease(y.easeLinear) : v.attr("x", w.x).attr("y", w.y).attr("width", w.width).attr("height", w.height));
343
361
  },
344
362
  destroy() {
345
- v.remove();
363
+ p.remove();
346
364
  }
347
365
  };
348
- }, K = (e) => {
349
- const t = N(e, {
366
+ }, ne = (e) => {
367
+ const t = S(e, {
350
368
  baseClassName: "sc-charts__main-line",
351
369
  id: `${e.chartId}-sc-charts__main-line`
352
- }), a = U(e), s = j(e.svg), c = J(e, {
370
+ }), a = ae(e), r = W(e.svg), d = se(e, {
353
371
  baseClassName: "sc-charts__highlight-line",
354
372
  id: `${e.chartId}-sc-charts__highlight-line`,
355
373
  clip: { x: 0, y: 0, width: "0", height: "0" }
356
374
  });
357
- let i = null;
358
- e.config.enableBelowZeroLine && (i = N(e, {
375
+ let n = null;
376
+ e.config.enableBelowZeroLine && (n = S(e, {
359
377
  baseClassName: "sc-charts__below-zero-line",
360
378
  id: `${e.chartId}-sc-charts__below-zero-line`,
361
- clip: B(e)
379
+ clip: z(e)
362
380
  }));
363
- const o = _(e.svg, {
381
+ const s = A(e.svg, {
364
382
  className: "sc-charts__hover-circle",
365
383
  hidden: !0
366
- }), d = M(e.svg), n = M(e.svg), r = N(e, {
384
+ }), l = R(e.svg), i = R(e.svg), o = S(e, {
367
385
  baseClassName: "sc-charts__range-line",
368
386
  id: `${e.chartId}-sc-charts__range-line`,
369
387
  clip: { x: 0, y: 0, width: "0", height: "0" }
370
- }), l = _(e.svg, {
388
+ }), c = A(e.svg, {
371
389
  className: "sc-charts__range-circle-left",
372
390
  hidden: !0
373
- }), u = _(e.svg, {
391
+ }), u = A(e.svg, {
374
392
  className: "sc-charts__range-circle-right",
375
393
  hidden: !0
376
- }), h = W(e), g = O(e), m = q(e);
394
+ }), h = j(e), g = ee(e), m = re(e);
377
395
  return {
378
- hoverLine: s,
379
- hoverCircle: o,
380
- rangeBorderLeft: d,
381
- rangeBorderRight: n,
382
- rangeLine: r,
396
+ hoverLine: r,
397
+ hoverCircle: s,
398
+ rangeBorderLeft: l,
399
+ rangeBorderRight: i,
400
+ rangeLine: o,
383
401
  rangeLineArea: m,
384
- rangeCircleLeft: l,
402
+ rangeCircleLeft: c,
385
403
  rangeCircleRight: u,
386
404
  mainLine: t,
387
405
  rangeTooltip: h,
388
- highlightLine: c,
406
+ highlightLine: d,
389
407
  hoverTooltip: g,
390
408
  mainLineArea: a,
391
- belowZeroLine: i
409
+ belowZeroLine: n
392
410
  };
393
- }, Q = (e, t, a) => {
394
- const s = e.match(/^(\d+)([dMhmw])$/);
395
- if (!s)
411
+ }, oe = (e, t, a) => {
412
+ const r = e.match(/^(\d+)([dMhmw])$/);
413
+ if (!r)
396
414
  return console.warn("Invalid hoverRange:", e), {
397
415
  x: 0,
398
416
  y: 0,
399
417
  width: "100%",
400
418
  height: "100%"
401
419
  };
402
- const [, c, i] = s, o = parseInt(c, 10), [d, n] = a.domain();
403
- let r = new Date(d), l = new Date(r);
404
- for (; l < n; ) {
405
- switch (i) {
420
+ const [, d, n] = r, s = parseInt(d, 10), [l, i] = a.domain();
421
+ let o = new Date(l), c = new Date(o);
422
+ for (; c < i; ) {
423
+ switch (n) {
406
424
  case "M":
407
- l.setMinutes(r.getMinutes() + o);
425
+ c.setMinutes(o.getMinutes() + s);
408
426
  break;
409
427
  case "h":
410
- l.setHours(r.getHours() + o);
428
+ c.setHours(o.getHours() + s);
411
429
  break;
412
430
  case "d":
413
- l.setDate(r.getDate() + o);
431
+ c.setDate(o.getDate() + s);
414
432
  break;
415
433
  case "w":
416
- l.setDate(r.getDate() + o * 7);
434
+ c.setDate(o.getDate() + s * 7);
417
435
  break;
418
436
  case "m":
419
- l = new Date(r.getFullYear(), r.getMonth() + o, 1);
437
+ c = new Date(o.getFullYear(), o.getMonth() + s, 1);
420
438
  break;
421
439
  default:
422
440
  return {
@@ -426,8 +444,8 @@ const G = (e) => {
426
444
  height: "100%"
427
445
  };
428
446
  }
429
- if (t >= r && t < l) {
430
- const u = a(r), h = a(l);
447
+ if (t >= o && t < c) {
448
+ const u = a(o), h = a(c);
431
449
  return {
432
450
  x: u,
433
451
  y: 0,
@@ -435,7 +453,7 @@ const G = (e) => {
435
453
  height: "100%"
436
454
  };
437
455
  }
438
- r = new Date(l);
456
+ o = new Date(c);
439
457
  }
440
458
  return {
441
459
  x: 0,
@@ -443,48 +461,46 @@ const G = (e) => {
443
461
  width: "100%",
444
462
  height: "100%"
445
463
  };
446
- }, D = (e, t) => {
447
- var r;
464
+ }, F = (e, t) => {
465
+ var o;
448
466
  const {
449
467
  x: a,
450
- y: s,
451
- elements: c,
452
- config: { margin: i, height: o, hover: d }
468
+ y: r,
469
+ elements: d,
470
+ config: { margin: n, height: s, hover: l }
453
471
  } = e;
454
- c.hoverLine.update({
472
+ d.hoverLine.update({
455
473
  x1: a(t.date),
456
474
  x2: a(t.date),
457
- y1: i.top,
458
- y2: o - i.bottom,
475
+ y1: n.top,
476
+ y2: s - n.bottom,
459
477
  hidden: !1
460
- }), c.hoverCircle.update({
478
+ }), d.hoverCircle.update({
461
479
  cx: a(t.date),
462
- cy: s(t.value),
480
+ cy: r(t.value),
463
481
  hidden: !1
464
- }), c.hoverTooltip.update({
482
+ }), d.hoverTooltip.update({
465
483
  dataItem: t,
466
- x: a(t.date),
467
- y: 0,
468
484
  hidden: !1
469
485
  });
470
- const n = Q(d.range, t.date, a);
471
- c.highlightLine.update({
472
- clip: n,
486
+ const i = oe(l.range, t.date, a);
487
+ d.highlightLine.update({
488
+ clip: i,
473
489
  hidden: !1
474
- }), (r = c.belowZeroLine) == null || r.update({
490
+ }), (o = d.belowZeroLine) == null || o.update({
475
491
  clip: {
476
- ...n,
477
- y: s(0),
478
- height: s.range()[0] - s(0) + i.bottom
492
+ ...i,
493
+ y: r(0),
494
+ height: r.range()[0] - r(0) + n.bottom
479
495
  }
480
- }), c.mainLine.className("add", "_muted");
481
- }, R = (e) => {
496
+ }), d.mainLine.className("add", "_muted");
497
+ }, D = (e) => {
482
498
  var a;
483
499
  const { elements: t } = e;
484
500
  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({
485
- clip: B(e)
501
+ clip: z(e)
486
502
  }));
487
- }, ee = (e, t) => {
503
+ }, ie = (e, t) => {
488
504
  [
489
505
  "rangeBorderLeft",
490
506
  "rangeBorderRight",
@@ -493,129 +509,129 @@ const G = (e) => {
493
509
  "rangeLine",
494
510
  "rangeLineArea",
495
511
  "rangeTooltip"
496
- ].forEach((s) => {
497
- t ? (e[s].className("remove", "_down"), e[s].className("add", "_up")) : (e[s].className("remove", "_up"), e[s].className("add", "_down"));
512
+ ].forEach((r) => {
513
+ t ? (e[r].className("remove", "_down"), e[r].className("add", "_up")) : (e[r].className("remove", "_up"), e[r].className("add", "_down"));
498
514
  });
499
- }, te = (e, t, a) => {
515
+ }, le = (e, t, a) => {
500
516
  var m;
501
517
  const {
502
- x: s,
503
- y: c,
504
- config: { margin: i, height: o },
505
- elements: d
506
- } = e, n = s(t.date) < s(a.date) ? t : a, r = s(t.date) >= s(a.date) ? t : a, l = r.value - n.value >= 0, u = s(n.date), h = s(r.date), g = h - u;
507
- d.rangeBorderLeft.update({
518
+ x: r,
519
+ y: d,
520
+ config: { margin: n, height: s },
521
+ elements: l
522
+ } = e, i = r(t.date) < r(a.date) ? t : a, o = r(t.date) >= r(a.date) ? t : a, c = o.value - i.value >= 0, u = r(i.date), h = r(o.date), g = h - u;
523
+ l.rangeBorderLeft.update({
508
524
  x1: u,
509
525
  x2: u,
510
- y1: i.top,
511
- y2: o - i.bottom,
526
+ y1: n.top,
527
+ y2: s - n.bottom,
512
528
  hidden: !1
513
- }), d.rangeBorderRight.update({
529
+ }), l.rangeBorderRight.update({
514
530
  x1: h,
515
531
  x2: h,
516
- y1: i.top,
517
- y2: o - i.bottom,
532
+ y1: n.top,
533
+ y2: s - n.bottom,
518
534
  hidden: !1
519
- }), d.rangeCircleLeft.update({
535
+ }), l.rangeCircleLeft.update({
520
536
  cx: u,
521
- cy: c(n.value),
537
+ cy: d(i.value),
522
538
  hidden: !1
523
- }), d.rangeCircleRight.update({
539
+ }), l.rangeCircleRight.update({
524
540
  cx: h,
525
- cy: c(r.value),
541
+ cy: d(o.value),
526
542
  hidden: !1
527
- }), d.rangeLine.update({
543
+ }), l.rangeLine.update({
528
544
  clip: {
529
545
  x: u,
530
546
  y: 0,
531
547
  width: g,
532
- height: c.range()[0]
548
+ height: d.range()[0]
533
549
  },
534
550
  hidden: !1
535
- }), d.rangeLineArea.update({
551
+ }), l.rangeLineArea.update({
536
552
  clip: {
537
553
  x: u,
538
554
  y: 0,
539
555
  width: g,
540
- height: c.range()[0]
556
+ height: d.range()[0]
541
557
  },
542
558
  hidden: !1
543
- }), d.rangeTooltip.update({
544
- rightPoint: r,
545
- leftPoint: n,
559
+ }), l.rangeTooltip.update({
560
+ rightPoint: o,
561
+ leftPoint: i,
546
562
  closest: a,
547
563
  x: u + g / 2,
548
564
  y: 0,
549
565
  hidden: !1
550
- }), (m = d.belowZeroLine) == null || m.update({
566
+ }), (m = l.belowZeroLine) == null || m.update({
551
567
  hidden: !0
552
- }), d.mainLineArea.update({ hidden: !0 }), ee(d, l), d.mainLine.className("add", "_selected-muted");
553
- }, S = (e) => {
568
+ }), l.mainLineArea.update({ hidden: !0 }), ie(l, c), l.mainLine.className("add", "_selected-muted");
569
+ }, E = (e) => {
554
570
  var a;
555
571
  const { elements: t } = e;
556
572
  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 });
557
- }, ae = (e) => {
558
- const { svg: t, data: a, x: s, config: c } = e, { height: i, margin: o, width: d, hover: n, selection: r } = c;
559
- let l = null, u = !1;
573
+ }, de = (e) => {
574
+ const { svg: t, data: a, x: r, config: d } = e, { height: n, margin: s, width: l, hover: i, selection: o } = d;
575
+ let c = null, u = !1;
560
576
  const h = (m) => a.reduce(
561
- (x, y) => Math.abs(s(x.date) - m) < Math.abs(s(y.date) - m) ? x : y
577
+ (x, v) => Math.abs(r(x.date) - m) < Math.abs(r(v.date) - m) ? x : v
562
578
  );
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) {
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));
579
+ t.append("rect").attr("width", l - s.left - s.right).attr("height", n - s.top - s.bottom).attr("x", s.left).attr("y", s.top).attr("fill", "transparent").on("mousemove", function(m) {
580
+ const [x] = y.pointer(m, this), v = h(x);
581
+ !u && i.enable ? (e.action = "hover", F(e, v)) : (e.action = u ? "selection" : "none", D(e)), c && o.enable && (e.action = "selection", le(e, c, v));
566
582
  }).on("mouseleave", () => {
567
- e.action = "none", u = !1, l = null, R(e), S(e);
583
+ e.action = "none", u = !1, c = null, D(e), E(e);
568
584
  }).on("mousedown", function(m) {
569
- if (r.enable) {
585
+ if (o.enable) {
570
586
  u = !0, e.action = "selection";
571
- const [x] = w.pointer(m, this);
572
- l = h(x);
587
+ const [x] = y.pointer(m, this);
588
+ c = h(x);
573
589
  }
574
590
  }).on("mouseup", function(m) {
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);
591
+ const [x] = y.pointer(m, this), v = h(x);
592
+ u = !1, c = null, e.action = "hover", o.enable && E(e), i.enable && F(e, v);
577
593
  });
578
- }, re = (e, t) => {
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]);
581
- }, se = (e, t) => {
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);
594
+ }, ce = (e, t) => {
595
+ const { width: a, margin: r } = t, d = y.scaleTime(), n = y.extent(e, (s) => new Date(s.date));
596
+ return n[0] == null || n[1] == null ? d : d.domain([n[0], n[1]]).range([r.left, a - r.right]);
597
+ }, he = (e, t) => {
598
+ const { height: a, margin: r } = t, d = y.max(e, (s) => s.value) ?? 0, n = y.min(e, (s) => s.value) ?? 0;
599
+ return y.scaleLinear().domain([n, d]).range([a - r.bottom, r.top]);
600
+ }, ge = (e, t) => {
601
+ const a = y.select(e);
586
602
  if (a.empty())
587
603
  return console.error(`Element with selector ${e} not found!`), null;
588
604
  if (!t.chartId || !/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.chartId))
589
605
  return console.error(`chartId is required and must be a valid id
590
606
  (only letters, numbers or underscores. The first character must be a letter)`), null;
591
- const s = a.append("svg"), i = a.node().getBoundingClientRect(), o = i.width, d = i.height;
592
- let n = I({ ...P, width: o, height: d }, t.config);
593
- const r = (l, u = !1) => {
594
- u && l.config && (n = I(n, l.config));
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);
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();
607
+ const r = a.append("svg"), n = a.node().getBoundingClientRect(), s = n.width, l = n.height;
608
+ let i = M({ ...te, width: s, height: l }, t.config);
609
+ const o = (c, u = !1) => {
610
+ u && c.config && (i = M(i, c.config));
611
+ const h = c.data.map((p) => ({ date: new Date(p.date), value: p.value })).sort((p, f) => p.date.getTime() - f.date.getTime()), g = ce(h, i), m = he(h, i);
612
+ r.attr("class", `sc-charts sc-charts__${i.theme}`).attr("preserveAspectRatio", "xMinYMin meet").attr("viewBox", `0 0 ${s} ${l}`).style("width", "100%").style("height", "100%").selectAll("*").remove();
597
613
  const x = {
598
614
  chartId: t.chartId,
599
- svg: s,
615
+ svg: r,
600
616
  data: h,
601
617
  x: g,
602
618
  y: m,
603
- config: n,
619
+ config: i,
604
620
  action: "none"
605
621
  };
606
- X(x);
607
- const y = {
622
+ P(x);
623
+ const v = {
608
624
  ...x,
609
- elements: K(x)
625
+ elements: ne(x)
610
626
  };
611
- ae(y);
627
+ de(v);
612
628
  };
613
- return r(t), {
614
- update: (l) => r(l, !0),
615
- destroy: () => s.remove()
629
+ return o(t), {
630
+ update: (c) => o(c, !0),
631
+ destroy: () => r.remove()
616
632
  };
617
633
  };
618
634
  export {
619
- ne as createLineChart
635
+ ge as createLineChart
620
636
  };
621
637
  //# sourceMappingURL=charts-core.js.map