monobill-mintui 0.6.618 → 0.6.619
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chart/browser.js +110 -99
- package/dist/components/chart/index.cjs +3 -3
- package/dist/components/chart/index.js +110 -99
- package/dist/index.cjs +3 -3
- package/dist/index.css +1 -1
- package/dist/index.js +111 -100
- package/dist/input.css +1 -1
- package/package.json +1 -1
|
@@ -346,12 +346,14 @@ var t = class e extends HTMLElement {
|
|
|
346
346
|
let e = document.createElement("canvas").getContext("2d");
|
|
347
347
|
if (!e) return 60;
|
|
348
348
|
e.font = "12px system-ui, -apple-system, sans-serif";
|
|
349
|
-
let t = this._showLegend ? Math.max(this._legendHeight, 60) : 0, n = this._height - t, r = Math.floor(n / 35), i = Math.min(5, r), a =
|
|
349
|
+
let t = this._showLegend ? Math.max(this._legendHeight, 60) : 0, n = this._height - t, r = Math.floor(n / 35), i = Math.max(1, Math.min(5, r)), a = this._getYRange();
|
|
350
|
+
if (this._hasOnlyZeroValues()) return Math.ceil(e.measureText(this._formatYAxisValue(0)).width) + 20;
|
|
351
|
+
let o = 0;
|
|
350
352
|
for (let t = 0; t <= i; t++) {
|
|
351
|
-
let n =
|
|
352
|
-
|
|
353
|
+
let n = a.max - (a.max - a.min) / i * t, r = this._formatYAxisValue(n), s = e.measureText(r);
|
|
354
|
+
o = Math.max(o, s.width);
|
|
353
355
|
}
|
|
354
|
-
return Math.ceil(
|
|
356
|
+
return Math.ceil(o) + 20;
|
|
355
357
|
}
|
|
356
358
|
_getChartBounds() {
|
|
357
359
|
let e = this._calculateMaxYAxisLabelWidth(), t = `${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;
|
|
@@ -386,6 +388,10 @@ var t = class e extends HTMLElement {
|
|
|
386
388
|
this._isDatasetVisible(t, n) && e.push(...t.data);
|
|
387
389
|
}), e;
|
|
388
390
|
}
|
|
391
|
+
_hasOnlyZeroValues() {
|
|
392
|
+
let e = this._getAllDataPoints();
|
|
393
|
+
return e.length > 0 && e.every((e) => e.y === 0);
|
|
394
|
+
}
|
|
389
395
|
_getXValues() {
|
|
390
396
|
if (!this._chartData) return [];
|
|
391
397
|
let e = JSON.stringify(this._chartData.labels) + JSON.stringify(this._chartData.datasets.map((e) => e.data.map((e) => e.x)));
|
|
@@ -754,7 +760,7 @@ var t = class e extends HTMLElement {
|
|
|
754
760
|
}
|
|
755
761
|
_scaleY(e, t) {
|
|
756
762
|
let n = this._getYRange();
|
|
757
|
-
if (n.max === n.min) return t.y + t.height / 2;
|
|
763
|
+
if (n.max === n.min) return n.min === 0 ? t.y + t.height : t.y + t.height / 2;
|
|
758
764
|
let r = (e - n.min) / (n.max - n.min);
|
|
759
765
|
return t.y + t.height - r * t.height;
|
|
760
766
|
}
|
|
@@ -801,116 +807,117 @@ var t = class e extends HTMLElement {
|
|
|
801
807
|
}
|
|
802
808
|
}
|
|
803
809
|
_renderGrid(e) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
o
|
|
811
|
-
|
|
812
|
-
|
|
810
|
+
let t = this._chartType !== "pie" && this._hasOnlyZeroValues();
|
|
811
|
+
if (!this._svg || !this._showGrid && !t) return;
|
|
812
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
813
|
+
n.setAttribute("class", "chart-grid");
|
|
814
|
+
let r = this._getYRange(), i = Math.floor(e.height / 35), a = t ? 0 : Math.max(1, Math.min(5, i));
|
|
815
|
+
for (let i = 0; i <= a; i++) {
|
|
816
|
+
let o = t ? e.y + e.height : e.y + e.height / a * i, s = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
817
|
+
if (s.setAttribute("x1", e.x.toString()), s.setAttribute("y1", o.toString()), s.setAttribute("x2", (e.x + e.width).toString()), s.setAttribute("y2", o.toString()), s.setAttribute("stroke", t ? "#9ca3af" : "#e5e7eb"), s.setAttribute("stroke-width", "1"), t || s.setAttribute("stroke-dasharray", "2,2"), document.documentElement.classList.contains("dark") && s.setAttribute("stroke", "#374151"), n.appendChild(s), t && !this._showGrid) continue;
|
|
818
|
+
let c = t ? 0 : r.max - (r.max - r.min) / a * i, l = document.createElementNS("http://www.w3.org/2000/svg", "text"), u = o + 4;
|
|
819
|
+
i === 0 && (u = o + 12), l.setAttribute("x", "5"), l.setAttribute("y", u.toString()), l.setAttribute("text-anchor", "start"), l.setAttribute("fill", "#6b7280"), l.setAttribute("font-size", "12"), l.textContent = this._formatYAxisValue(c), document.documentElement.classList.contains("dark") && l.setAttribute("fill", "#9ca3af"), n.appendChild(l);
|
|
813
820
|
}
|
|
814
|
-
let
|
|
815
|
-
if (
|
|
816
|
-
this._svg.appendChild(
|
|
821
|
+
let o = this._getXValues();
|
|
822
|
+
if (o.length === 0) {
|
|
823
|
+
this._svg.appendChild(n);
|
|
817
824
|
return;
|
|
818
825
|
}
|
|
819
|
-
let
|
|
820
|
-
|
|
821
|
-
let n =
|
|
822
|
-
|
|
826
|
+
let s = this._chartType === "bar", c = [];
|
|
827
|
+
o.forEach((t) => {
|
|
828
|
+
let n = s ? this._scaleXForBarChart(t, e) : this._scaleX(t, e);
|
|
829
|
+
c.push(n);
|
|
823
830
|
});
|
|
824
|
-
let
|
|
825
|
-
if (
|
|
826
|
-
|
|
831
|
+
let l = document.createElement("canvas").getContext("2d"), u = !1, d = Array(o.length).fill(!0);
|
|
832
|
+
if (l && o.length > 1) {
|
|
833
|
+
l.font = "12px system-ui, -apple-system, sans-serif";
|
|
827
834
|
let e = [];
|
|
828
|
-
|
|
829
|
-
let n = this._formatXAxisValue(t), r =
|
|
835
|
+
o.forEach((t) => {
|
|
836
|
+
let n = this._formatXAxisValue(t), r = l.measureText(n);
|
|
830
837
|
e.push(r.width);
|
|
831
838
|
});
|
|
832
839
|
let t = !0;
|
|
833
|
-
for (let n = 1; n <
|
|
834
|
-
let r =
|
|
840
|
+
for (let n = 1; n < o.length; n++) {
|
|
841
|
+
let r = c[n] - c[n - 1], i = e[n - 1] / 2 + e[n] / 2 + 10;
|
|
835
842
|
if (r < Math.max(i, 80)) {
|
|
836
843
|
t = !1;
|
|
837
844
|
break;
|
|
838
845
|
}
|
|
839
846
|
}
|
|
840
847
|
if (!t) {
|
|
841
|
-
|
|
848
|
+
u = !0;
|
|
842
849
|
let t = 12 * 1.2;
|
|
843
850
|
if (this._rotatedLabelHeight === 0) {
|
|
844
851
|
let n = (Math.max(...e) + t) * .707;
|
|
845
852
|
this._rotatedLabelHeight = Math.ceil(n) + 10;
|
|
846
853
|
}
|
|
847
854
|
let n = t * 1.5, r = !0;
|
|
848
|
-
for (let e = 1; e <
|
|
855
|
+
for (let e = 1; e < o.length; e++) if (c[e] - c[e - 1] < n) {
|
|
849
856
|
r = !1;
|
|
850
857
|
break;
|
|
851
858
|
}
|
|
852
859
|
if (!r) {
|
|
853
860
|
let e = n;
|
|
854
|
-
|
|
861
|
+
d = Array(o.length).fill(!1);
|
|
855
862
|
let t = -Infinity;
|
|
856
|
-
|
|
857
|
-
for (let n = 1; n <
|
|
858
|
-
let r =
|
|
859
|
-
r - t >= e && (
|
|
863
|
+
o.length > 0 && (d[0] = !0, t = c[0]);
|
|
864
|
+
for (let n = 1; n < o.length - 1; n++) {
|
|
865
|
+
let r = c[n];
|
|
866
|
+
r - t >= e && (d[n] = !0, t = r);
|
|
860
867
|
}
|
|
861
|
-
if (
|
|
862
|
-
let n =
|
|
863
|
-
if (n - t >= e)
|
|
868
|
+
if (o.length > 1) {
|
|
869
|
+
let n = c[o.length - 1];
|
|
870
|
+
if (n - t >= e) d[o.length - 1] = !0;
|
|
864
871
|
else {
|
|
865
872
|
for (; n - t < e;) {
|
|
866
873
|
let e = !1;
|
|
867
|
-
for (let n =
|
|
868
|
-
if (
|
|
869
|
-
for (let r = n - 1; r >= 0; r--) if (
|
|
870
|
-
t =
|
|
874
|
+
for (let n = o.length - 2; n >= 0; n--) if (d[n]) {
|
|
875
|
+
if (d[n] = !1, n > 0) {
|
|
876
|
+
for (let r = n - 1; r >= 0; r--) if (d[r]) {
|
|
877
|
+
t = c[r], e = !0;
|
|
871
878
|
break;
|
|
872
879
|
}
|
|
873
|
-
e || (t =
|
|
874
|
-
} else t =
|
|
880
|
+
e || (t = c[0]);
|
|
881
|
+
} else t = c[0];
|
|
875
882
|
e = !0;
|
|
876
883
|
break;
|
|
877
884
|
}
|
|
878
885
|
if (!e) break;
|
|
879
886
|
}
|
|
880
|
-
n - t >= e && (
|
|
887
|
+
n - t >= e && (d[o.length - 1] = !0);
|
|
881
888
|
}
|
|
882
889
|
}
|
|
883
890
|
}
|
|
884
891
|
}
|
|
885
|
-
} else
|
|
886
|
-
|
|
887
|
-
if (
|
|
888
|
-
let i =
|
|
889
|
-
|
|
890
|
-
let
|
|
891
|
-
if (!
|
|
892
|
+
} else d = Array(o.length).fill(!1), o.length > 0 && (d[0] = !0), o.length > 1 && (d[o.length - 1] = !0), this._rotatedLabelHeight = 0;
|
|
893
|
+
u || (this._rotatedLabelHeight = 0), o.forEach((t, r) => {
|
|
894
|
+
if (d[r]) {
|
|
895
|
+
let i = c[r], a = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
896
|
+
a.setAttribute("x1", i.toString()), a.setAttribute("y1", e.y.toString()), a.setAttribute("x2", i.toString()), a.setAttribute("y2", (e.y + e.height).toString()), a.setAttribute("stroke", "#e5e7eb"), a.setAttribute("stroke-width", "1"), a.setAttribute("stroke-dasharray", "2,2"), document.documentElement.classList.contains("dark") && a.setAttribute("stroke", "#374151"), n.appendChild(a);
|
|
897
|
+
let s = document.createElementNS("http://www.w3.org/2000/svg", "text"), l = i, d = "middle";
|
|
898
|
+
if (!u) {
|
|
892
899
|
if (r === 0) {
|
|
893
900
|
let t = e.x;
|
|
894
|
-
|
|
895
|
-
} else if (r ===
|
|
901
|
+
l = Math.max(i, t), d = "start";
|
|
902
|
+
} else if (r === o.length - 1) {
|
|
896
903
|
let t = e.x + e.width;
|
|
897
|
-
|
|
904
|
+
l = Math.min(i, t), d = "end";
|
|
898
905
|
}
|
|
899
|
-
} else if (d = "end", r ===
|
|
900
|
-
let
|
|
901
|
-
if (
|
|
902
|
-
|
|
903
|
-
let r = this._formatXAxisValue(
|
|
904
|
-
|
|
906
|
+
} else if (d = "end", r === o.length - 1) {
|
|
907
|
+
let n = document.createElement("canvas").getContext("2d");
|
|
908
|
+
if (n) {
|
|
909
|
+
n.font = "12px system-ui, -apple-system, sans-serif";
|
|
910
|
+
let r = this._formatXAxisValue(t), a = n.measureText(r).width * .707, o = e.x + e.width + 100;
|
|
911
|
+
l = Math.min(i, o - a);
|
|
905
912
|
}
|
|
906
913
|
}
|
|
907
|
-
|
|
914
|
+
s.setAttribute("x", l.toString());
|
|
908
915
|
let f = (this._rotatedLabelHeight > 0 ? 30 : 20) + this._rotatedLabelHeight + 12, p = f;
|
|
909
916
|
this._showLegend && (p = f + 20 + Math.max(this._legendHeight, 60));
|
|
910
|
-
let m = (this._height - e.y - e.height) / p, h = (
|
|
911
|
-
|
|
917
|
+
let m = (this._height - e.y - e.height) / p, h = (u ? 30 : 20) * m, g = e.y + e.height + h;
|
|
918
|
+
s.setAttribute("y", g.toString()), s.setAttribute("text-anchor", d), s.setAttribute("fill", "#6b7280"), s.setAttribute("font-size", "12"), u && s.setAttribute("transform", `rotate(-45 ${l} ${g})`), s.textContent = this._formatXAxisValue(t), document.documentElement.classList.contains("dark") && s.setAttribute("fill", "#9ca3af"), n.appendChild(s);
|
|
912
919
|
}
|
|
913
|
-
}), this._svg.appendChild(
|
|
920
|
+
}), this._svg.appendChild(n);
|
|
914
921
|
}
|
|
915
922
|
_buildMonotoneXLinePathD(e) {
|
|
916
923
|
let t = (e) => e < 0 ? -1 : 1, n = (e, n, r, i, a, o) => {
|
|
@@ -979,26 +986,26 @@ var t = class e extends HTMLElement {
|
|
|
979
986
|
}
|
|
980
987
|
_renderLineChart() {
|
|
981
988
|
if (!this._svg || !this._chartData) return;
|
|
982
|
-
let e = this._getChartBounds();
|
|
989
|
+
let e = this._getChartBounds(), t = this._hasOnlyZeroValues();
|
|
983
990
|
this._renderGrid(e);
|
|
984
|
-
let
|
|
985
|
-
|
|
986
|
-
let
|
|
987
|
-
this._chartData.datasets.forEach((
|
|
988
|
-
if (!this._isDatasetVisible(
|
|
989
|
-
let
|
|
991
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
992
|
+
n.setAttribute("class", "chart-data");
|
|
993
|
+
let r = document.createDocumentFragment();
|
|
994
|
+
this._chartData.datasets.forEach((n, i) => {
|
|
995
|
+
if (!this._isDatasetVisible(n, i)) return;
|
|
996
|
+
let a = this._getDatasetColor(n, i), o = document.createElementNS("http://www.w3.org/2000/svg", "path"), s = n.data.map((t) => ({
|
|
990
997
|
x: this._scaleX(t.x, e),
|
|
991
998
|
y: this._scaleY(t.y, e)
|
|
992
999
|
}));
|
|
993
|
-
|
|
994
|
-
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(
|
|
995
|
-
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill",
|
|
1000
|
+
s.length !== 0 && (t || (o.setAttribute("d", this._buildSmoothLinePathD(s)), o.setAttribute("fill", "none"), o.setAttribute("stroke", a), o.setAttribute("stroke-width", "2"), o.setAttribute("stroke-linecap", "round"), o.setAttribute("stroke-linejoin", "round"), r.appendChild(o)), n.data.forEach((t) => {
|
|
1001
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(t.x, e), c = this._scaleY(t.y, e);
|
|
1002
|
+
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill", a);
|
|
996
1003
|
let l = document.documentElement.classList.contains("dark");
|
|
997
|
-
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset",
|
|
998
|
-
let u = String(
|
|
999
|
-
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o),
|
|
1004
|
+
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset", i.toString()), o.setAttribute("data-x", String(t.x)), o.setAttribute("data-y", t.y.toString()), o.setAttribute("data-name", n.name), o.style.opacity = "0", o.style.pointerEvents = "none";
|
|
1005
|
+
let u = String(t.x);
|
|
1006
|
+
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o), r.appendChild(o);
|
|
1000
1007
|
}));
|
|
1001
|
-
}),
|
|
1008
|
+
}), n.appendChild(r), this._svg.appendChild(n);
|
|
1002
1009
|
}
|
|
1003
1010
|
_scaleXForBarChart(e, t) {
|
|
1004
1011
|
let n = this._getXValues();
|
|
@@ -1051,30 +1058,34 @@ var t = class e extends HTMLElement {
|
|
|
1051
1058
|
}
|
|
1052
1059
|
_renderAreaChart() {
|
|
1053
1060
|
if (!this._svg || !this._chartData) return;
|
|
1054
|
-
let e = this._getChartBounds();
|
|
1061
|
+
let e = this._getChartBounds(), t = this._hasOnlyZeroValues();
|
|
1055
1062
|
this._renderGrid(e);
|
|
1056
|
-
let
|
|
1057
|
-
|
|
1058
|
-
let
|
|
1059
|
-
this._chartData.datasets.forEach((
|
|
1060
|
-
if (!this._isDatasetVisible(
|
|
1061
|
-
let
|
|
1063
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
1064
|
+
n.setAttribute("class", "chart-data");
|
|
1065
|
+
let r = document.createDocumentFragment();
|
|
1066
|
+
this._chartData.datasets.forEach((n, i) => {
|
|
1067
|
+
if (!this._isDatasetVisible(n, i)) return;
|
|
1068
|
+
let a = this._getDatasetColor(n, i), o = n.data.map((t) => ({
|
|
1062
1069
|
x: this._scaleX(t.x, e),
|
|
1063
1070
|
y: this._scaleY(t.y, e)
|
|
1064
1071
|
}));
|
|
1065
|
-
if (
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1072
|
+
if (o.length !== 0) {
|
|
1073
|
+
if (!t) {
|
|
1074
|
+
let t = e.y + e.height, n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1075
|
+
n.setAttribute("d", this._buildAreaFillPathD(o, t)), n.setAttribute("fill", a), n.setAttribute("fill-opacity", "0.3"), r.appendChild(n);
|
|
1076
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1077
|
+
i.setAttribute("d", this._buildSmoothLinePathD(o)), i.setAttribute("fill", "none"), i.setAttribute("stroke", a), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), r.appendChild(i);
|
|
1078
|
+
}
|
|
1079
|
+
n.data.forEach((t) => {
|
|
1080
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(t.x, e), c = this._scaleY(t.y, e);
|
|
1081
|
+
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill", a);
|
|
1082
|
+
let l = document.documentElement.classList.contains("dark");
|
|
1083
|
+
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset", i.toString()), o.setAttribute("data-x", String(t.x)), o.setAttribute("data-y", t.y.toString()), o.setAttribute("data-name", n.name), o.style.opacity = "0", o.style.pointerEvents = "none";
|
|
1084
|
+
let u = String(t.x);
|
|
1085
|
+
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o), r.appendChild(o);
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
}), n.appendChild(r), this._svg.appendChild(n);
|
|
1078
1089
|
}
|
|
1079
1090
|
_renderPieChart() {
|
|
1080
1091
|
if (!this._svg || !this._chartData) return;
|