myio-js-library 0.1.162 → 0.1.164
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/index.cjs +1278 -5
- package/dist/index.d.cts +76 -1
- package/dist/index.js +1277 -5
- package/dist/myio-js-library.umd.js +1275 -5
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
|
@@ -22967,7 +22967,7 @@ ${rangeText}`;
|
|
|
22967
22967
|
const isTemperature = config.domain === "temperature";
|
|
22968
22968
|
let datasets;
|
|
22969
22969
|
if (currentVizMode === "separate" && data.shoppingData && data.shoppingNames) {
|
|
22970
|
-
const shoppingColors = [
|
|
22970
|
+
const shoppingColors = colors.shoppingColors || [
|
|
22971
22971
|
"#2563eb",
|
|
22972
22972
|
"#16a34a",
|
|
22973
22973
|
"#ea580c",
|
|
@@ -23652,8 +23652,1277 @@ ${rangeText}`;
|
|
|
23652
23652
|
return instance;
|
|
23653
23653
|
}
|
|
23654
23654
|
|
|
23655
|
+
// src/components/Consumption7DaysChart/createConsumptionChartWidget.ts
|
|
23656
|
+
var DOMAIN_CONFIG4 = {
|
|
23657
|
+
energy: {
|
|
23658
|
+
name: "Energia",
|
|
23659
|
+
icon: "\u26A1",
|
|
23660
|
+
color: "#6c2fbf",
|
|
23661
|
+
colors: ["#2563eb", "#16a34a", "#8b5cf6", "#ea580c", "#dc2626"]
|
|
23662
|
+
},
|
|
23663
|
+
water: {
|
|
23664
|
+
name: "\xC1gua",
|
|
23665
|
+
icon: "\u{1F4A7}",
|
|
23666
|
+
color: "#0288d1",
|
|
23667
|
+
colors: ["#0288d1", "#06b6d4", "#0891b2", "#22d3ee", "#67e8f9"]
|
|
23668
|
+
},
|
|
23669
|
+
gas: {
|
|
23670
|
+
name: "G\xE1s",
|
|
23671
|
+
icon: "\u{1F525}",
|
|
23672
|
+
color: "#ea580c",
|
|
23673
|
+
colors: ["#ea580c", "#f97316", "#fb923c", "#fdba74", "#fed7aa"]
|
|
23674
|
+
},
|
|
23675
|
+
temperature: {
|
|
23676
|
+
name: "Temperatura",
|
|
23677
|
+
icon: "\u{1F321}\uFE0F",
|
|
23678
|
+
color: "#e65100",
|
|
23679
|
+
colors: ["#dc2626", "#059669", "#0ea5e9", "#f59e0b", "#8b5cf6"]
|
|
23680
|
+
}
|
|
23681
|
+
};
|
|
23682
|
+
function getWidgetStyles(theme, primaryColor) {
|
|
23683
|
+
const colors = THEME_COLORS[theme];
|
|
23684
|
+
return `
|
|
23685
|
+
.myio-chart-widget {
|
|
23686
|
+
font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
|
|
23687
|
+
background: ${colors.chartBackground};
|
|
23688
|
+
border: 1px solid ${colors.border};
|
|
23689
|
+
border-radius: 16px;
|
|
23690
|
+
overflow: hidden;
|
|
23691
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
|
23692
|
+
}
|
|
23693
|
+
|
|
23694
|
+
.myio-chart-widget.dark {
|
|
23695
|
+
background: ${THEME_COLORS.dark.chartBackground};
|
|
23696
|
+
border-color: ${THEME_COLORS.dark.border};
|
|
23697
|
+
}
|
|
23698
|
+
|
|
23699
|
+
.myio-chart-widget-header {
|
|
23700
|
+
display: flex;
|
|
23701
|
+
justify-content: space-between;
|
|
23702
|
+
align-items: center;
|
|
23703
|
+
padding: 16px 20px;
|
|
23704
|
+
border-bottom: 1px solid ${colors.border};
|
|
23705
|
+
flex-wrap: wrap;
|
|
23706
|
+
gap: 12px;
|
|
23707
|
+
}
|
|
23708
|
+
|
|
23709
|
+
.myio-chart-widget-title-group {
|
|
23710
|
+
display: flex;
|
|
23711
|
+
align-items: center;
|
|
23712
|
+
gap: 10px;
|
|
23713
|
+
}
|
|
23714
|
+
|
|
23715
|
+
.myio-chart-widget-title {
|
|
23716
|
+
margin: 0;
|
|
23717
|
+
font-size: 16px;
|
|
23718
|
+
font-weight: 600;
|
|
23719
|
+
color: ${colors.text};
|
|
23720
|
+
}
|
|
23721
|
+
|
|
23722
|
+
.myio-chart-widget-controls {
|
|
23723
|
+
display: flex;
|
|
23724
|
+
align-items: center;
|
|
23725
|
+
gap: 12px;
|
|
23726
|
+
flex-wrap: wrap;
|
|
23727
|
+
}
|
|
23728
|
+
|
|
23729
|
+
.myio-chart-widget-tabs {
|
|
23730
|
+
display: flex;
|
|
23731
|
+
gap: 2px;
|
|
23732
|
+
background: ${theme === "dark" ? "#374151" : "#f3f4f6"};
|
|
23733
|
+
padding: 3px;
|
|
23734
|
+
border-radius: 8px;
|
|
23735
|
+
}
|
|
23736
|
+
|
|
23737
|
+
.myio-chart-widget-tab {
|
|
23738
|
+
padding: 6px 14px;
|
|
23739
|
+
font-size: 12px;
|
|
23740
|
+
font-weight: 500;
|
|
23741
|
+
border: none;
|
|
23742
|
+
background: transparent;
|
|
23743
|
+
color: ${colors.textMuted};
|
|
23744
|
+
cursor: pointer;
|
|
23745
|
+
border-radius: 6px;
|
|
23746
|
+
transition: all 0.2s;
|
|
23747
|
+
white-space: nowrap;
|
|
23748
|
+
}
|
|
23749
|
+
|
|
23750
|
+
.myio-chart-widget-tab:hover {
|
|
23751
|
+
color: ${colors.text};
|
|
23752
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.05)"};
|
|
23753
|
+
}
|
|
23754
|
+
|
|
23755
|
+
.myio-chart-widget-tab.active {
|
|
23756
|
+
background: ${primaryColor};
|
|
23757
|
+
color: white;
|
|
23758
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
23759
|
+
}
|
|
23760
|
+
|
|
23761
|
+
.myio-chart-widget-btn {
|
|
23762
|
+
background: transparent;
|
|
23763
|
+
border: 1px solid ${colors.border};
|
|
23764
|
+
font-size: 16px;
|
|
23765
|
+
cursor: pointer;
|
|
23766
|
+
padding: 6px 10px;
|
|
23767
|
+
border-radius: 6px;
|
|
23768
|
+
transition: all 0.2s;
|
|
23769
|
+
color: ${colors.text};
|
|
23770
|
+
}
|
|
23771
|
+
|
|
23772
|
+
.myio-chart-widget-btn:hover {
|
|
23773
|
+
background: ${primaryColor};
|
|
23774
|
+
border-color: ${primaryColor};
|
|
23775
|
+
color: white;
|
|
23776
|
+
}
|
|
23777
|
+
|
|
23778
|
+
.myio-chart-widget-body {
|
|
23779
|
+
position: relative;
|
|
23780
|
+
padding: 16px 20px;
|
|
23781
|
+
}
|
|
23782
|
+
|
|
23783
|
+
.myio-chart-widget-canvas-container {
|
|
23784
|
+
position: relative;
|
|
23785
|
+
width: 100%;
|
|
23786
|
+
}
|
|
23787
|
+
|
|
23788
|
+
.myio-chart-widget-loading {
|
|
23789
|
+
position: absolute;
|
|
23790
|
+
top: 0;
|
|
23791
|
+
left: 0;
|
|
23792
|
+
right: 0;
|
|
23793
|
+
bottom: 0;
|
|
23794
|
+
background: rgba(255, 255, 255, 0.9);
|
|
23795
|
+
display: flex;
|
|
23796
|
+
align-items: center;
|
|
23797
|
+
justify-content: center;
|
|
23798
|
+
z-index: 10;
|
|
23799
|
+
border-radius: 8px;
|
|
23800
|
+
}
|
|
23801
|
+
|
|
23802
|
+
.myio-chart-widget.dark .myio-chart-widget-loading {
|
|
23803
|
+
background: rgba(31, 41, 55, 0.9);
|
|
23804
|
+
}
|
|
23805
|
+
|
|
23806
|
+
.myio-chart-widget-spinner {
|
|
23807
|
+
width: 32px;
|
|
23808
|
+
height: 32px;
|
|
23809
|
+
border: 3px solid ${colors.border};
|
|
23810
|
+
border-top-color: ${primaryColor};
|
|
23811
|
+
border-radius: 50%;
|
|
23812
|
+
animation: myio-spin 1s linear infinite;
|
|
23813
|
+
}
|
|
23814
|
+
|
|
23815
|
+
@keyframes myio-spin {
|
|
23816
|
+
to { transform: rotate(360deg); }
|
|
23817
|
+
}
|
|
23818
|
+
|
|
23819
|
+
.myio-chart-widget-footer {
|
|
23820
|
+
display: flex;
|
|
23821
|
+
justify-content: space-around;
|
|
23822
|
+
padding: 16px 20px;
|
|
23823
|
+
border-top: 1px solid ${colors.border};
|
|
23824
|
+
gap: 16px;
|
|
23825
|
+
flex-wrap: wrap;
|
|
23826
|
+
}
|
|
23827
|
+
|
|
23828
|
+
.myio-chart-widget-stat {
|
|
23829
|
+
display: flex;
|
|
23830
|
+
flex-direction: column;
|
|
23831
|
+
align-items: center;
|
|
23832
|
+
text-align: center;
|
|
23833
|
+
min-width: 100px;
|
|
23834
|
+
}
|
|
23835
|
+
|
|
23836
|
+
.myio-chart-widget-stat-label {
|
|
23837
|
+
font-size: 11px;
|
|
23838
|
+
font-weight: 500;
|
|
23839
|
+
color: ${colors.textMuted};
|
|
23840
|
+
text-transform: uppercase;
|
|
23841
|
+
letter-spacing: 0.5px;
|
|
23842
|
+
margin-bottom: 4px;
|
|
23843
|
+
}
|
|
23844
|
+
|
|
23845
|
+
.myio-chart-widget-stat-value {
|
|
23846
|
+
font-size: 20px;
|
|
23847
|
+
font-weight: 700;
|
|
23848
|
+
color: ${colors.text};
|
|
23849
|
+
}
|
|
23850
|
+
|
|
23851
|
+
.myio-chart-widget-stat-value.primary {
|
|
23852
|
+
color: ${primaryColor};
|
|
23853
|
+
}
|
|
23854
|
+
|
|
23855
|
+
.myio-chart-widget-stat-sub {
|
|
23856
|
+
font-size: 11px;
|
|
23857
|
+
color: ${colors.textMuted};
|
|
23858
|
+
margin-top: 2px;
|
|
23859
|
+
}
|
|
23860
|
+
|
|
23861
|
+
/* Settings Modal Overlay */
|
|
23862
|
+
.myio-settings-overlay {
|
|
23863
|
+
position: fixed;
|
|
23864
|
+
inset: 0;
|
|
23865
|
+
background: rgba(0, 0, 0, 0.6);
|
|
23866
|
+
display: flex;
|
|
23867
|
+
align-items: center;
|
|
23868
|
+
justify-content: center;
|
|
23869
|
+
z-index: 99999;
|
|
23870
|
+
backdrop-filter: blur(4px);
|
|
23871
|
+
}
|
|
23872
|
+
|
|
23873
|
+
.myio-settings-overlay.hidden {
|
|
23874
|
+
display: none;
|
|
23875
|
+
}
|
|
23876
|
+
|
|
23877
|
+
.myio-settings-card {
|
|
23878
|
+
background: ${colors.chartBackground};
|
|
23879
|
+
border-radius: 10px;
|
|
23880
|
+
width: 90%;
|
|
23881
|
+
max-width: 600px;
|
|
23882
|
+
max-height: 90vh;
|
|
23883
|
+
display: flex;
|
|
23884
|
+
flex-direction: column;
|
|
23885
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
|
23886
|
+
overflow: hidden;
|
|
23887
|
+
}
|
|
23888
|
+
|
|
23889
|
+
.myio-settings-card .myio-modal-header {
|
|
23890
|
+
border-radius: 10px 10px 0 0;
|
|
23891
|
+
}
|
|
23892
|
+
|
|
23893
|
+
.myio-settings-body {
|
|
23894
|
+
padding: 20px;
|
|
23895
|
+
overflow-y: auto;
|
|
23896
|
+
display: flex;
|
|
23897
|
+
flex-direction: column;
|
|
23898
|
+
gap: 20px;
|
|
23899
|
+
}
|
|
23900
|
+
|
|
23901
|
+
.myio-settings-section {
|
|
23902
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.05)" : "#f8fafc"};
|
|
23903
|
+
border-radius: 10px;
|
|
23904
|
+
padding: 16px;
|
|
23905
|
+
border: 1px solid ${theme === "dark" ? "rgba(255,255,255,0.1)" : "#e2e8f0"};
|
|
23906
|
+
}
|
|
23907
|
+
|
|
23908
|
+
.myio-settings-section-label {
|
|
23909
|
+
font-size: 13px;
|
|
23910
|
+
font-weight: 600;
|
|
23911
|
+
color: ${colors.text};
|
|
23912
|
+
margin-bottom: 12px;
|
|
23913
|
+
display: flex;
|
|
23914
|
+
align-items: center;
|
|
23915
|
+
gap: 8px;
|
|
23916
|
+
}
|
|
23917
|
+
|
|
23918
|
+
.myio-settings-row {
|
|
23919
|
+
display: flex;
|
|
23920
|
+
gap: 16px;
|
|
23921
|
+
flex-wrap: wrap;
|
|
23922
|
+
align-items: flex-end;
|
|
23923
|
+
}
|
|
23924
|
+
|
|
23925
|
+
.myio-settings-field {
|
|
23926
|
+
display: flex;
|
|
23927
|
+
flex-direction: column;
|
|
23928
|
+
gap: 6px;
|
|
23929
|
+
flex: 1;
|
|
23930
|
+
min-width: 120px;
|
|
23931
|
+
}
|
|
23932
|
+
|
|
23933
|
+
.myio-settings-field-label {
|
|
23934
|
+
font-size: 12px;
|
|
23935
|
+
font-weight: 500;
|
|
23936
|
+
color: ${colors.textMuted};
|
|
23937
|
+
}
|
|
23938
|
+
|
|
23939
|
+
.myio-settings-input,
|
|
23940
|
+
.myio-settings-select {
|
|
23941
|
+
padding: 10px 14px;
|
|
23942
|
+
border: 1px solid ${colors.border};
|
|
23943
|
+
border-radius: 8px;
|
|
23944
|
+
font-size: 14px;
|
|
23945
|
+
background: ${colors.chartBackground};
|
|
23946
|
+
color: ${colors.text};
|
|
23947
|
+
width: 100%;
|
|
23948
|
+
}
|
|
23949
|
+
|
|
23950
|
+
.myio-settings-input:focus,
|
|
23951
|
+
.myio-settings-select:focus {
|
|
23952
|
+
outline: 2px solid ${primaryColor};
|
|
23953
|
+
outline-offset: 1px;
|
|
23954
|
+
}
|
|
23955
|
+
|
|
23956
|
+
.myio-settings-tabs {
|
|
23957
|
+
display: flex;
|
|
23958
|
+
gap: 2px;
|
|
23959
|
+
background: ${theme === "dark" ? "#374151" : "#e5e7eb"};
|
|
23960
|
+
padding: 3px;
|
|
23961
|
+
border-radius: 8px;
|
|
23962
|
+
}
|
|
23963
|
+
|
|
23964
|
+
.myio-settings-tab {
|
|
23965
|
+
flex: 1;
|
|
23966
|
+
padding: 8px 12px;
|
|
23967
|
+
font-size: 12px;
|
|
23968
|
+
font-weight: 500;
|
|
23969
|
+
border: none;
|
|
23970
|
+
background: transparent;
|
|
23971
|
+
color: ${colors.textMuted};
|
|
23972
|
+
cursor: pointer;
|
|
23973
|
+
border-radius: 6px;
|
|
23974
|
+
transition: all 0.2s;
|
|
23975
|
+
white-space: nowrap;
|
|
23976
|
+
}
|
|
23977
|
+
|
|
23978
|
+
.myio-settings-tab:hover {
|
|
23979
|
+
color: ${colors.text};
|
|
23980
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.05)"};
|
|
23981
|
+
}
|
|
23982
|
+
|
|
23983
|
+
.myio-settings-tab.active {
|
|
23984
|
+
background: ${primaryColor};
|
|
23985
|
+
color: white;
|
|
23986
|
+
}
|
|
23987
|
+
|
|
23988
|
+
.myio-settings-footer {
|
|
23989
|
+
display: flex;
|
|
23990
|
+
gap: 12px;
|
|
23991
|
+
justify-content: flex-end;
|
|
23992
|
+
padding: 16px 20px;
|
|
23993
|
+
border-top: 1px solid ${colors.border};
|
|
23994
|
+
background: ${theme === "dark" ? "rgba(0,0,0,0.2)" : "#fafafa"};
|
|
23995
|
+
}
|
|
23996
|
+
|
|
23997
|
+
.myio-settings-btn {
|
|
23998
|
+
padding: 10px 20px;
|
|
23999
|
+
border-radius: 8px;
|
|
24000
|
+
font-size: 14px;
|
|
24001
|
+
font-weight: 500;
|
|
24002
|
+
cursor: pointer;
|
|
24003
|
+
transition: all 0.2s;
|
|
24004
|
+
}
|
|
24005
|
+
|
|
24006
|
+
.myio-settings-btn-secondary {
|
|
24007
|
+
background: transparent;
|
|
24008
|
+
border: 1px solid ${colors.border};
|
|
24009
|
+
color: ${colors.text};
|
|
24010
|
+
}
|
|
24011
|
+
|
|
24012
|
+
.myio-settings-btn-secondary:hover {
|
|
24013
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.1)" : "#f3f4f6"};
|
|
24014
|
+
}
|
|
24015
|
+
|
|
24016
|
+
.myio-settings-btn-primary {
|
|
24017
|
+
background: ${primaryColor};
|
|
24018
|
+
border: none;
|
|
24019
|
+
color: white;
|
|
24020
|
+
}
|
|
24021
|
+
|
|
24022
|
+
.myio-settings-btn-primary:hover {
|
|
24023
|
+
filter: brightness(1.1);
|
|
24024
|
+
}
|
|
24025
|
+
|
|
24026
|
+
.myio-settings-hint {
|
|
24027
|
+
font-size: 11px;
|
|
24028
|
+
color: ${colors.textMuted};
|
|
24029
|
+
font-weight: normal;
|
|
24030
|
+
}
|
|
24031
|
+
|
|
24032
|
+
.myio-settings-context-group {
|
|
24033
|
+
margin-bottom: 8px;
|
|
24034
|
+
}
|
|
24035
|
+
|
|
24036
|
+
.myio-settings-context-group:last-child {
|
|
24037
|
+
margin-bottom: 0;
|
|
24038
|
+
}
|
|
24039
|
+
|
|
24040
|
+
/* Dropdown styles */
|
|
24041
|
+
.myio-settings-dropdown-container {
|
|
24042
|
+
position: relative;
|
|
24043
|
+
}
|
|
24044
|
+
|
|
24045
|
+
.myio-settings-dropdown-btn {
|
|
24046
|
+
padding: 10px 14px;
|
|
24047
|
+
border: 1px solid ${colors.border};
|
|
24048
|
+
border-radius: 8px;
|
|
24049
|
+
font-size: 14px;
|
|
24050
|
+
background: ${colors.chartBackground};
|
|
24051
|
+
color: ${colors.text};
|
|
24052
|
+
cursor: pointer;
|
|
24053
|
+
min-width: 180px;
|
|
24054
|
+
display: flex;
|
|
24055
|
+
align-items: center;
|
|
24056
|
+
justify-content: space-between;
|
|
24057
|
+
gap: 8px;
|
|
24058
|
+
width: 100%;
|
|
24059
|
+
}
|
|
24060
|
+
|
|
24061
|
+
.myio-settings-dropdown-btn:hover {
|
|
24062
|
+
border-color: ${primaryColor};
|
|
24063
|
+
}
|
|
24064
|
+
|
|
24065
|
+
.myio-settings-dropdown-arrow {
|
|
24066
|
+
font-size: 10px;
|
|
24067
|
+
color: ${colors.textMuted};
|
|
24068
|
+
}
|
|
24069
|
+
|
|
24070
|
+
.myio-settings-dropdown {
|
|
24071
|
+
position: absolute;
|
|
24072
|
+
top: calc(100% + 4px);
|
|
24073
|
+
left: 0;
|
|
24074
|
+
z-index: 100001;
|
|
24075
|
+
background: ${colors.chartBackground};
|
|
24076
|
+
border: 1px solid ${colors.border};
|
|
24077
|
+
border-radius: 8px;
|
|
24078
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
|
24079
|
+
min-width: 220px;
|
|
24080
|
+
padding: 8px 0;
|
|
24081
|
+
}
|
|
24082
|
+
|
|
24083
|
+
.myio-settings-dropdown.hidden {
|
|
24084
|
+
display: none;
|
|
24085
|
+
}
|
|
24086
|
+
|
|
24087
|
+
.myio-settings-dropdown-option {
|
|
24088
|
+
display: flex;
|
|
24089
|
+
align-items: center;
|
|
24090
|
+
gap: 10px;
|
|
24091
|
+
padding: 10px 14px;
|
|
24092
|
+
cursor: pointer;
|
|
24093
|
+
font-size: 13px;
|
|
24094
|
+
color: ${colors.text};
|
|
24095
|
+
transition: background 0.15s;
|
|
24096
|
+
}
|
|
24097
|
+
|
|
24098
|
+
.myio-settings-dropdown-option:hover {
|
|
24099
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.1)" : "#f3f4f6"};
|
|
24100
|
+
}
|
|
24101
|
+
|
|
24102
|
+
.myio-settings-dropdown-option input {
|
|
24103
|
+
width: 16px;
|
|
24104
|
+
height: 16px;
|
|
24105
|
+
cursor: pointer;
|
|
24106
|
+
accent-color: ${primaryColor};
|
|
24107
|
+
}
|
|
24108
|
+
|
|
24109
|
+
.myio-settings-dropdown-actions {
|
|
24110
|
+
border-top: 1px solid ${colors.border};
|
|
24111
|
+
margin-top: 8px;
|
|
24112
|
+
padding: 8px;
|
|
24113
|
+
display: flex;
|
|
24114
|
+
flex-direction: column;
|
|
24115
|
+
gap: 6px;
|
|
24116
|
+
}
|
|
24117
|
+
|
|
24118
|
+
.myio-settings-dropdown-actions button {
|
|
24119
|
+
width: 100%;
|
|
24120
|
+
padding: 8px;
|
|
24121
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.1)" : "#f3f4f6"};
|
|
24122
|
+
border: none;
|
|
24123
|
+
border-radius: 6px;
|
|
24124
|
+
cursor: pointer;
|
|
24125
|
+
font-size: 12px;
|
|
24126
|
+
color: ${colors.text};
|
|
24127
|
+
transition: background 0.15s;
|
|
24128
|
+
}
|
|
24129
|
+
|
|
24130
|
+
.myio-settings-dropdown-actions button:hover {
|
|
24131
|
+
background: ${theme === "dark" ? "rgba(255,255,255,0.15)" : "#e5e7eb"};
|
|
24132
|
+
}
|
|
24133
|
+
|
|
24134
|
+
/* Suggestion icon styles */
|
|
24135
|
+
.myio-settings-section-label span[id$="-settings-suggestion"] {
|
|
24136
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
24137
|
+
}
|
|
24138
|
+
|
|
24139
|
+
.myio-settings-section-label span[id$="-settings-suggestion"]:hover {
|
|
24140
|
+
opacity: 1 !important;
|
|
24141
|
+
transform: scale(1.2);
|
|
24142
|
+
}
|
|
24143
|
+
`;
|
|
24144
|
+
}
|
|
24145
|
+
function createConsumptionChartWidget(config) {
|
|
24146
|
+
const widgetId = `myio-widget-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
24147
|
+
let containerElement = null;
|
|
24148
|
+
let chartInstance = null;
|
|
24149
|
+
let styleElement = null;
|
|
24150
|
+
let settingsModalElement = null;
|
|
24151
|
+
let settingsHeaderInstance = null;
|
|
24152
|
+
let currentTheme = config.theme ?? "light";
|
|
24153
|
+
let currentChartType = config.defaultChartType ?? "line";
|
|
24154
|
+
let currentVizMode = config.defaultVizMode ?? "total";
|
|
24155
|
+
let currentPeriod = config.defaultPeriod ?? 7;
|
|
24156
|
+
let currentIdealRange = config.idealRange ?? null;
|
|
24157
|
+
let tempPeriod = currentPeriod;
|
|
24158
|
+
let tempChartType = currentChartType;
|
|
24159
|
+
let tempVizMode = currentVizMode;
|
|
24160
|
+
let tempTheme = currentTheme;
|
|
24161
|
+
let tempIdealRange = currentIdealRange;
|
|
24162
|
+
let currentSuggestion = null;
|
|
24163
|
+
const domainCfg = DOMAIN_CONFIG4[config.domain] || DOMAIN_CONFIG4.energy;
|
|
24164
|
+
const primaryColor = config.colors?.primary || domainCfg.color;
|
|
24165
|
+
const domainColors = config.colors?.shoppingColors || domainCfg.colors;
|
|
24166
|
+
const showSettingsButton = config.showSettingsButton ?? true;
|
|
24167
|
+
const showMaximizeButton = config.showMaximizeButton ?? true;
|
|
24168
|
+
const showVizModeTabs = config.showVizModeTabs ?? true;
|
|
24169
|
+
const showChartTypeTabs = config.showChartTypeTabs ?? true;
|
|
24170
|
+
const chartHeight = typeof config.chartHeight === "number" ? `${config.chartHeight}px` : config.chartHeight ?? "300px";
|
|
24171
|
+
function getTitle() {
|
|
24172
|
+
if (config.title) return config.title;
|
|
24173
|
+
const domainName = config.domain === "temperature" ? "Temperatura" : "Consumo";
|
|
24174
|
+
return `${domainName} dos \xFAltimos ${currentPeriod} dias`;
|
|
24175
|
+
}
|
|
24176
|
+
function renderHTML() {
|
|
24177
|
+
return `
|
|
24178
|
+
<div id="${widgetId}" class="myio-chart-widget ${currentTheme === "dark" ? "dark" : ""} ${config.className || ""}">
|
|
24179
|
+
<div class="myio-chart-widget-header">
|
|
24180
|
+
<div class="myio-chart-widget-title-group">
|
|
24181
|
+
${showSettingsButton ? `
|
|
24182
|
+
<button id="${widgetId}-settings-btn" class="myio-chart-widget-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
|
|
24183
|
+
` : ""}
|
|
24184
|
+
<h4 id="${widgetId}-title" class="myio-chart-widget-title">${getTitle()}</h4>
|
|
24185
|
+
</div>
|
|
24186
|
+
<div class="myio-chart-widget-controls">
|
|
24187
|
+
${showVizModeTabs ? `
|
|
24188
|
+
<div class="myio-chart-widget-tabs" id="${widgetId}-viz-tabs">
|
|
24189
|
+
<button class="myio-chart-widget-tab ${currentVizMode === "total" ? "active" : ""}" data-viz="total">Consolidado</button>
|
|
24190
|
+
<button class="myio-chart-widget-tab ${currentVizMode === "separate" ? "active" : ""}" data-viz="separate">Por Shopping</button>
|
|
24191
|
+
</div>
|
|
24192
|
+
` : ""}
|
|
24193
|
+
${showChartTypeTabs ? `
|
|
24194
|
+
<div class="myio-chart-widget-tabs" id="${widgetId}-type-tabs">
|
|
24195
|
+
<button class="myio-chart-widget-tab ${currentChartType === "line" ? "active" : ""}" data-type="line">Linhas</button>
|
|
24196
|
+
<button class="myio-chart-widget-tab ${currentChartType === "bar" ? "active" : ""}" data-type="bar">Barras</button>
|
|
24197
|
+
</div>
|
|
24198
|
+
` : ""}
|
|
24199
|
+
${showMaximizeButton ? `
|
|
24200
|
+
<button id="${widgetId}-maximize-btn" class="myio-chart-widget-btn" title="Maximizar">\u26F6</button>
|
|
24201
|
+
` : ""}
|
|
24202
|
+
</div>
|
|
24203
|
+
</div>
|
|
24204
|
+
<div class="myio-chart-widget-body">
|
|
24205
|
+
<div id="${widgetId}-loading" class="myio-chart-widget-loading" style="display: none;">
|
|
24206
|
+
<div class="myio-chart-widget-spinner"></div>
|
|
24207
|
+
</div>
|
|
24208
|
+
<div class="myio-chart-widget-canvas-container" style="height: ${chartHeight};">
|
|
24209
|
+
<canvas id="${widgetId}-canvas"></canvas>
|
|
24210
|
+
</div>
|
|
24211
|
+
</div>
|
|
24212
|
+
<div class="myio-chart-widget-footer" id="${widgetId}-footer">
|
|
24213
|
+
<div class="myio-chart-widget-stat">
|
|
24214
|
+
<span class="myio-chart-widget-stat-label">Total Per\xEDodo</span>
|
|
24215
|
+
<span id="${widgetId}-stat-total" class="myio-chart-widget-stat-value primary">--</span>
|
|
24216
|
+
</div>
|
|
24217
|
+
<div class="myio-chart-widget-stat">
|
|
24218
|
+
<span class="myio-chart-widget-stat-label">M\xE9dia Di\xE1ria</span>
|
|
24219
|
+
<span id="${widgetId}-stat-avg" class="myio-chart-widget-stat-value">--</span>
|
|
24220
|
+
</div>
|
|
24221
|
+
<div class="myio-chart-widget-stat">
|
|
24222
|
+
<span class="myio-chart-widget-stat-label">Dia de Pico</span>
|
|
24223
|
+
<span id="${widgetId}-stat-peak" class="myio-chart-widget-stat-value">--</span>
|
|
24224
|
+
<span id="${widgetId}-stat-peak-date" class="myio-chart-widget-stat-sub"></span>
|
|
24225
|
+
</div>
|
|
24226
|
+
</div>
|
|
24227
|
+
</div>
|
|
24228
|
+
`;
|
|
24229
|
+
}
|
|
24230
|
+
function renderSettingsModal() {
|
|
24231
|
+
const unit = config.unit ?? "";
|
|
24232
|
+
const isTemperature = config.domain === "temperature";
|
|
24233
|
+
settingsHeaderInstance = createModalHeader({
|
|
24234
|
+
id: `${widgetId}-settings`,
|
|
24235
|
+
title: "Configura\xE7\xF5es",
|
|
24236
|
+
icon: "\u2699\uFE0F",
|
|
24237
|
+
theme: tempTheme,
|
|
24238
|
+
backgroundColor: primaryColor,
|
|
24239
|
+
showThemeToggle: false,
|
|
24240
|
+
showMaximize: false,
|
|
24241
|
+
showClose: true,
|
|
24242
|
+
onClose: () => closeSettingsModal()
|
|
24243
|
+
});
|
|
24244
|
+
return `
|
|
24245
|
+
<div id="${widgetId}-settings-overlay" class="myio-settings-overlay hidden">
|
|
24246
|
+
<div class="myio-settings-card">
|
|
24247
|
+
${settingsHeaderInstance.render()}
|
|
24248
|
+
<div class="myio-settings-body">
|
|
24249
|
+
<!-- CONTEXT 1: Per\xEDodo e Dados -->
|
|
24250
|
+
<div class="myio-settings-context-group">
|
|
24251
|
+
<!-- Per\xEDodo -->
|
|
24252
|
+
<div class="myio-settings-section">
|
|
24253
|
+
<div class="myio-settings-section-label">\u{1F4C5} Per\xEDodo</div>
|
|
24254
|
+
<div class="myio-settings-row">
|
|
24255
|
+
<div class="myio-settings-field" style="flex: 1;">
|
|
24256
|
+
<select id="${widgetId}-settings-period" class="myio-settings-select">
|
|
24257
|
+
<option value="7" ${tempPeriod === 7 ? "selected" : ""}>\xDAltimos 7 dias</option>
|
|
24258
|
+
<option value="14" ${tempPeriod === 14 ? "selected" : ""}>\xDAltimos 14 dias</option>
|
|
24259
|
+
<option value="30" ${tempPeriod === 30 ? "selected" : ""}>\xDAltimos 30 dias</option>
|
|
24260
|
+
<option value="60" ${tempPeriod === 60 ? "selected" : ""}>\xDAltimos 60 dias</option>
|
|
24261
|
+
<option value="90" ${tempPeriod === 90 ? "selected" : ""}>\xDAltimos 90 dias</option>
|
|
24262
|
+
</select>
|
|
24263
|
+
</div>
|
|
24264
|
+
</div>
|
|
24265
|
+
</div>
|
|
24266
|
+
|
|
24267
|
+
<!-- Dados -->
|
|
24268
|
+
<div class="myio-settings-section">
|
|
24269
|
+
<div class="myio-settings-section-label">\u{1F4CA} Dados</div>
|
|
24270
|
+
<div class="myio-settings-row">
|
|
24271
|
+
<!-- Granularity Select -->
|
|
24272
|
+
<div class="myio-settings-field">
|
|
24273
|
+
<label class="myio-settings-field-label">Granularidade</label>
|
|
24274
|
+
<select id="${widgetId}-settings-granularity" class="myio-settings-select">
|
|
24275
|
+
<option value="1d" selected>\u{1F4C6} Por Dia</option>
|
|
24276
|
+
<option value="1h">\u{1F550} Por Hora</option>
|
|
24277
|
+
</select>
|
|
24278
|
+
</div>
|
|
24279
|
+
|
|
24280
|
+
<!-- Weekday Filter -->
|
|
24281
|
+
<div class="myio-settings-field">
|
|
24282
|
+
<label class="myio-settings-field-label">Dias da Semana</label>
|
|
24283
|
+
<div class="myio-settings-dropdown-container">
|
|
24284
|
+
<button type="button" id="${widgetId}-settings-weekday-btn" class="myio-settings-dropdown-btn">
|
|
24285
|
+
<span id="${widgetId}-settings-weekday-label">Todos os dias</span>
|
|
24286
|
+
<span class="myio-settings-dropdown-arrow">\u25BC</span>
|
|
24287
|
+
</button>
|
|
24288
|
+
<div id="${widgetId}-settings-weekday-dropdown" class="myio-settings-dropdown hidden">
|
|
24289
|
+
<label class="myio-settings-dropdown-option">
|
|
24290
|
+
<input type="checkbox" name="${widgetId}-weekday" value="dom" checked /> Domingo
|
|
24291
|
+
</label>
|
|
24292
|
+
<label class="myio-settings-dropdown-option">
|
|
24293
|
+
<input type="checkbox" name="${widgetId}-weekday" value="seg" checked /> Segunda-feira
|
|
24294
|
+
</label>
|
|
24295
|
+
<label class="myio-settings-dropdown-option">
|
|
24296
|
+
<input type="checkbox" name="${widgetId}-weekday" value="ter" checked /> Ter\xE7a-feira
|
|
24297
|
+
</label>
|
|
24298
|
+
<label class="myio-settings-dropdown-option">
|
|
24299
|
+
<input type="checkbox" name="${widgetId}-weekday" value="qua" checked /> Quarta-feira
|
|
24300
|
+
</label>
|
|
24301
|
+
<label class="myio-settings-dropdown-option">
|
|
24302
|
+
<input type="checkbox" name="${widgetId}-weekday" value="qui" checked /> Quinta-feira
|
|
24303
|
+
</label>
|
|
24304
|
+
<label class="myio-settings-dropdown-option">
|
|
24305
|
+
<input type="checkbox" name="${widgetId}-weekday" value="sex" checked /> Sexta-feira
|
|
24306
|
+
</label>
|
|
24307
|
+
<label class="myio-settings-dropdown-option">
|
|
24308
|
+
<input type="checkbox" name="${widgetId}-weekday" value="sab" checked /> S\xE1bado
|
|
24309
|
+
</label>
|
|
24310
|
+
<div class="myio-settings-dropdown-actions">
|
|
24311
|
+
<button type="button" id="${widgetId}-settings-weekday-all">Selecionar Todos</button>
|
|
24312
|
+
<button type="button" id="${widgetId}-settings-weekday-clear">Limpar</button>
|
|
24313
|
+
</div>
|
|
24314
|
+
</div>
|
|
24315
|
+
</div>
|
|
24316
|
+
</div>
|
|
24317
|
+
|
|
24318
|
+
<!-- Day Period Filter (only visible when hourly) -->
|
|
24319
|
+
<div class="myio-settings-field" id="${widgetId}-settings-dayperiod-field" style="display: none;">
|
|
24320
|
+
<label class="myio-settings-field-label">Per\xEDodos do Dia</label>
|
|
24321
|
+
<div class="myio-settings-dropdown-container">
|
|
24322
|
+
<button type="button" id="${widgetId}-settings-dayperiod-btn" class="myio-settings-dropdown-btn">
|
|
24323
|
+
<span id="${widgetId}-settings-dayperiod-label">Todos os per\xEDodos</span>
|
|
24324
|
+
<span class="myio-settings-dropdown-arrow">\u25BC</span>
|
|
24325
|
+
</button>
|
|
24326
|
+
<div id="${widgetId}-settings-dayperiod-dropdown" class="myio-settings-dropdown hidden">
|
|
24327
|
+
<label class="myio-settings-dropdown-option">
|
|
24328
|
+
<input type="checkbox" name="${widgetId}-dayperiod" value="madrugada" checked /> Madrugada (00h-06h)
|
|
24329
|
+
</label>
|
|
24330
|
+
<label class="myio-settings-dropdown-option">
|
|
24331
|
+
<input type="checkbox" name="${widgetId}-dayperiod" value="manha" checked /> Manh\xE3 (06h-12h)
|
|
24332
|
+
</label>
|
|
24333
|
+
<label class="myio-settings-dropdown-option">
|
|
24334
|
+
<input type="checkbox" name="${widgetId}-dayperiod" value="tarde" checked /> Tarde (12h-18h)
|
|
24335
|
+
</label>
|
|
24336
|
+
<label class="myio-settings-dropdown-option">
|
|
24337
|
+
<input type="checkbox" name="${widgetId}-dayperiod" value="noite" checked /> Noite (18h-24h)
|
|
24338
|
+
</label>
|
|
24339
|
+
<div class="myio-settings-dropdown-actions">
|
|
24340
|
+
<button type="button" id="${widgetId}-settings-dayperiod-all">Selecionar Todos</button>
|
|
24341
|
+
<button type="button" id="${widgetId}-settings-dayperiod-clear">Limpar</button>
|
|
24342
|
+
</div>
|
|
24343
|
+
</div>
|
|
24344
|
+
</div>
|
|
24345
|
+
</div>
|
|
24346
|
+
</div>
|
|
24347
|
+
</div>
|
|
24348
|
+
</div>
|
|
24349
|
+
|
|
24350
|
+
<!-- CONTEXT 2: Faixa Ideal -->
|
|
24351
|
+
<div class="myio-settings-context-group">
|
|
24352
|
+
<div class="myio-settings-section">
|
|
24353
|
+
<div class="myio-settings-section-label">
|
|
24354
|
+
\u{1F3AF} Faixa Ideal
|
|
24355
|
+
<span class="myio-settings-hint" id="${widgetId}-settings-range-hint">(opcional - deixe zerado para n\xE3o exibir)</span>
|
|
24356
|
+
<span
|
|
24357
|
+
id="${widgetId}-settings-suggestion"
|
|
24358
|
+
title=""
|
|
24359
|
+
style="cursor: pointer; font-size: 16px; opacity: 0.7; transition: opacity 0.2s; margin-left: 4px;"
|
|
24360
|
+
>\u{1F4A1}</span>
|
|
24361
|
+
</div>
|
|
24362
|
+
<div class="myio-settings-row">
|
|
24363
|
+
<div class="myio-settings-field" style="min-width: 100px;">
|
|
24364
|
+
<label class="myio-settings-field-label">M\xEDnimo (${unit})</label>
|
|
24365
|
+
<input type="number" id="${widgetId}-settings-range-min" class="myio-settings-input"
|
|
24366
|
+
value="${tempIdealRange?.min ?? ""}" placeholder="0" step="0.1">
|
|
24367
|
+
</div>
|
|
24368
|
+
<div class="myio-settings-field" style="min-width: 100px;">
|
|
24369
|
+
<label class="myio-settings-field-label">M\xE1ximo (${unit})</label>
|
|
24370
|
+
<input type="number" id="${widgetId}-settings-range-max" class="myio-settings-input"
|
|
24371
|
+
value="${tempIdealRange?.max ?? ""}" placeholder="0" step="0.1">
|
|
24372
|
+
</div>
|
|
24373
|
+
<div class="myio-settings-field" style="flex: 1;">
|
|
24374
|
+
<label class="myio-settings-field-label">R\xF3tulo</label>
|
|
24375
|
+
<input type="text" id="${widgetId}-settings-range-label" class="myio-settings-input"
|
|
24376
|
+
value="${tempIdealRange?.label ?? ""}" placeholder="${isTemperature ? "Faixa Ideal" : "Meta de Consumo"}">
|
|
24377
|
+
</div>
|
|
24378
|
+
</div>
|
|
24379
|
+
</div>
|
|
24380
|
+
</div>
|
|
24381
|
+
|
|
24382
|
+
<!-- CONTEXT 3: Visualiza\xE7\xE3o -->
|
|
24383
|
+
<div class="myio-settings-context-group">
|
|
24384
|
+
<div class="myio-settings-section">
|
|
24385
|
+
<div class="myio-settings-section-label">\u{1F3A8} Visualiza\xE7\xE3o</div>
|
|
24386
|
+
<div class="myio-settings-row" style="gap: 20px; flex-wrap: wrap;">
|
|
24387
|
+
<!-- Chart Type -->
|
|
24388
|
+
<div class="myio-settings-field" style="flex: 1; min-width: 180px;">
|
|
24389
|
+
<label class="myio-settings-field-label">Tipo de Gr\xE1fico</label>
|
|
24390
|
+
<div class="myio-settings-tabs" id="${widgetId}-settings-chart-type">
|
|
24391
|
+
<button class="myio-settings-tab ${tempChartType === "line" ? "active" : ""}" data-type="line">\u{1F4C8} Linhas</button>
|
|
24392
|
+
<button class="myio-settings-tab ${tempChartType === "bar" ? "active" : ""}" data-type="bar">\u{1F4CA} Barras</button>
|
|
24393
|
+
</div>
|
|
24394
|
+
</div>
|
|
24395
|
+
|
|
24396
|
+
<!-- Viz Mode -->
|
|
24397
|
+
<div class="myio-settings-field" style="flex: 1; min-width: 200px;">
|
|
24398
|
+
<label class="myio-settings-field-label">Agrupamento</label>
|
|
24399
|
+
<div class="myio-settings-tabs" id="${widgetId}-settings-viz-mode">
|
|
24400
|
+
<button class="myio-settings-tab ${tempVizMode === "total" ? "active" : ""}" data-viz="total">\u{1F517} Consolidado</button>
|
|
24401
|
+
<button class="myio-settings-tab ${tempVizMode === "separate" ? "active" : ""}" data-viz="separate">\u{1F3EC} Por Shopping</button>
|
|
24402
|
+
</div>
|
|
24403
|
+
</div>
|
|
24404
|
+
|
|
24405
|
+
<!-- Theme -->
|
|
24406
|
+
<div class="myio-settings-field" style="flex: 1; min-width: 160px;">
|
|
24407
|
+
<label class="myio-settings-field-label">Tema</label>
|
|
24408
|
+
<div class="myio-settings-tabs" id="${widgetId}-settings-theme">
|
|
24409
|
+
<button class="myio-settings-tab ${tempTheme === "light" ? "active" : ""}" data-theme="light">\u2600\uFE0F Light</button>
|
|
24410
|
+
<button class="myio-settings-tab ${tempTheme === "dark" ? "active" : ""}" data-theme="dark">\u{1F319} Dark</button>
|
|
24411
|
+
</div>
|
|
24412
|
+
</div>
|
|
24413
|
+
</div>
|
|
24414
|
+
</div>
|
|
24415
|
+
</div>
|
|
24416
|
+
</div>
|
|
24417
|
+
<div class="myio-settings-footer">
|
|
24418
|
+
<button id="${widgetId}-settings-reset" class="myio-settings-btn myio-settings-btn-secondary">Resetar</button>
|
|
24419
|
+
<button id="${widgetId}-settings-apply" class="myio-settings-btn myio-settings-btn-primary">Carregar</button>
|
|
24420
|
+
</div>
|
|
24421
|
+
</div>
|
|
24422
|
+
</div>
|
|
24423
|
+
`;
|
|
24424
|
+
}
|
|
24425
|
+
function injectStyles() {
|
|
24426
|
+
if (styleElement) return;
|
|
24427
|
+
styleElement = document.createElement("style");
|
|
24428
|
+
styleElement.id = `${widgetId}-styles`;
|
|
24429
|
+
styleElement.textContent = getWidgetStyles(currentTheme, primaryColor);
|
|
24430
|
+
document.head.appendChild(styleElement);
|
|
24431
|
+
}
|
|
24432
|
+
function updateStyles() {
|
|
24433
|
+
if (styleElement) {
|
|
24434
|
+
styleElement.textContent = getWidgetStyles(currentTheme, primaryColor);
|
|
24435
|
+
}
|
|
24436
|
+
}
|
|
24437
|
+
function setupListeners() {
|
|
24438
|
+
if (showSettingsButton) {
|
|
24439
|
+
document.getElementById(`${widgetId}-settings-btn`)?.addEventListener("click", () => {
|
|
24440
|
+
openSettingsModal();
|
|
24441
|
+
config.onSettingsClick?.();
|
|
24442
|
+
});
|
|
24443
|
+
}
|
|
24444
|
+
if (showMaximizeButton && config.onMaximizeClick) {
|
|
24445
|
+
document.getElementById(`${widgetId}-maximize-btn`)?.addEventListener("click", () => {
|
|
24446
|
+
config.onMaximizeClick?.();
|
|
24447
|
+
});
|
|
24448
|
+
}
|
|
24449
|
+
if (showVizModeTabs) {
|
|
24450
|
+
document.getElementById(`${widgetId}-viz-tabs`)?.addEventListener("click", (e) => {
|
|
24451
|
+
const target = e.target;
|
|
24452
|
+
if (target.classList.contains("myio-chart-widget-tab")) {
|
|
24453
|
+
const mode = target.dataset.viz;
|
|
24454
|
+
if (mode) {
|
|
24455
|
+
instance.setVizMode(mode);
|
|
24456
|
+
}
|
|
24457
|
+
}
|
|
24458
|
+
});
|
|
24459
|
+
}
|
|
24460
|
+
if (showChartTypeTabs) {
|
|
24461
|
+
document.getElementById(`${widgetId}-type-tabs`)?.addEventListener("click", (e) => {
|
|
24462
|
+
const target = e.target;
|
|
24463
|
+
if (target.classList.contains("myio-chart-widget-tab")) {
|
|
24464
|
+
const type = target.dataset.type;
|
|
24465
|
+
if (type) {
|
|
24466
|
+
instance.setChartType(type);
|
|
24467
|
+
}
|
|
24468
|
+
}
|
|
24469
|
+
});
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24472
|
+
function updateTabStates() {
|
|
24473
|
+
document.querySelectorAll(`#${widgetId}-viz-tabs .myio-chart-widget-tab`).forEach((tab) => {
|
|
24474
|
+
const btn = tab;
|
|
24475
|
+
btn.classList.toggle("active", btn.dataset.viz === currentVizMode);
|
|
24476
|
+
});
|
|
24477
|
+
document.querySelectorAll(`#${widgetId}-type-tabs .myio-chart-widget-tab`).forEach((tab) => {
|
|
24478
|
+
const btn = tab;
|
|
24479
|
+
btn.classList.toggle("active", btn.dataset.type === currentChartType);
|
|
24480
|
+
});
|
|
24481
|
+
}
|
|
24482
|
+
function updateTitle() {
|
|
24483
|
+
const titleEl = document.getElementById(`${widgetId}-title`);
|
|
24484
|
+
if (titleEl) {
|
|
24485
|
+
titleEl.textContent = getTitle();
|
|
24486
|
+
}
|
|
24487
|
+
}
|
|
24488
|
+
function setLoading(loading) {
|
|
24489
|
+
const loadingEl = document.getElementById(`${widgetId}-loading`);
|
|
24490
|
+
if (loadingEl) {
|
|
24491
|
+
loadingEl.style.display = loading ? "flex" : "none";
|
|
24492
|
+
}
|
|
24493
|
+
}
|
|
24494
|
+
function formatValue(value) {
|
|
24495
|
+
const unit = config.unit ?? "";
|
|
24496
|
+
const unitLarge = config.unitLarge;
|
|
24497
|
+
const threshold = config.thresholdForLargeUnit ?? 1e3;
|
|
24498
|
+
if (unitLarge && Math.abs(value) >= threshold) {
|
|
24499
|
+
return `${(value / threshold).toFixed(2)} ${unitLarge}`;
|
|
24500
|
+
}
|
|
24501
|
+
return `${value.toFixed(2)} ${unit}`;
|
|
24502
|
+
}
|
|
24503
|
+
function updateFooterStats(data) {
|
|
24504
|
+
const totalEl = document.getElementById(`${widgetId}-stat-total`);
|
|
24505
|
+
const avgEl = document.getElementById(`${widgetId}-stat-avg`);
|
|
24506
|
+
const peakEl = document.getElementById(`${widgetId}-stat-peak`);
|
|
24507
|
+
const peakDateEl = document.getElementById(`${widgetId}-stat-peak-date`);
|
|
24508
|
+
if (!data.dailyTotals || data.dailyTotals.length === 0) {
|
|
24509
|
+
if (totalEl) totalEl.textContent = "--";
|
|
24510
|
+
if (avgEl) avgEl.textContent = "--";
|
|
24511
|
+
if (peakEl) peakEl.textContent = "--";
|
|
24512
|
+
if (peakDateEl) peakDateEl.textContent = "";
|
|
24513
|
+
return;
|
|
24514
|
+
}
|
|
24515
|
+
const isTemperature = config.domain === "temperature";
|
|
24516
|
+
const totals = data.dailyTotals;
|
|
24517
|
+
const labels = data.labels ?? [];
|
|
24518
|
+
const total = totals.reduce((a, b) => a + b, 0);
|
|
24519
|
+
const avg = total / totals.length;
|
|
24520
|
+
const peakValue = Math.max(...totals);
|
|
24521
|
+
const peakIndex = totals.indexOf(peakValue);
|
|
24522
|
+
const peakDate = labels[peakIndex] ?? "";
|
|
24523
|
+
if (totalEl) {
|
|
24524
|
+
if (isTemperature) {
|
|
24525
|
+
totalEl.textContent = formatValue(avg);
|
|
24526
|
+
const labelEl = totalEl.previousElementSibling;
|
|
24527
|
+
if (labelEl) labelEl.textContent = "M\xE9dia Per\xEDodo";
|
|
24528
|
+
} else {
|
|
24529
|
+
totalEl.textContent = formatValue(total);
|
|
24530
|
+
}
|
|
24531
|
+
}
|
|
24532
|
+
if (avgEl) {
|
|
24533
|
+
avgEl.textContent = formatValue(avg);
|
|
24534
|
+
}
|
|
24535
|
+
if (peakEl) {
|
|
24536
|
+
peakEl.textContent = formatValue(peakValue);
|
|
24537
|
+
}
|
|
24538
|
+
if (peakDateEl) {
|
|
24539
|
+
peakDateEl.textContent = peakDate;
|
|
24540
|
+
}
|
|
24541
|
+
}
|
|
24542
|
+
function openSettingsModal() {
|
|
24543
|
+
tempPeriod = currentPeriod;
|
|
24544
|
+
tempChartType = currentChartType;
|
|
24545
|
+
tempVizMode = currentVizMode;
|
|
24546
|
+
tempTheme = currentTheme;
|
|
24547
|
+
tempIdealRange = currentIdealRange ? { ...currentIdealRange } : null;
|
|
24548
|
+
if (!settingsModalElement) {
|
|
24549
|
+
settingsModalElement = document.createElement("div");
|
|
24550
|
+
settingsModalElement.innerHTML = renderSettingsModal();
|
|
24551
|
+
document.body.appendChild(settingsModalElement.firstElementChild);
|
|
24552
|
+
settingsModalElement = document.getElementById(`${widgetId}-settings-overlay`);
|
|
24553
|
+
setupSettingsModalListeners();
|
|
24554
|
+
}
|
|
24555
|
+
updateSettingsModalValues();
|
|
24556
|
+
updateIdealRangeSuggestionTooltip();
|
|
24557
|
+
settingsModalElement?.classList.remove("hidden");
|
|
24558
|
+
}
|
|
24559
|
+
function closeSettingsModal() {
|
|
24560
|
+
settingsModalElement?.classList.add("hidden");
|
|
24561
|
+
}
|
|
24562
|
+
function updateSettingsModalValues() {
|
|
24563
|
+
const periodSelect = document.getElementById(`${widgetId}-settings-period`);
|
|
24564
|
+
if (periodSelect) periodSelect.value = String(tempPeriod);
|
|
24565
|
+
const minInput = document.getElementById(`${widgetId}-settings-range-min`);
|
|
24566
|
+
const maxInput = document.getElementById(`${widgetId}-settings-range-max`);
|
|
24567
|
+
const labelInput = document.getElementById(`${widgetId}-settings-range-label`);
|
|
24568
|
+
if (minInput) minInput.value = tempIdealRange?.min?.toString() ?? "";
|
|
24569
|
+
if (maxInput) maxInput.value = tempIdealRange?.max?.toString() ?? "";
|
|
24570
|
+
if (labelInput) labelInput.value = tempIdealRange?.label ?? "";
|
|
24571
|
+
updateSettingsModalTabs();
|
|
24572
|
+
}
|
|
24573
|
+
function updateSettingsModalTabs() {
|
|
24574
|
+
document.querySelectorAll(`#${widgetId}-settings-chart-type .myio-settings-tab`).forEach((tab) => {
|
|
24575
|
+
const btn = tab;
|
|
24576
|
+
btn.classList.toggle("active", btn.dataset.type === tempChartType);
|
|
24577
|
+
});
|
|
24578
|
+
document.querySelectorAll(`#${widgetId}-settings-viz-mode .myio-settings-tab`).forEach((tab) => {
|
|
24579
|
+
const btn = tab;
|
|
24580
|
+
btn.classList.toggle("active", btn.dataset.viz === tempVizMode);
|
|
24581
|
+
});
|
|
24582
|
+
document.querySelectorAll(`#${widgetId}-settings-theme .myio-settings-tab`).forEach((tab) => {
|
|
24583
|
+
const btn = tab;
|
|
24584
|
+
btn.classList.toggle("active", btn.dataset.theme === tempTheme);
|
|
24585
|
+
});
|
|
24586
|
+
}
|
|
24587
|
+
function updateWeekdayLabel() {
|
|
24588
|
+
const checkboxes = document.querySelectorAll(`input[name="${widgetId}-weekday"]`);
|
|
24589
|
+
const checked = Array.from(checkboxes).filter((cb) => cb.checked);
|
|
24590
|
+
const label = document.getElementById(`${widgetId}-settings-weekday-label`);
|
|
24591
|
+
if (label) {
|
|
24592
|
+
if (checked.length === 0) {
|
|
24593
|
+
label.textContent = "Nenhum dia";
|
|
24594
|
+
} else if (checked.length === checkboxes.length) {
|
|
24595
|
+
label.textContent = "Todos os dias";
|
|
24596
|
+
} else {
|
|
24597
|
+
label.textContent = `${checked.length} dias selecionados`;
|
|
24598
|
+
}
|
|
24599
|
+
}
|
|
24600
|
+
}
|
|
24601
|
+
function updateDayPeriodLabel() {
|
|
24602
|
+
const checkboxes = document.querySelectorAll(`input[name="${widgetId}-dayperiod"]`);
|
|
24603
|
+
const checked = Array.from(checkboxes).filter((cb) => cb.checked);
|
|
24604
|
+
const label = document.getElementById(`${widgetId}-settings-dayperiod-label`);
|
|
24605
|
+
if (label) {
|
|
24606
|
+
if (checked.length === 0) {
|
|
24607
|
+
label.textContent = "Nenhum per\xEDodo";
|
|
24608
|
+
} else if (checked.length === checkboxes.length) {
|
|
24609
|
+
label.textContent = "Todos os per\xEDodos";
|
|
24610
|
+
} else {
|
|
24611
|
+
label.textContent = `${checked.length} per\xEDodos selecionados`;
|
|
24612
|
+
}
|
|
24613
|
+
}
|
|
24614
|
+
}
|
|
24615
|
+
function calculateIdealRangeSuggestion() {
|
|
24616
|
+
const data = chartInstance?.getCachedData();
|
|
24617
|
+
if (!data || !data.dailyTotals || data.dailyTotals.length === 0) {
|
|
24618
|
+
return { min: 0, max: 0, avg: 0 };
|
|
24619
|
+
}
|
|
24620
|
+
const total = data.dailyTotals.reduce((a, b) => a + b, 0);
|
|
24621
|
+
const avg = total / data.dailyTotals.length;
|
|
24622
|
+
const min = avg * 0.85;
|
|
24623
|
+
const max = avg * 1.15;
|
|
24624
|
+
return {
|
|
24625
|
+
min: Math.round(min * 10) / 10,
|
|
24626
|
+
max: Math.round(max * 10) / 10,
|
|
24627
|
+
avg: Math.round(avg * 10) / 10
|
|
24628
|
+
};
|
|
24629
|
+
}
|
|
24630
|
+
function updateIdealRangeSuggestionTooltip() {
|
|
24631
|
+
const suggestion = calculateIdealRangeSuggestion();
|
|
24632
|
+
const suggestionEl = document.getElementById(`${widgetId}-settings-suggestion`);
|
|
24633
|
+
const hintEl = document.getElementById(`${widgetId}-settings-range-hint`);
|
|
24634
|
+
const unit = config.unit ?? "";
|
|
24635
|
+
const isTemperature = config.domain === "temperature";
|
|
24636
|
+
currentSuggestion = suggestion;
|
|
24637
|
+
if (hintEl) {
|
|
24638
|
+
if (isTemperature) {
|
|
24639
|
+
hintEl.textContent = "(valores carregados do cliente)";
|
|
24640
|
+
} else {
|
|
24641
|
+
hintEl.textContent = "(opcional - deixe zerado para n\xE3o exibir)";
|
|
24642
|
+
}
|
|
24643
|
+
}
|
|
24644
|
+
if (suggestionEl) {
|
|
24645
|
+
if (suggestion.avg > 0) {
|
|
24646
|
+
const tooltipText = `Sugest\xE3o: ${suggestion.min} - ${suggestion.max} ${unit} (m\xE9dia \xB115%). Clique para aplicar.`;
|
|
24647
|
+
suggestionEl.title = tooltipText;
|
|
24648
|
+
suggestionEl.style.display = "inline";
|
|
24649
|
+
} else {
|
|
24650
|
+
suggestionEl.style.display = "none";
|
|
24651
|
+
}
|
|
24652
|
+
}
|
|
24653
|
+
}
|
|
24654
|
+
function applyIdealRangeSuggestion() {
|
|
24655
|
+
if (!currentSuggestion || currentSuggestion.min === 0 && currentSuggestion.max === 0) {
|
|
24656
|
+
return;
|
|
24657
|
+
}
|
|
24658
|
+
const minInput = document.getElementById(`${widgetId}-settings-range-min`);
|
|
24659
|
+
const maxInput = document.getElementById(`${widgetId}-settings-range-max`);
|
|
24660
|
+
const labelInput = document.getElementById(`${widgetId}-settings-range-label`);
|
|
24661
|
+
if (minInput) minInput.value = String(currentSuggestion.min);
|
|
24662
|
+
if (maxInput) maxInput.value = String(currentSuggestion.max);
|
|
24663
|
+
if (labelInput) labelInput.value = "Faixa Sugerida";
|
|
24664
|
+
tempIdealRange = {
|
|
24665
|
+
min: currentSuggestion.min,
|
|
24666
|
+
max: currentSuggestion.max,
|
|
24667
|
+
label: "Faixa Sugerida"
|
|
24668
|
+
};
|
|
24669
|
+
}
|
|
24670
|
+
function setupSettingsModalListeners() {
|
|
24671
|
+
settingsHeaderInstance?.attachListeners();
|
|
24672
|
+
document.getElementById(`${widgetId}-settings-overlay`)?.addEventListener("click", (e) => {
|
|
24673
|
+
if (e.target.classList.contains("myio-settings-overlay")) {
|
|
24674
|
+
closeSettingsModal();
|
|
24675
|
+
}
|
|
24676
|
+
});
|
|
24677
|
+
document.getElementById(`${widgetId}-settings-granularity`)?.addEventListener("change", (e) => {
|
|
24678
|
+
const select = e.target;
|
|
24679
|
+
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
24680
|
+
if (dayPeriodField) {
|
|
24681
|
+
dayPeriodField.style.display = select.value === "1h" ? "block" : "none";
|
|
24682
|
+
}
|
|
24683
|
+
});
|
|
24684
|
+
document.getElementById(`${widgetId}-settings-suggestion`)?.addEventListener("click", () => {
|
|
24685
|
+
applyIdealRangeSuggestion();
|
|
24686
|
+
});
|
|
24687
|
+
document.getElementById(`${widgetId}-settings-weekday-btn`)?.addEventListener("click", (e) => {
|
|
24688
|
+
e.stopPropagation();
|
|
24689
|
+
const dropdown = document.getElementById(`${widgetId}-settings-weekday-dropdown`);
|
|
24690
|
+
dropdown?.classList.toggle("hidden");
|
|
24691
|
+
});
|
|
24692
|
+
document.querySelectorAll(`input[name="${widgetId}-weekday"]`).forEach((cb) => {
|
|
24693
|
+
cb.addEventListener("change", updateWeekdayLabel);
|
|
24694
|
+
});
|
|
24695
|
+
document.getElementById(`${widgetId}-settings-weekday-all`)?.addEventListener("click", () => {
|
|
24696
|
+
document.querySelectorAll(`input[name="${widgetId}-weekday"]`).forEach((cb) => {
|
|
24697
|
+
cb.checked = true;
|
|
24698
|
+
});
|
|
24699
|
+
updateWeekdayLabel();
|
|
24700
|
+
});
|
|
24701
|
+
document.getElementById(`${widgetId}-settings-weekday-clear`)?.addEventListener("click", () => {
|
|
24702
|
+
document.querySelectorAll(`input[name="${widgetId}-weekday"]`).forEach((cb) => {
|
|
24703
|
+
cb.checked = false;
|
|
24704
|
+
});
|
|
24705
|
+
updateWeekdayLabel();
|
|
24706
|
+
});
|
|
24707
|
+
document.getElementById(`${widgetId}-settings-dayperiod-btn`)?.addEventListener("click", (e) => {
|
|
24708
|
+
e.stopPropagation();
|
|
24709
|
+
const dropdown = document.getElementById(`${widgetId}-settings-dayperiod-dropdown`);
|
|
24710
|
+
dropdown?.classList.toggle("hidden");
|
|
24711
|
+
});
|
|
24712
|
+
document.querySelectorAll(`input[name="${widgetId}-dayperiod"]`).forEach((cb) => {
|
|
24713
|
+
cb.addEventListener("change", updateDayPeriodLabel);
|
|
24714
|
+
});
|
|
24715
|
+
document.getElementById(`${widgetId}-settings-dayperiod-all`)?.addEventListener("click", () => {
|
|
24716
|
+
document.querySelectorAll(`input[name="${widgetId}-dayperiod"]`).forEach((cb) => {
|
|
24717
|
+
cb.checked = true;
|
|
24718
|
+
});
|
|
24719
|
+
updateDayPeriodLabel();
|
|
24720
|
+
});
|
|
24721
|
+
document.getElementById(`${widgetId}-settings-dayperiod-clear`)?.addEventListener("click", () => {
|
|
24722
|
+
document.querySelectorAll(`input[name="${widgetId}-dayperiod"]`).forEach((cb) => {
|
|
24723
|
+
cb.checked = false;
|
|
24724
|
+
});
|
|
24725
|
+
updateDayPeriodLabel();
|
|
24726
|
+
});
|
|
24727
|
+
document.addEventListener("click", (e) => {
|
|
24728
|
+
const target = e.target;
|
|
24729
|
+
const weekdayDropdown = document.getElementById(`${widgetId}-settings-weekday-dropdown`);
|
|
24730
|
+
const dayperiodDropdown = document.getElementById(`${widgetId}-settings-dayperiod-dropdown`);
|
|
24731
|
+
if (weekdayDropdown && !target.closest(`#${widgetId}-settings-weekday-btn`) && !target.closest(`#${widgetId}-settings-weekday-dropdown`)) {
|
|
24732
|
+
weekdayDropdown.classList.add("hidden");
|
|
24733
|
+
}
|
|
24734
|
+
if (dayperiodDropdown && !target.closest(`#${widgetId}-settings-dayperiod-btn`) && !target.closest(`#${widgetId}-settings-dayperiod-dropdown`)) {
|
|
24735
|
+
dayperiodDropdown.classList.add("hidden");
|
|
24736
|
+
}
|
|
24737
|
+
});
|
|
24738
|
+
document.getElementById(`${widgetId}-settings-chart-type`)?.addEventListener("click", (e) => {
|
|
24739
|
+
const target = e.target;
|
|
24740
|
+
if (target.classList.contains("myio-settings-tab")) {
|
|
24741
|
+
tempChartType = target.dataset.type;
|
|
24742
|
+
updateSettingsModalTabs();
|
|
24743
|
+
}
|
|
24744
|
+
});
|
|
24745
|
+
document.getElementById(`${widgetId}-settings-viz-mode`)?.addEventListener("click", (e) => {
|
|
24746
|
+
const target = e.target;
|
|
24747
|
+
if (target.classList.contains("myio-settings-tab")) {
|
|
24748
|
+
tempVizMode = target.dataset.viz;
|
|
24749
|
+
updateSettingsModalTabs();
|
|
24750
|
+
}
|
|
24751
|
+
});
|
|
24752
|
+
document.getElementById(`${widgetId}-settings-theme`)?.addEventListener("click", (e) => {
|
|
24753
|
+
const target = e.target;
|
|
24754
|
+
if (target.classList.contains("myio-settings-tab")) {
|
|
24755
|
+
tempTheme = target.dataset.theme;
|
|
24756
|
+
updateSettingsModalTabs();
|
|
24757
|
+
}
|
|
24758
|
+
});
|
|
24759
|
+
document.getElementById(`${widgetId}-settings-reset`)?.addEventListener("click", () => {
|
|
24760
|
+
tempPeriod = config.defaultPeriod ?? 7;
|
|
24761
|
+
tempChartType = config.defaultChartType ?? "line";
|
|
24762
|
+
tempVizMode = config.defaultVizMode ?? "total";
|
|
24763
|
+
tempTheme = config.theme ?? "light";
|
|
24764
|
+
tempIdealRange = config.idealRange ?? null;
|
|
24765
|
+
const granularitySelect = document.getElementById(`${widgetId}-settings-granularity`);
|
|
24766
|
+
if (granularitySelect) granularitySelect.value = "1d";
|
|
24767
|
+
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
24768
|
+
if (dayPeriodField) dayPeriodField.style.display = "none";
|
|
24769
|
+
document.querySelectorAll(`input[name="${widgetId}-weekday"]`).forEach((cb) => {
|
|
24770
|
+
cb.checked = true;
|
|
24771
|
+
});
|
|
24772
|
+
updateWeekdayLabel();
|
|
24773
|
+
document.querySelectorAll(`input[name="${widgetId}-dayperiod"]`).forEach((cb) => {
|
|
24774
|
+
cb.checked = true;
|
|
24775
|
+
});
|
|
24776
|
+
updateDayPeriodLabel();
|
|
24777
|
+
updateSettingsModalValues();
|
|
24778
|
+
});
|
|
24779
|
+
document.getElementById(`${widgetId}-settings-apply`)?.addEventListener("click", async () => {
|
|
24780
|
+
const minInput = document.getElementById(`${widgetId}-settings-range-min`);
|
|
24781
|
+
const maxInput = document.getElementById(`${widgetId}-settings-range-max`);
|
|
24782
|
+
const labelInput = document.getElementById(`${widgetId}-settings-range-label`);
|
|
24783
|
+
const periodSelect = document.getElementById(`${widgetId}-settings-period`);
|
|
24784
|
+
const min = parseFloat(minInput?.value || "0");
|
|
24785
|
+
const max = parseFloat(maxInput?.value || "0");
|
|
24786
|
+
const label = labelInput?.value || "";
|
|
24787
|
+
tempPeriod = parseInt(periodSelect?.value || "7", 10);
|
|
24788
|
+
if (min > 0 || max > 0) {
|
|
24789
|
+
tempIdealRange = { min, max, label };
|
|
24790
|
+
} else {
|
|
24791
|
+
tempIdealRange = null;
|
|
24792
|
+
}
|
|
24793
|
+
closeSettingsModal();
|
|
24794
|
+
if (tempTheme !== currentTheme) {
|
|
24795
|
+
instance.setTheme(tempTheme);
|
|
24796
|
+
}
|
|
24797
|
+
if (tempChartType !== currentChartType) {
|
|
24798
|
+
instance.setChartType(tempChartType);
|
|
24799
|
+
}
|
|
24800
|
+
if (tempVizMode !== currentVizMode) {
|
|
24801
|
+
instance.setVizMode(tempVizMode);
|
|
24802
|
+
}
|
|
24803
|
+
if (JSON.stringify(tempIdealRange) !== JSON.stringify(currentIdealRange)) {
|
|
24804
|
+
instance.setIdealRange(tempIdealRange);
|
|
24805
|
+
}
|
|
24806
|
+
if (tempPeriod !== currentPeriod) {
|
|
24807
|
+
await instance.setPeriod(tempPeriod);
|
|
24808
|
+
}
|
|
24809
|
+
});
|
|
24810
|
+
}
|
|
24811
|
+
const instance = {
|
|
24812
|
+
async render() {
|
|
24813
|
+
containerElement = document.getElementById(config.containerId);
|
|
24814
|
+
if (!containerElement) {
|
|
24815
|
+
console.error(`[ConsumptionWidget] Container #${config.containerId} not found`);
|
|
24816
|
+
return;
|
|
24817
|
+
}
|
|
24818
|
+
injectStyles();
|
|
24819
|
+
containerElement.innerHTML = renderHTML();
|
|
24820
|
+
setupListeners();
|
|
24821
|
+
setLoading(true);
|
|
24822
|
+
chartInstance = createConsumption7DaysChart({
|
|
24823
|
+
...config,
|
|
24824
|
+
containerId: `${widgetId}-canvas`,
|
|
24825
|
+
theme: currentTheme,
|
|
24826
|
+
defaultChartType: currentChartType,
|
|
24827
|
+
defaultVizMode: currentVizMode,
|
|
24828
|
+
defaultPeriod: currentPeriod,
|
|
24829
|
+
idealRange: currentIdealRange,
|
|
24830
|
+
colors: {
|
|
24831
|
+
primary: primaryColor,
|
|
24832
|
+
background: `${primaryColor}20`,
|
|
24833
|
+
shoppingColors: domainColors,
|
|
24834
|
+
...config.colors
|
|
24835
|
+
},
|
|
24836
|
+
onDataLoaded: (data) => {
|
|
24837
|
+
setLoading(false);
|
|
24838
|
+
updateFooterStats(data);
|
|
24839
|
+
config.onDataLoaded?.(data);
|
|
24840
|
+
},
|
|
24841
|
+
onError: (error) => {
|
|
24842
|
+
setLoading(false);
|
|
24843
|
+
config.onError?.(error);
|
|
24844
|
+
}
|
|
24845
|
+
});
|
|
24846
|
+
await chartInstance.render();
|
|
24847
|
+
setLoading(false);
|
|
24848
|
+
},
|
|
24849
|
+
async refresh(forceRefresh = false) {
|
|
24850
|
+
if (!chartInstance) return;
|
|
24851
|
+
setLoading(true);
|
|
24852
|
+
await chartInstance.refresh(forceRefresh);
|
|
24853
|
+
setLoading(false);
|
|
24854
|
+
},
|
|
24855
|
+
setChartType(type) {
|
|
24856
|
+
if (currentChartType === type) return;
|
|
24857
|
+
currentChartType = type;
|
|
24858
|
+
chartInstance?.setChartType(type);
|
|
24859
|
+
updateTabStates();
|
|
24860
|
+
},
|
|
24861
|
+
setVizMode(mode) {
|
|
24862
|
+
if (currentVizMode === mode) return;
|
|
24863
|
+
currentVizMode = mode;
|
|
24864
|
+
chartInstance?.setVizMode(mode);
|
|
24865
|
+
updateTabStates();
|
|
24866
|
+
},
|
|
24867
|
+
setTheme(theme) {
|
|
24868
|
+
if (currentTheme === theme) return;
|
|
24869
|
+
currentTheme = theme;
|
|
24870
|
+
chartInstance?.setTheme(theme);
|
|
24871
|
+
const widget = document.getElementById(widgetId);
|
|
24872
|
+
if (widget) {
|
|
24873
|
+
widget.classList.toggle("dark", theme === "dark");
|
|
24874
|
+
}
|
|
24875
|
+
updateStyles();
|
|
24876
|
+
},
|
|
24877
|
+
async setPeriod(days) {
|
|
24878
|
+
if (currentPeriod === days) return;
|
|
24879
|
+
currentPeriod = days;
|
|
24880
|
+
updateTitle();
|
|
24881
|
+
setLoading(true);
|
|
24882
|
+
await chartInstance?.setPeriod(days);
|
|
24883
|
+
setLoading(false);
|
|
24884
|
+
},
|
|
24885
|
+
setIdealRange(range) {
|
|
24886
|
+
currentIdealRange = range;
|
|
24887
|
+
chartInstance?.setIdealRange(range);
|
|
24888
|
+
},
|
|
24889
|
+
getChart() {
|
|
24890
|
+
return chartInstance;
|
|
24891
|
+
},
|
|
24892
|
+
// Alias for backwards compatibility with createConsumption7DaysChart API
|
|
24893
|
+
getChartInstance() {
|
|
24894
|
+
return chartInstance?.getChartInstance?.() ?? null;
|
|
24895
|
+
},
|
|
24896
|
+
getCachedData() {
|
|
24897
|
+
return chartInstance?.getCachedData() ?? null;
|
|
24898
|
+
},
|
|
24899
|
+
exportCSV(filename) {
|
|
24900
|
+
chartInstance?.exportCSV(filename);
|
|
24901
|
+
},
|
|
24902
|
+
destroy() {
|
|
24903
|
+
chartInstance?.destroy();
|
|
24904
|
+
chartInstance = null;
|
|
24905
|
+
if (styleElement) {
|
|
24906
|
+
styleElement.remove();
|
|
24907
|
+
styleElement = null;
|
|
24908
|
+
}
|
|
24909
|
+
settingsHeaderInstance?.destroy();
|
|
24910
|
+
settingsHeaderInstance = null;
|
|
24911
|
+
if (settingsModalElement) {
|
|
24912
|
+
settingsModalElement.remove();
|
|
24913
|
+
settingsModalElement = null;
|
|
24914
|
+
}
|
|
24915
|
+
if (containerElement) {
|
|
24916
|
+
containerElement.innerHTML = "";
|
|
24917
|
+
containerElement = null;
|
|
24918
|
+
}
|
|
24919
|
+
}
|
|
24920
|
+
};
|
|
24921
|
+
return instance;
|
|
24922
|
+
}
|
|
24923
|
+
|
|
23655
24924
|
// src/components/ExportData/index.ts
|
|
23656
|
-
var
|
|
24925
|
+
var DEFAULT_COLORS4 = {
|
|
23657
24926
|
primary: "#3e1a7d",
|
|
23658
24927
|
// MyIO purple
|
|
23659
24928
|
secondary: "#6b4c9a",
|
|
@@ -23981,9 +25250,9 @@ ${rangeText}`;
|
|
|
23981
25250
|
footerText
|
|
23982
25251
|
} = params;
|
|
23983
25252
|
const colors = {
|
|
23984
|
-
...
|
|
25253
|
+
...DEFAULT_COLORS4,
|
|
23985
25254
|
...colorsPallet,
|
|
23986
|
-
chartColors: colorsPallet?.chartColors ||
|
|
25255
|
+
chartColors: colorsPallet?.chartColors || DEFAULT_COLORS4.chartColors
|
|
23987
25256
|
};
|
|
23988
25257
|
return {
|
|
23989
25258
|
domain,
|
|
@@ -24086,7 +25355,7 @@ ${rangeText}`;
|
|
|
24086
25355
|
}
|
|
24087
25356
|
return instance;
|
|
24088
25357
|
}
|
|
24089
|
-
var EXPORT_DEFAULT_COLORS =
|
|
25358
|
+
var EXPORT_DEFAULT_COLORS = DEFAULT_COLORS4;
|
|
24090
25359
|
var EXPORT_DOMAIN_ICONS = DOMAIN_ICONS;
|
|
24091
25360
|
var EXPORT_DOMAIN_LABELS = DOMAIN_LABELS;
|
|
24092
25361
|
var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
@@ -24127,6 +25396,7 @@ ${rangeText}`;
|
|
|
24127
25396
|
exports.clearAllAuthCaches = clearAllAuthCaches;
|
|
24128
25397
|
exports.connectionStatusIcons = connectionStatusIcons;
|
|
24129
25398
|
exports.createConsumption7DaysChart = createConsumption7DaysChart;
|
|
25399
|
+
exports.createConsumptionChartWidget = createConsumptionChartWidget;
|
|
24130
25400
|
exports.createConsumptionModal = createConsumptionModal;
|
|
24131
25401
|
exports.createDateRangePicker = createDateRangePicker2;
|
|
24132
25402
|
exports.createInputDateRangePickerInsideDIV = createInputDateRangePickerInsideDIV;
|