charts-core 0.0.21 → 1.0.0

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