myio-js-library 0.1.165 → 0.1.166
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 +695 -50
- package/dist/index.d.cts +229 -9
- package/dist/index.js +684 -50
- package/dist/myio-js-library.umd.js +682 -50
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -574,6 +574,10 @@ __export(index_exports, {
|
|
|
574
574
|
CONSUMPTION_THEME_COLORS: () => THEME_COLORS,
|
|
575
575
|
ConnectionStatusType: () => ConnectionStatusType,
|
|
576
576
|
DEFAULT_CLAMP_RANGE: () => DEFAULT_CLAMP_RANGE,
|
|
577
|
+
DEFAULT_ENERGY_GROUP_COLORS: () => DEFAULT_ENERGY_GROUP_COLORS,
|
|
578
|
+
DEFAULT_GAS_GROUP_COLORS: () => DEFAULT_GAS_GROUP_COLORS,
|
|
579
|
+
DEFAULT_SHOPPING_COLORS: () => DEFAULT_SHOPPING_COLORS,
|
|
580
|
+
DEFAULT_WATER_GROUP_COLORS: () => DEFAULT_WATER_GROUP_COLORS,
|
|
577
581
|
DeviceStatusType: () => DeviceStatusType,
|
|
578
582
|
EXPORT_DEFAULT_COLORS: () => EXPORT_DEFAULT_COLORS,
|
|
579
583
|
EXPORT_DOMAIN_ICONS: () => EXPORT_DOMAIN_ICONS,
|
|
@@ -587,6 +591,7 @@ __export(index_exports, {
|
|
|
587
591
|
addDetectionContext: () => addDetectionContext,
|
|
588
592
|
addNamespace: () => addNamespace,
|
|
589
593
|
aggregateByDay: () => aggregateByDay,
|
|
594
|
+
assignShoppingColors: () => assignShoppingColors,
|
|
590
595
|
averageByDay: () => averageByDay,
|
|
591
596
|
buildListItemsThingsboardByUniqueDatasource: () => buildListItemsThingsboardByUniqueDatasource,
|
|
592
597
|
buildMyioIngestionAuth: () => buildMyioIngestionAuth,
|
|
@@ -608,6 +613,7 @@ __export(index_exports, {
|
|
|
608
613
|
createConsumptionChartWidget: () => createConsumptionChartWidget,
|
|
609
614
|
createConsumptionModal: () => createConsumptionModal,
|
|
610
615
|
createDateRangePicker: () => createDateRangePicker2,
|
|
616
|
+
createDistributionChartWidget: () => createDistributionChartWidget,
|
|
611
617
|
createInputDateRangePickerInsideDIV: () => createInputDateRangePickerInsideDIV,
|
|
612
618
|
createModalHeader: () => createModalHeader,
|
|
613
619
|
decodePayload: () => decodePayload,
|
|
@@ -646,11 +652,16 @@ __export(index_exports, {
|
|
|
646
652
|
getAvailableContexts: () => getAvailableContexts,
|
|
647
653
|
getConnectionStatusIcon: () => getConnectionStatusIcon,
|
|
648
654
|
getDateRangeArray: () => getDateRangeArray,
|
|
655
|
+
getDefaultGroupColors: () => getDefaultGroupColors,
|
|
649
656
|
getDeviceStatusIcon: () => getDeviceStatusIcon,
|
|
650
657
|
getDeviceStatusInfo: () => getDeviceStatusInfo,
|
|
658
|
+
getDistributionThemeColors: () => getThemeColors2,
|
|
659
|
+
getGroupColor: () => getGroupColor,
|
|
660
|
+
getHashColor: () => getHashColor,
|
|
651
661
|
getModalHeaderStyles: () => getModalHeaderStyles,
|
|
652
662
|
getSaoPauloISOString: () => getSaoPauloISOString,
|
|
653
663
|
getSaoPauloISOStringFixed: () => getSaoPauloISOStringFixed,
|
|
664
|
+
getShoppingColor: () => getShoppingColor,
|
|
654
665
|
getValueByDatakey: () => getValueByDatakey,
|
|
655
666
|
getValueByDatakeyLegacy: () => getValueByDatakeyLegacy,
|
|
656
667
|
getWaterCategories: () => getWaterCategories,
|
|
@@ -23723,11 +23734,16 @@ function createConsumptionModal(config) {
|
|
|
23723
23734
|
let isMaximized = false;
|
|
23724
23735
|
const domainCfg = DOMAIN_CONFIG3[config.domain] || { name: config.domain, icon: "\u{1F4CA}" };
|
|
23725
23736
|
const title = config.title || `${domainCfg.name} - Hist\xF3rico de Consumo`;
|
|
23726
|
-
function
|
|
23737
|
+
function getThemeColors3() {
|
|
23727
23738
|
return THEME_COLORS[currentTheme];
|
|
23728
23739
|
}
|
|
23740
|
+
const consolidadoIcon = `<svg viewBox="0 0 16 16" fill="currentColor" style="width:14px;height:14px;pointer-events:none"><rect x="3" y="3" width="10" height="10" rx="2"/></svg>`;
|
|
23741
|
+
const porShoppingIcon = `<svg viewBox="0 0 16 16" fill="currentColor" style="width:14px;height:14px;pointer-events:none"><rect x="1" y="1" width="6" height="6" rx="1"/><rect x="9" y="1" width="6" height="6" rx="1"/><rect x="1" y="9" width="6" height="6" rx="1"/><rect x="9" y="9" width="6" height="6" rx="1"/></svg>`;
|
|
23742
|
+
const lineChartIcon = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;pointer-events:none"><polyline points="2,12 5,7 9,9 14,3"/></svg>`;
|
|
23743
|
+
const barChartIcon = `<svg viewBox="0 0 16 16" fill="currentColor" style="width:14px;height:14px;pointer-events:none"><rect x="1" y="9" width="3" height="6" rx="0.5"/><rect x="6" y="5" width="3" height="10" rx="0.5"/><rect x="11" y="7" width="3" height="8" rx="0.5"/></svg>`;
|
|
23744
|
+
const showSettingsButton = config.showSettingsButton ?? true;
|
|
23729
23745
|
function renderModal4() {
|
|
23730
|
-
const colors =
|
|
23746
|
+
const colors = getThemeColors3();
|
|
23731
23747
|
const exportFormats = config.exportFormats || ["csv"];
|
|
23732
23748
|
headerInstance = createModalHeader({
|
|
23733
23749
|
id: modalId,
|
|
@@ -23760,7 +23776,55 @@ function createConsumptionModal(config) {
|
|
|
23760
23776
|
instance.close();
|
|
23761
23777
|
}
|
|
23762
23778
|
});
|
|
23779
|
+
const btnBaseStyle = `
|
|
23780
|
+
display: flex;
|
|
23781
|
+
align-items: center;
|
|
23782
|
+
justify-content: center;
|
|
23783
|
+
gap: 6px;
|
|
23784
|
+
padding: 6px 12px;
|
|
23785
|
+
border: none;
|
|
23786
|
+
border-radius: 6px;
|
|
23787
|
+
font-size: 12px;
|
|
23788
|
+
font-weight: 500;
|
|
23789
|
+
cursor: pointer;
|
|
23790
|
+
transition: all 0.2s;
|
|
23791
|
+
white-space: nowrap;
|
|
23792
|
+
`.replace(/\s+/g, " ").trim();
|
|
23793
|
+
const tabBgColor = currentTheme === "dark" ? "#4b5563" : "#e5e7eb";
|
|
23794
|
+
const activeColor = "#3e1a7d";
|
|
23795
|
+
const inactiveTextColor = colors.text;
|
|
23763
23796
|
return `
|
|
23797
|
+
<style>
|
|
23798
|
+
.myio-modal-tab-btn {
|
|
23799
|
+
${btnBaseStyle}
|
|
23800
|
+
}
|
|
23801
|
+
.myio-modal-tab-btn:hover {
|
|
23802
|
+
opacity: 0.85;
|
|
23803
|
+
}
|
|
23804
|
+
.myio-modal-tab-btn.active {
|
|
23805
|
+
background: ${activeColor} !important;
|
|
23806
|
+
color: white !important;
|
|
23807
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
23808
|
+
}
|
|
23809
|
+
.myio-modal-tab-btn svg {
|
|
23810
|
+
pointer-events: none;
|
|
23811
|
+
}
|
|
23812
|
+
.myio-modal-settings-btn {
|
|
23813
|
+
background: transparent;
|
|
23814
|
+
border: 1px solid ${colors.border};
|
|
23815
|
+
font-size: 16px;
|
|
23816
|
+
cursor: pointer;
|
|
23817
|
+
padding: 6px 10px;
|
|
23818
|
+
border-radius: 6px;
|
|
23819
|
+
transition: all 0.2s;
|
|
23820
|
+
color: ${colors.text};
|
|
23821
|
+
}
|
|
23822
|
+
.myio-modal-settings-btn:hover {
|
|
23823
|
+
background: ${activeColor};
|
|
23824
|
+
border-color: ${activeColor};
|
|
23825
|
+
color: white;
|
|
23826
|
+
}
|
|
23827
|
+
</style>
|
|
23764
23828
|
<div class="myio-consumption-modal-overlay" style="
|
|
23765
23829
|
position: fixed;
|
|
23766
23830
|
top: 0;
|
|
@@ -23791,59 +23855,44 @@ function createConsumptionModal(config) {
|
|
|
23791
23855
|
<!-- Controls Bar -->
|
|
23792
23856
|
<div class="myio-consumption-modal-controls" style="
|
|
23793
23857
|
display: flex;
|
|
23794
|
-
gap:
|
|
23858
|
+
gap: 12px;
|
|
23795
23859
|
padding: 12px 16px;
|
|
23796
23860
|
background: ${currentTheme === "dark" ? "#374151" : "#f7f7f7"};
|
|
23797
23861
|
border-bottom: 1px solid ${colors.border};
|
|
23798
23862
|
align-items: center;
|
|
23799
23863
|
flex-wrap: wrap;
|
|
23800
23864
|
">
|
|
23865
|
+
<!-- Settings Button -->
|
|
23866
|
+
${showSettingsButton ? `
|
|
23867
|
+
<button id="${modalId}-settings-btn" class="myio-modal-settings-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
|
|
23868
|
+
` : ""}
|
|
23869
|
+
|
|
23801
23870
|
<!-- Viz Mode Tabs -->
|
|
23802
|
-
<div style="display: flex; gap: 2px; background: ${
|
|
23803
|
-
<button id="${modalId}-viz-total"
|
|
23804
|
-
|
|
23805
|
-
|
|
23806
|
-
|
|
23807
|
-
|
|
23808
|
-
|
|
23809
|
-
|
|
23810
|
-
background: ${currentVizMode === "
|
|
23811
|
-
|
|
23812
|
-
|
|
23813
|
-
<button id="${modalId}-viz-separate" style="
|
|
23814
|
-
padding: 6px 12px;
|
|
23815
|
-
border: none;
|
|
23816
|
-
border-radius: 6px;
|
|
23817
|
-
font-size: 13px;
|
|
23818
|
-
cursor: pointer;
|
|
23819
|
-
transition: all 0.2s;
|
|
23820
|
-
background: ${currentVizMode === "separate" ? "#3e1a7d" : "transparent"};
|
|
23821
|
-
color: ${currentVizMode === "separate" ? "white" : colors.text};
|
|
23822
|
-
">Por Shopping</button>
|
|
23871
|
+
<div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
|
|
23872
|
+
<button id="${modalId}-viz-total" class="myio-modal-tab-btn ${currentVizMode === "total" ? "active" : ""}"
|
|
23873
|
+
data-viz="total" title="Consolidado"
|
|
23874
|
+
style="background: ${currentVizMode === "total" ? activeColor : "transparent"}; color: ${currentVizMode === "total" ? "white" : inactiveTextColor};">
|
|
23875
|
+
${consolidadoIcon}
|
|
23876
|
+
</button>
|
|
23877
|
+
<button id="${modalId}-viz-separate" class="myio-modal-tab-btn ${currentVizMode === "separate" ? "active" : ""}"
|
|
23878
|
+
data-viz="separate" title="Por Shopping"
|
|
23879
|
+
style="background: ${currentVizMode === "separate" ? activeColor : "transparent"}; color: ${currentVizMode === "separate" ? "white" : inactiveTextColor};">
|
|
23880
|
+
${porShoppingIcon}
|
|
23881
|
+
</button>
|
|
23823
23882
|
</div>
|
|
23824
23883
|
|
|
23825
23884
|
<!-- Chart Type Tabs -->
|
|
23826
|
-
<div style="display: flex; gap: 2px; background: ${
|
|
23827
|
-
<button id="${modalId}-type-line"
|
|
23828
|
-
|
|
23829
|
-
|
|
23830
|
-
|
|
23831
|
-
|
|
23832
|
-
|
|
23833
|
-
|
|
23834
|
-
background: ${currentChartType === "
|
|
23835
|
-
|
|
23836
|
-
|
|
23837
|
-
<button id="${modalId}-type-bar" style="
|
|
23838
|
-
padding: 6px 12px;
|
|
23839
|
-
border: none;
|
|
23840
|
-
border-radius: 6px;
|
|
23841
|
-
font-size: 13px;
|
|
23842
|
-
cursor: pointer;
|
|
23843
|
-
transition: all 0.2s;
|
|
23844
|
-
background: ${currentChartType === "bar" ? "#3e1a7d" : "transparent"};
|
|
23845
|
-
color: ${currentChartType === "bar" ? "white" : colors.text};
|
|
23846
|
-
">Barras</button>
|
|
23885
|
+
<div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
|
|
23886
|
+
<button id="${modalId}-type-line" class="myio-modal-tab-btn ${currentChartType === "line" ? "active" : ""}"
|
|
23887
|
+
data-type="line" title="Gr\xE1fico de Linhas"
|
|
23888
|
+
style="background: ${currentChartType === "line" ? activeColor : "transparent"}; color: ${currentChartType === "line" ? "white" : inactiveTextColor};">
|
|
23889
|
+
${lineChartIcon}
|
|
23890
|
+
</button>
|
|
23891
|
+
<button id="${modalId}-type-bar" class="myio-modal-tab-btn ${currentChartType === "bar" ? "active" : ""}"
|
|
23892
|
+
data-type="bar" title="Gr\xE1fico de Barras"
|
|
23893
|
+
style="background: ${currentChartType === "bar" ? activeColor : "transparent"}; color: ${currentChartType === "bar" ? "white" : inactiveTextColor};">
|
|
23894
|
+
${barChartIcon}
|
|
23895
|
+
</button>
|
|
23847
23896
|
</div>
|
|
23848
23897
|
</div>
|
|
23849
23898
|
|
|
@@ -23864,6 +23913,11 @@ function createConsumptionModal(config) {
|
|
|
23864
23913
|
function setupListeners() {
|
|
23865
23914
|
if (!modalElement) return;
|
|
23866
23915
|
headerInstance?.attachListeners();
|
|
23916
|
+
if (showSettingsButton) {
|
|
23917
|
+
document.getElementById(`${modalId}-settings-btn`)?.addEventListener("click", () => {
|
|
23918
|
+
config.onSettingsClick?.();
|
|
23919
|
+
});
|
|
23920
|
+
}
|
|
23867
23921
|
document.getElementById(`${modalId}-viz-total`)?.addEventListener("click", () => {
|
|
23868
23922
|
currentVizMode = "total";
|
|
23869
23923
|
chartInstance?.setVizMode("total");
|
|
@@ -23898,25 +23952,30 @@ function createConsumptionModal(config) {
|
|
|
23898
23952
|
modalElement.__handleKeydown = handleKeydown;
|
|
23899
23953
|
}
|
|
23900
23954
|
function updateControlStyles() {
|
|
23901
|
-
const colors =
|
|
23955
|
+
const colors = getThemeColors3();
|
|
23956
|
+
const activeColor = "#3e1a7d";
|
|
23902
23957
|
const vizTotalBtn = document.getElementById(`${modalId}-viz-total`);
|
|
23903
23958
|
const vizSeparateBtn = document.getElementById(`${modalId}-viz-separate`);
|
|
23904
23959
|
if (vizTotalBtn) {
|
|
23905
|
-
vizTotalBtn.
|
|
23960
|
+
vizTotalBtn.classList.toggle("active", currentVizMode === "total");
|
|
23961
|
+
vizTotalBtn.style.background = currentVizMode === "total" ? activeColor : "transparent";
|
|
23906
23962
|
vizTotalBtn.style.color = currentVizMode === "total" ? "white" : colors.text;
|
|
23907
23963
|
}
|
|
23908
23964
|
if (vizSeparateBtn) {
|
|
23909
|
-
vizSeparateBtn.
|
|
23965
|
+
vizSeparateBtn.classList.toggle("active", currentVizMode === "separate");
|
|
23966
|
+
vizSeparateBtn.style.background = currentVizMode === "separate" ? activeColor : "transparent";
|
|
23910
23967
|
vizSeparateBtn.style.color = currentVizMode === "separate" ? "white" : colors.text;
|
|
23911
23968
|
}
|
|
23912
23969
|
const typeLineBtn = document.getElementById(`${modalId}-type-line`);
|
|
23913
23970
|
const typeBarBtn = document.getElementById(`${modalId}-type-bar`);
|
|
23914
23971
|
if (typeLineBtn) {
|
|
23915
|
-
typeLineBtn.
|
|
23972
|
+
typeLineBtn.classList.toggle("active", currentChartType === "line");
|
|
23973
|
+
typeLineBtn.style.background = currentChartType === "line" ? activeColor : "transparent";
|
|
23916
23974
|
typeLineBtn.style.color = currentChartType === "line" ? "white" : colors.text;
|
|
23917
23975
|
}
|
|
23918
23976
|
if (typeBarBtn) {
|
|
23919
|
-
typeBarBtn.
|
|
23977
|
+
typeBarBtn.classList.toggle("active", currentChartType === "bar");
|
|
23978
|
+
typeBarBtn.style.background = currentChartType === "bar" ? activeColor : "transparent";
|
|
23920
23979
|
typeBarBtn.style.color = currentChartType === "bar" ? "white" : colors.text;
|
|
23921
23980
|
}
|
|
23922
23981
|
}
|
|
@@ -25816,6 +25875,581 @@ var EXPORT_DEFAULT_COLORS = DEFAULT_COLORS4;
|
|
|
25816
25875
|
var EXPORT_DOMAIN_ICONS = DOMAIN_ICONS;
|
|
25817
25876
|
var EXPORT_DOMAIN_LABELS = DOMAIN_LABELS;
|
|
25818
25877
|
var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
25878
|
+
|
|
25879
|
+
// src/components/DistributionChart/colorManager.ts
|
|
25880
|
+
var DEFAULT_SHOPPING_COLORS = [
|
|
25881
|
+
"#3b82f6",
|
|
25882
|
+
// Blue
|
|
25883
|
+
"#8b5cf6",
|
|
25884
|
+
// Purple
|
|
25885
|
+
"#f59e0b",
|
|
25886
|
+
// Amber
|
|
25887
|
+
"#ef4444",
|
|
25888
|
+
// Red
|
|
25889
|
+
"#10b981",
|
|
25890
|
+
// Emerald
|
|
25891
|
+
"#06b6d4",
|
|
25892
|
+
// Cyan
|
|
25893
|
+
"#ec4899",
|
|
25894
|
+
// Pink
|
|
25895
|
+
"#14b8a6",
|
|
25896
|
+
// Teal
|
|
25897
|
+
"#f97316",
|
|
25898
|
+
// Orange
|
|
25899
|
+
"#a855f7"
|
|
25900
|
+
// Violet
|
|
25901
|
+
];
|
|
25902
|
+
var DEFAULT_ENERGY_GROUP_COLORS = {
|
|
25903
|
+
"Elevadores": "#3b82f6",
|
|
25904
|
+
"Escadas Rolantes": "#8b5cf6",
|
|
25905
|
+
"Climatiza\xE7\xE3o": "#f59e0b",
|
|
25906
|
+
"Climatizacao": "#f59e0b",
|
|
25907
|
+
// Without accent
|
|
25908
|
+
"Outros Equipamentos": "#ef4444",
|
|
25909
|
+
"Lojas": "#10b981"
|
|
25910
|
+
};
|
|
25911
|
+
var DEFAULT_WATER_GROUP_COLORS = {
|
|
25912
|
+
"Lojas": "#10b981",
|
|
25913
|
+
"\xC1rea Comum": "#0288d1",
|
|
25914
|
+
"Area Comum": "#0288d1"
|
|
25915
|
+
// Without accent
|
|
25916
|
+
};
|
|
25917
|
+
var DEFAULT_GAS_GROUP_COLORS = {
|
|
25918
|
+
"Cozinha": "#f59e0b",
|
|
25919
|
+
"Aquecimento": "#ef4444",
|
|
25920
|
+
"Outros": "#94a3b8"
|
|
25921
|
+
};
|
|
25922
|
+
function getDefaultGroupColors(domain) {
|
|
25923
|
+
switch (domain.toLowerCase()) {
|
|
25924
|
+
case "energy":
|
|
25925
|
+
return DEFAULT_ENERGY_GROUP_COLORS;
|
|
25926
|
+
case "water":
|
|
25927
|
+
return DEFAULT_WATER_GROUP_COLORS;
|
|
25928
|
+
case "gas":
|
|
25929
|
+
return DEFAULT_GAS_GROUP_COLORS;
|
|
25930
|
+
default:
|
|
25931
|
+
return DEFAULT_ENERGY_GROUP_COLORS;
|
|
25932
|
+
}
|
|
25933
|
+
}
|
|
25934
|
+
function assignShoppingColors(shoppingIds) {
|
|
25935
|
+
const colors = {};
|
|
25936
|
+
shoppingIds.forEach((id, index) => {
|
|
25937
|
+
colors[id] = DEFAULT_SHOPPING_COLORS[index % DEFAULT_SHOPPING_COLORS.length];
|
|
25938
|
+
});
|
|
25939
|
+
return colors;
|
|
25940
|
+
}
|
|
25941
|
+
function getShoppingColor(shoppingId, shoppingColors, fallbackIndex = 0) {
|
|
25942
|
+
if (shoppingColors && shoppingColors[shoppingId]) {
|
|
25943
|
+
return shoppingColors[shoppingId];
|
|
25944
|
+
}
|
|
25945
|
+
if (shoppingColors) {
|
|
25946
|
+
const normalizedId = shoppingId.toLowerCase();
|
|
25947
|
+
for (const [key, color] of Object.entries(shoppingColors)) {
|
|
25948
|
+
if (key.toLowerCase() === normalizedId || key.toLowerCase().includes(normalizedId)) {
|
|
25949
|
+
return color;
|
|
25950
|
+
}
|
|
25951
|
+
}
|
|
25952
|
+
}
|
|
25953
|
+
return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
|
|
25954
|
+
}
|
|
25955
|
+
function getGroupColor(groupName, groupColors, domain = "energy", fallbackIndex = 0) {
|
|
25956
|
+
if (groupColors && groupColors[groupName]) {
|
|
25957
|
+
return groupColors[groupName];
|
|
25958
|
+
}
|
|
25959
|
+
const defaultColors = getDefaultGroupColors(domain);
|
|
25960
|
+
if (defaultColors[groupName]) {
|
|
25961
|
+
return defaultColors[groupName];
|
|
25962
|
+
}
|
|
25963
|
+
return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
|
|
25964
|
+
}
|
|
25965
|
+
function getThemeColors2(theme) {
|
|
25966
|
+
if (theme === "dark") {
|
|
25967
|
+
return {
|
|
25968
|
+
text: "#f3f4f6",
|
|
25969
|
+
secondaryText: "#9ca3af",
|
|
25970
|
+
background: "#111827",
|
|
25971
|
+
cardBackground: "#1f2937",
|
|
25972
|
+
border: "#374151",
|
|
25973
|
+
grid: "#374151"
|
|
25974
|
+
};
|
|
25975
|
+
}
|
|
25976
|
+
return {
|
|
25977
|
+
text: "#1f2937",
|
|
25978
|
+
secondaryText: "#6b7280",
|
|
25979
|
+
background: "#f5f5f5",
|
|
25980
|
+
cardBackground: "#ffffff",
|
|
25981
|
+
border: "#e5e7eb",
|
|
25982
|
+
grid: "#e5e7eb"
|
|
25983
|
+
};
|
|
25984
|
+
}
|
|
25985
|
+
function getHashColor(str) {
|
|
25986
|
+
let hash = 0;
|
|
25987
|
+
for (let i = 0; i < str.length; i++) {
|
|
25988
|
+
const char = str.charCodeAt(i);
|
|
25989
|
+
hash = (hash << 5) - hash + char;
|
|
25990
|
+
hash = hash & hash;
|
|
25991
|
+
}
|
|
25992
|
+
return DEFAULT_SHOPPING_COLORS[Math.abs(hash) % DEFAULT_SHOPPING_COLORS.length];
|
|
25993
|
+
}
|
|
25994
|
+
|
|
25995
|
+
// src/components/DistributionChart/createDistributionChartWidget.ts
|
|
25996
|
+
var settingsIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:16px;height:16px;pointer-events:none"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>`;
|
|
25997
|
+
var maximizeIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:16px;height:16px;pointer-events:none"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>`;
|
|
25998
|
+
function createDistributionChartWidget(config) {
|
|
25999
|
+
const widgetId = `distribution-${config.domain}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
26000
|
+
let chartInstance = null;
|
|
26001
|
+
let currentMode = config.defaultMode || "groups";
|
|
26002
|
+
let currentTheme = config.theme || "light";
|
|
26003
|
+
let currentData = null;
|
|
26004
|
+
let containerElement = null;
|
|
26005
|
+
let isLoading = false;
|
|
26006
|
+
const title = config.title || getDomainTitle(config.domain);
|
|
26007
|
+
const chartHeight = config.chartHeight || 300;
|
|
26008
|
+
const showHeader = config.showHeader !== false;
|
|
26009
|
+
const showModeSelector = config.showModeSelector !== false;
|
|
26010
|
+
const showSettingsButton = config.showSettingsButton ?? false;
|
|
26011
|
+
const showMaximizeButton = config.showMaximizeButton ?? false;
|
|
26012
|
+
const decimalPlaces = config.decimalPlaces ?? 2;
|
|
26013
|
+
const modes = config.modes || getDefaultModes(config.domain);
|
|
26014
|
+
const groupColors = config.groupColors || getDefaultGroupColors(config.domain);
|
|
26015
|
+
function getDomainTitle(domain) {
|
|
26016
|
+
const titles = {
|
|
26017
|
+
energy: "Distribui\xE7\xE3o de Energia",
|
|
26018
|
+
water: "Distribui\xE7\xE3o de \xC1gua",
|
|
26019
|
+
gas: "Distribui\xE7\xE3o de G\xE1s",
|
|
26020
|
+
temperature: "Distribui\xE7\xE3o de Temperatura"
|
|
26021
|
+
};
|
|
26022
|
+
return titles[domain.toLowerCase()] || `Distribui\xE7\xE3o de ${domain}`;
|
|
26023
|
+
}
|
|
26024
|
+
function getDefaultModes(domain) {
|
|
26025
|
+
if (domain === "water") {
|
|
26026
|
+
return [
|
|
26027
|
+
{ value: "groups", label: "Lojas vs \xC1rea Comum" },
|
|
26028
|
+
{ value: "stores", label: "Lojas por Shopping" },
|
|
26029
|
+
{ value: "common", label: "\xC1rea Comum por Shopping" }
|
|
26030
|
+
];
|
|
26031
|
+
}
|
|
26032
|
+
return [
|
|
26033
|
+
{ value: "groups", label: "Por Grupos de Equipamentos" },
|
|
26034
|
+
{ value: "elevators", label: "Elevadores por Shopping" },
|
|
26035
|
+
{ value: "escalators", label: "Escadas Rolantes por Shopping" },
|
|
26036
|
+
{ value: "hvac", label: "Climatiza\xE7\xE3o por Shopping" },
|
|
26037
|
+
{ value: "others", label: "Outros Equipamentos por Shopping" },
|
|
26038
|
+
{ value: "stores", label: "Lojas por Shopping" }
|
|
26039
|
+
];
|
|
26040
|
+
}
|
|
26041
|
+
function $id(id) {
|
|
26042
|
+
if (config.$container) {
|
|
26043
|
+
return config.$container[0].querySelector(`#${id}`);
|
|
26044
|
+
}
|
|
26045
|
+
return document.getElementById(id);
|
|
26046
|
+
}
|
|
26047
|
+
function formatValue(value) {
|
|
26048
|
+
if (config.unitLarge && config.thresholdForLargeUnit && value >= config.thresholdForLargeUnit) {
|
|
26049
|
+
return `${(value / config.thresholdForLargeUnit).toFixed(decimalPlaces)} ${config.unitLarge}`;
|
|
26050
|
+
}
|
|
26051
|
+
return `${value.toFixed(decimalPlaces)} ${config.unit}`;
|
|
26052
|
+
}
|
|
26053
|
+
function getColor(key, index, isGroupMode2) {
|
|
26054
|
+
if (isGroupMode2) {
|
|
26055
|
+
return getGroupColor(key, groupColors, config.domain, index);
|
|
26056
|
+
}
|
|
26057
|
+
const shoppingColors = config.getShoppingColors?.();
|
|
26058
|
+
return getShoppingColor(key, shoppingColors, index);
|
|
26059
|
+
}
|
|
26060
|
+
function getColors2() {
|
|
26061
|
+
return getThemeColors2(currentTheme);
|
|
26062
|
+
}
|
|
26063
|
+
function isGroupMode() {
|
|
26064
|
+
return currentMode === "groups";
|
|
26065
|
+
}
|
|
26066
|
+
function renderHTML() {
|
|
26067
|
+
const colors = getColors2();
|
|
26068
|
+
const modeOptions = modes.map(
|
|
26069
|
+
(m) => `<option value="${m.value}" ${m.value === currentMode ? "selected" : ""}>${m.label}</option>`
|
|
26070
|
+
).join("");
|
|
26071
|
+
const headerButtons = [];
|
|
26072
|
+
if (showSettingsButton) {
|
|
26073
|
+
headerButtons.push(`
|
|
26074
|
+
<button id="${widgetId}-settings-btn" class="myio-dist-btn" title="Configura\xE7\xF5es">
|
|
26075
|
+
${settingsIcon}
|
|
26076
|
+
</button>
|
|
26077
|
+
`);
|
|
26078
|
+
}
|
|
26079
|
+
if (showMaximizeButton) {
|
|
26080
|
+
headerButtons.push(`
|
|
26081
|
+
<button id="${widgetId}-maximize-btn" class="myio-dist-btn" title="Expandir">
|
|
26082
|
+
${maximizeIcon}
|
|
26083
|
+
</button>
|
|
26084
|
+
`);
|
|
26085
|
+
}
|
|
26086
|
+
return `
|
|
26087
|
+
<style>
|
|
26088
|
+
#${widgetId} {
|
|
26089
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
26090
|
+
}
|
|
26091
|
+
#${widgetId} .myio-dist-header {
|
|
26092
|
+
display: flex;
|
|
26093
|
+
justify-content: space-between;
|
|
26094
|
+
align-items: center;
|
|
26095
|
+
margin-bottom: 16px;
|
|
26096
|
+
flex-wrap: wrap;
|
|
26097
|
+
gap: 12px;
|
|
26098
|
+
}
|
|
26099
|
+
#${widgetId} .myio-dist-title {
|
|
26100
|
+
margin: 0;
|
|
26101
|
+
font-size: 16px;
|
|
26102
|
+
font-weight: 600;
|
|
26103
|
+
color: ${colors.text};
|
|
26104
|
+
}
|
|
26105
|
+
#${widgetId} .myio-dist-controls {
|
|
26106
|
+
display: flex;
|
|
26107
|
+
align-items: center;
|
|
26108
|
+
gap: 8px;
|
|
26109
|
+
}
|
|
26110
|
+
#${widgetId} .myio-dist-label {
|
|
26111
|
+
font-size: 12px;
|
|
26112
|
+
color: ${colors.secondaryText};
|
|
26113
|
+
}
|
|
26114
|
+
#${widgetId} .myio-dist-select {
|
|
26115
|
+
padding: 6px 10px;
|
|
26116
|
+
border-radius: 6px;
|
|
26117
|
+
border: 1px solid ${colors.border};
|
|
26118
|
+
background: ${colors.cardBackground};
|
|
26119
|
+
color: ${colors.text};
|
|
26120
|
+
font-size: 12px;
|
|
26121
|
+
cursor: pointer;
|
|
26122
|
+
min-width: 180px;
|
|
26123
|
+
}
|
|
26124
|
+
#${widgetId} .myio-dist-select:focus {
|
|
26125
|
+
outline: none;
|
|
26126
|
+
border-color: #3e1a7d;
|
|
26127
|
+
}
|
|
26128
|
+
#${widgetId} .myio-dist-btn {
|
|
26129
|
+
display: flex;
|
|
26130
|
+
align-items: center;
|
|
26131
|
+
justify-content: center;
|
|
26132
|
+
padding: 6px 8px;
|
|
26133
|
+
border: 1px solid ${colors.border};
|
|
26134
|
+
border-radius: 6px;
|
|
26135
|
+
background: transparent;
|
|
26136
|
+
color: ${colors.text};
|
|
26137
|
+
cursor: pointer;
|
|
26138
|
+
transition: all 0.2s;
|
|
26139
|
+
}
|
|
26140
|
+
#${widgetId} .myio-dist-btn:hover {
|
|
26141
|
+
background: #3e1a7d;
|
|
26142
|
+
border-color: #3e1a7d;
|
|
26143
|
+
color: white;
|
|
26144
|
+
}
|
|
26145
|
+
#${widgetId} .myio-dist-chart-container {
|
|
26146
|
+
position: relative;
|
|
26147
|
+
height: ${chartHeight}px;
|
|
26148
|
+
}
|
|
26149
|
+
#${widgetId} .myio-dist-loading {
|
|
26150
|
+
position: absolute;
|
|
26151
|
+
top: 0;
|
|
26152
|
+
left: 0;
|
|
26153
|
+
right: 0;
|
|
26154
|
+
bottom: 0;
|
|
26155
|
+
display: flex;
|
|
26156
|
+
align-items: center;
|
|
26157
|
+
justify-content: center;
|
|
26158
|
+
background: ${colors.cardBackground}ee;
|
|
26159
|
+
z-index: 10;
|
|
26160
|
+
}
|
|
26161
|
+
#${widgetId} .myio-dist-spinner {
|
|
26162
|
+
width: 32px;
|
|
26163
|
+
height: 32px;
|
|
26164
|
+
border: 3px solid ${colors.border};
|
|
26165
|
+
border-top-color: #3e1a7d;
|
|
26166
|
+
border-radius: 50%;
|
|
26167
|
+
animation: myio-dist-spin 0.8s linear infinite;
|
|
26168
|
+
}
|
|
26169
|
+
@keyframes myio-dist-spin {
|
|
26170
|
+
to { transform: rotate(360deg); }
|
|
26171
|
+
}
|
|
26172
|
+
#${widgetId} .myio-dist-empty {
|
|
26173
|
+
display: flex;
|
|
26174
|
+
flex-direction: column;
|
|
26175
|
+
align-items: center;
|
|
26176
|
+
justify-content: center;
|
|
26177
|
+
height: 100%;
|
|
26178
|
+
color: ${colors.secondaryText};
|
|
26179
|
+
font-size: 14px;
|
|
26180
|
+
}
|
|
26181
|
+
#${widgetId} .myio-dist-empty-icon {
|
|
26182
|
+
font-size: 48px;
|
|
26183
|
+
margin-bottom: 12px;
|
|
26184
|
+
opacity: 0.5;
|
|
26185
|
+
}
|
|
26186
|
+
</style>
|
|
26187
|
+
|
|
26188
|
+
<div id="${widgetId}" class="myio-distribution-widget" style="
|
|
26189
|
+
background: ${colors.cardBackground};
|
|
26190
|
+
border-radius: 12px;
|
|
26191
|
+
padding: 16px;
|
|
26192
|
+
height: 100%;
|
|
26193
|
+
display: flex;
|
|
26194
|
+
flex-direction: column;
|
|
26195
|
+
">
|
|
26196
|
+
${showHeader ? `
|
|
26197
|
+
<div class="myio-dist-header">
|
|
26198
|
+
<h4 class="myio-dist-title">${title}</h4>
|
|
26199
|
+
<div class="myio-dist-controls">
|
|
26200
|
+
${showModeSelector && modes.length > 1 ? `
|
|
26201
|
+
<label for="${widgetId}-mode" class="myio-dist-label">Visualizar:</label>
|
|
26202
|
+
<select id="${widgetId}-mode" class="myio-dist-select">
|
|
26203
|
+
${modeOptions}
|
|
26204
|
+
</select>
|
|
26205
|
+
` : ""}
|
|
26206
|
+
${headerButtons.join("")}
|
|
26207
|
+
</div>
|
|
26208
|
+
</div>
|
|
26209
|
+
` : ""}
|
|
26210
|
+
|
|
26211
|
+
<div class="myio-dist-chart-container">
|
|
26212
|
+
<canvas id="${widgetId}-canvas"></canvas>
|
|
26213
|
+
<div id="${widgetId}-loading" class="myio-dist-loading" style="display: none;">
|
|
26214
|
+
<div class="myio-dist-spinner"></div>
|
|
26215
|
+
</div>
|
|
26216
|
+
</div>
|
|
26217
|
+
</div>
|
|
26218
|
+
`;
|
|
26219
|
+
}
|
|
26220
|
+
function setLoading(loading) {
|
|
26221
|
+
isLoading = loading;
|
|
26222
|
+
const loadingEl = $id(`${widgetId}-loading`);
|
|
26223
|
+
if (loadingEl) {
|
|
26224
|
+
loadingEl.style.display = loading ? "flex" : "none";
|
|
26225
|
+
}
|
|
26226
|
+
}
|
|
26227
|
+
function buildChartData(distribution) {
|
|
26228
|
+
const labels = [];
|
|
26229
|
+
const data = [];
|
|
26230
|
+
const backgroundColors = [];
|
|
26231
|
+
const total = Object.values(distribution).reduce((sum, val) => sum + val, 0);
|
|
26232
|
+
const isGroup = isGroupMode();
|
|
26233
|
+
const entries = Object.entries(distribution).filter(([_, value]) => value > 0).sort((a, b) => b[1] - a[1]);
|
|
26234
|
+
entries.forEach(([key, value], index) => {
|
|
26235
|
+
const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
|
|
26236
|
+
labels.push(`${key} (${formatValue(value)} - ${percentage}%)`);
|
|
26237
|
+
data.push(value);
|
|
26238
|
+
backgroundColors.push(getColor(key, index, isGroup));
|
|
26239
|
+
});
|
|
26240
|
+
return { labels, data, backgroundColors, total };
|
|
26241
|
+
}
|
|
26242
|
+
function renderEmptyState() {
|
|
26243
|
+
const container = $id(`${widgetId}-canvas`)?.parentElement;
|
|
26244
|
+
if (container) {
|
|
26245
|
+
const emptyEl = document.createElement("div");
|
|
26246
|
+
emptyEl.className = "myio-dist-empty";
|
|
26247
|
+
emptyEl.innerHTML = `
|
|
26248
|
+
<div class="myio-dist-empty-icon">\u{1F4CA}</div>
|
|
26249
|
+
<div>Sem dados dispon\xEDveis</div>
|
|
26250
|
+
`;
|
|
26251
|
+
const canvas = $id(`${widgetId}-canvas`);
|
|
26252
|
+
if (canvas) canvas.style.display = "none";
|
|
26253
|
+
const existingEmpty = container.querySelector(".myio-dist-empty");
|
|
26254
|
+
if (!existingEmpty) {
|
|
26255
|
+
container.appendChild(emptyEl);
|
|
26256
|
+
}
|
|
26257
|
+
}
|
|
26258
|
+
}
|
|
26259
|
+
function removeEmptyState() {
|
|
26260
|
+
const container = $id(`${widgetId}-canvas`)?.parentElement;
|
|
26261
|
+
if (container) {
|
|
26262
|
+
const emptyEl = container.querySelector(".myio-dist-empty");
|
|
26263
|
+
if (emptyEl) emptyEl.remove();
|
|
26264
|
+
const canvas = $id(`${widgetId}-canvas`);
|
|
26265
|
+
if (canvas) canvas.style.display = "block";
|
|
26266
|
+
}
|
|
26267
|
+
}
|
|
26268
|
+
async function updateChart() {
|
|
26269
|
+
const canvas = $id(`${widgetId}-canvas`);
|
|
26270
|
+
if (!canvas) {
|
|
26271
|
+
console.error(`[${config.domain.toUpperCase()}] Distribution canvas not found`);
|
|
26272
|
+
return;
|
|
26273
|
+
}
|
|
26274
|
+
setLoading(true);
|
|
26275
|
+
try {
|
|
26276
|
+
const distribution = await config.fetchDistribution(currentMode);
|
|
26277
|
+
if (!distribution || Object.keys(distribution).length === 0) {
|
|
26278
|
+
console.warn(`[${config.domain.toUpperCase()}] No distribution data for mode: ${currentMode}`);
|
|
26279
|
+
currentData = null;
|
|
26280
|
+
setLoading(false);
|
|
26281
|
+
renderEmptyState();
|
|
26282
|
+
return;
|
|
26283
|
+
}
|
|
26284
|
+
removeEmptyState();
|
|
26285
|
+
currentData = distribution;
|
|
26286
|
+
const { labels, data, backgroundColors, total } = buildChartData(distribution);
|
|
26287
|
+
const colors = getColors2();
|
|
26288
|
+
const Chart2 = window.Chart;
|
|
26289
|
+
if (!Chart2) {
|
|
26290
|
+
throw new Error("Chart.js not loaded");
|
|
26291
|
+
}
|
|
26292
|
+
if (chartInstance) {
|
|
26293
|
+
chartInstance.destroy();
|
|
26294
|
+
chartInstance = null;
|
|
26295
|
+
}
|
|
26296
|
+
const ctx = canvas.getContext("2d");
|
|
26297
|
+
if (!ctx) {
|
|
26298
|
+
throw new Error("Could not get canvas context");
|
|
26299
|
+
}
|
|
26300
|
+
chartInstance = new Chart2(ctx, {
|
|
26301
|
+
type: "bar",
|
|
26302
|
+
data: {
|
|
26303
|
+
labels,
|
|
26304
|
+
datasets: [
|
|
26305
|
+
{
|
|
26306
|
+
label: `Consumo (${config.unit})`,
|
|
26307
|
+
data,
|
|
26308
|
+
backgroundColor: backgroundColors
|
|
26309
|
+
}
|
|
26310
|
+
]
|
|
26311
|
+
},
|
|
26312
|
+
options: {
|
|
26313
|
+
responsive: true,
|
|
26314
|
+
maintainAspectRatio: false,
|
|
26315
|
+
indexAxis: "y",
|
|
26316
|
+
// Horizontal bar chart
|
|
26317
|
+
animation: false,
|
|
26318
|
+
plugins: {
|
|
26319
|
+
legend: { display: false },
|
|
26320
|
+
tooltip: {
|
|
26321
|
+
callbacks: {
|
|
26322
|
+
label: (context) => {
|
|
26323
|
+
const value = context.parsed.x || 0;
|
|
26324
|
+
const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
|
|
26325
|
+
return `${formatValue(value)} (${percentage}%)`;
|
|
26326
|
+
}
|
|
26327
|
+
}
|
|
26328
|
+
}
|
|
26329
|
+
},
|
|
26330
|
+
scales: {
|
|
26331
|
+
x: {
|
|
26332
|
+
beginAtZero: true,
|
|
26333
|
+
ticks: {
|
|
26334
|
+
callback: (value) => formatValue(Number(value)),
|
|
26335
|
+
color: colors.secondaryText,
|
|
26336
|
+
font: { size: 11 }
|
|
26337
|
+
},
|
|
26338
|
+
grid: { color: colors.grid }
|
|
26339
|
+
},
|
|
26340
|
+
y: {
|
|
26341
|
+
ticks: {
|
|
26342
|
+
font: { size: 11 },
|
|
26343
|
+
color: colors.text
|
|
26344
|
+
},
|
|
26345
|
+
grid: { display: false }
|
|
26346
|
+
}
|
|
26347
|
+
}
|
|
26348
|
+
}
|
|
26349
|
+
});
|
|
26350
|
+
config.onDataLoaded?.(distribution);
|
|
26351
|
+
console.log(`[${config.domain.toUpperCase()}] Distribution chart updated for mode: ${currentMode}`);
|
|
26352
|
+
} catch (error) {
|
|
26353
|
+
console.error(`[${config.domain.toUpperCase()}] Error updating distribution chart:`, error);
|
|
26354
|
+
config.onError?.(error);
|
|
26355
|
+
renderEmptyState();
|
|
26356
|
+
} finally {
|
|
26357
|
+
setLoading(false);
|
|
26358
|
+
}
|
|
26359
|
+
}
|
|
26360
|
+
function setupListeners() {
|
|
26361
|
+
const modeSelect = $id(`${widgetId}-mode`);
|
|
26362
|
+
if (modeSelect) {
|
|
26363
|
+
modeSelect.addEventListener("change", async (e) => {
|
|
26364
|
+
currentMode = e.target.value;
|
|
26365
|
+
config.onModeChange?.(currentMode);
|
|
26366
|
+
await updateChart();
|
|
26367
|
+
});
|
|
26368
|
+
}
|
|
26369
|
+
if (showSettingsButton) {
|
|
26370
|
+
const settingsBtn = $id(`${widgetId}-settings-btn`);
|
|
26371
|
+
if (settingsBtn) {
|
|
26372
|
+
settingsBtn.addEventListener("click", () => {
|
|
26373
|
+
config.onSettingsClick?.();
|
|
26374
|
+
});
|
|
26375
|
+
}
|
|
26376
|
+
}
|
|
26377
|
+
if (showMaximizeButton) {
|
|
26378
|
+
const maximizeBtn = $id(`${widgetId}-maximize-btn`);
|
|
26379
|
+
if (maximizeBtn) {
|
|
26380
|
+
maximizeBtn.addEventListener("click", () => {
|
|
26381
|
+
config.onMaximizeClick?.();
|
|
26382
|
+
});
|
|
26383
|
+
}
|
|
26384
|
+
}
|
|
26385
|
+
}
|
|
26386
|
+
function updateThemeStyles() {
|
|
26387
|
+
const colors = getColors2();
|
|
26388
|
+
const widget = $id(widgetId);
|
|
26389
|
+
if (widget) {
|
|
26390
|
+
widget.style.background = colors.cardBackground;
|
|
26391
|
+
const title2 = widget.querySelector(".myio-dist-title");
|
|
26392
|
+
if (title2) title2.style.color = colors.text;
|
|
26393
|
+
const labels = widget.querySelectorAll(".myio-dist-label");
|
|
26394
|
+
labels.forEach((l) => l.style.color = colors.secondaryText);
|
|
26395
|
+
const select = widget.querySelector(".myio-dist-select");
|
|
26396
|
+
if (select) {
|
|
26397
|
+
select.style.background = colors.cardBackground;
|
|
26398
|
+
select.style.color = colors.text;
|
|
26399
|
+
select.style.borderColor = colors.border;
|
|
26400
|
+
}
|
|
26401
|
+
const buttons = widget.querySelectorAll(".myio-dist-btn");
|
|
26402
|
+
buttons.forEach((b) => {
|
|
26403
|
+
b.style.color = colors.text;
|
|
26404
|
+
b.style.borderColor = colors.border;
|
|
26405
|
+
});
|
|
26406
|
+
}
|
|
26407
|
+
}
|
|
26408
|
+
const instance = {
|
|
26409
|
+
async render() {
|
|
26410
|
+
containerElement = $id(config.containerId);
|
|
26411
|
+
if (!containerElement) {
|
|
26412
|
+
throw new Error(`Container #${config.containerId} not found`);
|
|
26413
|
+
}
|
|
26414
|
+
containerElement.innerHTML = renderHTML();
|
|
26415
|
+
setupListeners();
|
|
26416
|
+
await updateChart();
|
|
26417
|
+
},
|
|
26418
|
+
async setMode(mode) {
|
|
26419
|
+
currentMode = mode;
|
|
26420
|
+
const modeSelect = $id(`${widgetId}-mode`);
|
|
26421
|
+
if (modeSelect) {
|
|
26422
|
+
modeSelect.value = mode;
|
|
26423
|
+
}
|
|
26424
|
+
config.onModeChange?.(mode);
|
|
26425
|
+
await updateChart();
|
|
26426
|
+
},
|
|
26427
|
+
async refresh() {
|
|
26428
|
+
await updateChart();
|
|
26429
|
+
},
|
|
26430
|
+
setTheme(theme) {
|
|
26431
|
+
currentTheme = theme;
|
|
26432
|
+
updateThemeStyles();
|
|
26433
|
+
if (currentData) {
|
|
26434
|
+
updateChart();
|
|
26435
|
+
}
|
|
26436
|
+
},
|
|
26437
|
+
destroy() {
|
|
26438
|
+
if (chartInstance) {
|
|
26439
|
+
chartInstance.destroy();
|
|
26440
|
+
chartInstance = null;
|
|
26441
|
+
}
|
|
26442
|
+
if (containerElement) {
|
|
26443
|
+
containerElement.innerHTML = "";
|
|
26444
|
+
}
|
|
26445
|
+
currentData = null;
|
|
26446
|
+
},
|
|
26447
|
+
getChartInstance: () => chartInstance,
|
|
26448
|
+
getCurrentMode: () => currentMode,
|
|
26449
|
+
getCurrentData: () => currentData
|
|
26450
|
+
};
|
|
26451
|
+
return instance;
|
|
26452
|
+
}
|
|
25819
26453
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25820
26454
|
0 && (module.exports = {
|
|
25821
26455
|
CHART_COLORS,
|
|
@@ -25824,6 +26458,10 @@ var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
|
25824
26458
|
CONSUMPTION_THEME_COLORS,
|
|
25825
26459
|
ConnectionStatusType,
|
|
25826
26460
|
DEFAULT_CLAMP_RANGE,
|
|
26461
|
+
DEFAULT_ENERGY_GROUP_COLORS,
|
|
26462
|
+
DEFAULT_GAS_GROUP_COLORS,
|
|
26463
|
+
DEFAULT_SHOPPING_COLORS,
|
|
26464
|
+
DEFAULT_WATER_GROUP_COLORS,
|
|
25827
26465
|
DeviceStatusType,
|
|
25828
26466
|
EXPORT_DEFAULT_COLORS,
|
|
25829
26467
|
EXPORT_DOMAIN_ICONS,
|
|
@@ -25837,6 +26475,7 @@ var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
|
25837
26475
|
addDetectionContext,
|
|
25838
26476
|
addNamespace,
|
|
25839
26477
|
aggregateByDay,
|
|
26478
|
+
assignShoppingColors,
|
|
25840
26479
|
averageByDay,
|
|
25841
26480
|
buildListItemsThingsboardByUniqueDatasource,
|
|
25842
26481
|
buildMyioIngestionAuth,
|
|
@@ -25858,6 +26497,7 @@ var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
|
25858
26497
|
createConsumptionChartWidget,
|
|
25859
26498
|
createConsumptionModal,
|
|
25860
26499
|
createDateRangePicker,
|
|
26500
|
+
createDistributionChartWidget,
|
|
25861
26501
|
createInputDateRangePickerInsideDIV,
|
|
25862
26502
|
createModalHeader,
|
|
25863
26503
|
decodePayload,
|
|
@@ -25896,11 +26536,16 @@ var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
|
|
|
25896
26536
|
getAvailableContexts,
|
|
25897
26537
|
getConnectionStatusIcon,
|
|
25898
26538
|
getDateRangeArray,
|
|
26539
|
+
getDefaultGroupColors,
|
|
25899
26540
|
getDeviceStatusIcon,
|
|
25900
26541
|
getDeviceStatusInfo,
|
|
26542
|
+
getDistributionThemeColors,
|
|
26543
|
+
getGroupColor,
|
|
26544
|
+
getHashColor,
|
|
25901
26545
|
getModalHeaderStyles,
|
|
25902
26546
|
getSaoPauloISOString,
|
|
25903
26547
|
getSaoPauloISOStringFixed,
|
|
26548
|
+
getShoppingColor,
|
|
25904
26549
|
getValueByDatakey,
|
|
25905
26550
|
getValueByDatakeyLegacy,
|
|
25906
26551
|
getWaterCategories,
|