myio-js-library 0.1.165 → 0.1.167

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.js CHANGED
@@ -23593,11 +23593,16 @@ function createConsumptionModal(config) {
23593
23593
  let isMaximized = false;
23594
23594
  const domainCfg = DOMAIN_CONFIG3[config.domain] || { name: config.domain, icon: "\u{1F4CA}" };
23595
23595
  const title = config.title || `${domainCfg.name} - Hist\xF3rico de Consumo`;
23596
- function getThemeColors2() {
23596
+ function getThemeColors3() {
23597
23597
  return THEME_COLORS[currentTheme];
23598
23598
  }
23599
+ 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>`;
23600
+ 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>`;
23601
+ 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>`;
23602
+ 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>`;
23603
+ const showSettingsButton = config.showSettingsButton ?? true;
23599
23604
  function renderModal4() {
23600
- const colors = getThemeColors2();
23605
+ const colors = getThemeColors3();
23601
23606
  const exportFormats = config.exportFormats || ["csv"];
23602
23607
  headerInstance = createModalHeader({
23603
23608
  id: modalId,
@@ -23630,7 +23635,55 @@ function createConsumptionModal(config) {
23630
23635
  instance.close();
23631
23636
  }
23632
23637
  });
23638
+ const btnBaseStyle = `
23639
+ display: flex;
23640
+ align-items: center;
23641
+ justify-content: center;
23642
+ gap: 6px;
23643
+ padding: 6px 12px;
23644
+ border: none;
23645
+ border-radius: 6px;
23646
+ font-size: 12px;
23647
+ font-weight: 500;
23648
+ cursor: pointer;
23649
+ transition: all 0.2s;
23650
+ white-space: nowrap;
23651
+ `.replace(/\s+/g, " ").trim();
23652
+ const tabBgColor = currentTheme === "dark" ? "#4b5563" : "#e5e7eb";
23653
+ const activeColor = "#3e1a7d";
23654
+ const inactiveTextColor = colors.text;
23633
23655
  return `
23656
+ <style>
23657
+ .myio-modal-tab-btn {
23658
+ ${btnBaseStyle}
23659
+ }
23660
+ .myio-modal-tab-btn:hover {
23661
+ opacity: 0.85;
23662
+ }
23663
+ .myio-modal-tab-btn.active {
23664
+ background: ${activeColor} !important;
23665
+ color: white !important;
23666
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
23667
+ }
23668
+ .myio-modal-tab-btn svg {
23669
+ pointer-events: none;
23670
+ }
23671
+ .myio-modal-settings-btn {
23672
+ background: transparent;
23673
+ border: 1px solid ${colors.border};
23674
+ font-size: 16px;
23675
+ cursor: pointer;
23676
+ padding: 6px 10px;
23677
+ border-radius: 6px;
23678
+ transition: all 0.2s;
23679
+ color: ${colors.text};
23680
+ }
23681
+ .myio-modal-settings-btn:hover {
23682
+ background: ${activeColor};
23683
+ border-color: ${activeColor};
23684
+ color: white;
23685
+ }
23686
+ </style>
23634
23687
  <div class="myio-consumption-modal-overlay" style="
23635
23688
  position: fixed;
23636
23689
  top: 0;
@@ -23661,59 +23714,44 @@ function createConsumptionModal(config) {
23661
23714
  <!-- Controls Bar -->
23662
23715
  <div class="myio-consumption-modal-controls" style="
23663
23716
  display: flex;
23664
- gap: 16px;
23717
+ gap: 12px;
23665
23718
  padding: 12px 16px;
23666
23719
  background: ${currentTheme === "dark" ? "#374151" : "#f7f7f7"};
23667
23720
  border-bottom: 1px solid ${colors.border};
23668
23721
  align-items: center;
23669
23722
  flex-wrap: wrap;
23670
23723
  ">
23724
+ <!-- Settings Button -->
23725
+ ${showSettingsButton ? `
23726
+ <button id="${modalId}-settings-btn" class="myio-modal-settings-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
23727
+ ` : ""}
23728
+
23671
23729
  <!-- Viz Mode Tabs -->
23672
- <div style="display: flex; gap: 2px; background: ${currentTheme === "dark" ? "#4b5563" : "#e5e7eb"}; border-radius: 8px; padding: 2px;">
23673
- <button id="${modalId}-viz-total" style="
23674
- padding: 6px 12px;
23675
- border: none;
23676
- border-radius: 6px;
23677
- font-size: 13px;
23678
- cursor: pointer;
23679
- transition: all 0.2s;
23680
- background: ${currentVizMode === "total" ? "#3e1a7d" : "transparent"};
23681
- color: ${currentVizMode === "total" ? "white" : colors.text};
23682
- ">Consolidado</button>
23683
- <button id="${modalId}-viz-separate" style="
23684
- padding: 6px 12px;
23685
- border: none;
23686
- border-radius: 6px;
23687
- font-size: 13px;
23688
- cursor: pointer;
23689
- transition: all 0.2s;
23690
- background: ${currentVizMode === "separate" ? "#3e1a7d" : "transparent"};
23691
- color: ${currentVizMode === "separate" ? "white" : colors.text};
23692
- ">Por Shopping</button>
23730
+ <div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
23731
+ <button id="${modalId}-viz-total" class="myio-modal-tab-btn ${currentVizMode === "total" ? "active" : ""}"
23732
+ data-viz="total" title="Consolidado"
23733
+ style="background: ${currentVizMode === "total" ? activeColor : "transparent"}; color: ${currentVizMode === "total" ? "white" : inactiveTextColor};">
23734
+ ${consolidadoIcon}
23735
+ </button>
23736
+ <button id="${modalId}-viz-separate" class="myio-modal-tab-btn ${currentVizMode === "separate" ? "active" : ""}"
23737
+ data-viz="separate" title="Por Shopping"
23738
+ style="background: ${currentVizMode === "separate" ? activeColor : "transparent"}; color: ${currentVizMode === "separate" ? "white" : inactiveTextColor};">
23739
+ ${porShoppingIcon}
23740
+ </button>
23693
23741
  </div>
23694
23742
 
23695
23743
  <!-- Chart Type Tabs -->
23696
- <div style="display: flex; gap: 2px; background: ${currentTheme === "dark" ? "#4b5563" : "#e5e7eb"}; border-radius: 8px; padding: 2px;">
23697
- <button id="${modalId}-type-line" style="
23698
- padding: 6px 12px;
23699
- border: none;
23700
- border-radius: 6px;
23701
- font-size: 13px;
23702
- cursor: pointer;
23703
- transition: all 0.2s;
23704
- background: ${currentChartType === "line" ? "#3e1a7d" : "transparent"};
23705
- color: ${currentChartType === "line" ? "white" : colors.text};
23706
- ">Linhas</button>
23707
- <button id="${modalId}-type-bar" style="
23708
- padding: 6px 12px;
23709
- border: none;
23710
- border-radius: 6px;
23711
- font-size: 13px;
23712
- cursor: pointer;
23713
- transition: all 0.2s;
23714
- background: ${currentChartType === "bar" ? "#3e1a7d" : "transparent"};
23715
- color: ${currentChartType === "bar" ? "white" : colors.text};
23716
- ">Barras</button>
23744
+ <div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
23745
+ <button id="${modalId}-type-line" class="myio-modal-tab-btn ${currentChartType === "line" ? "active" : ""}"
23746
+ data-type="line" title="Gr\xE1fico de Linhas"
23747
+ style="background: ${currentChartType === "line" ? activeColor : "transparent"}; color: ${currentChartType === "line" ? "white" : inactiveTextColor};">
23748
+ ${lineChartIcon}
23749
+ </button>
23750
+ <button id="${modalId}-type-bar" class="myio-modal-tab-btn ${currentChartType === "bar" ? "active" : ""}"
23751
+ data-type="bar" title="Gr\xE1fico de Barras"
23752
+ style="background: ${currentChartType === "bar" ? activeColor : "transparent"}; color: ${currentChartType === "bar" ? "white" : inactiveTextColor};">
23753
+ ${barChartIcon}
23754
+ </button>
23717
23755
  </div>
23718
23756
  </div>
23719
23757
 
@@ -23734,6 +23772,11 @@ function createConsumptionModal(config) {
23734
23772
  function setupListeners() {
23735
23773
  if (!modalElement) return;
23736
23774
  headerInstance?.attachListeners();
23775
+ if (showSettingsButton) {
23776
+ document.getElementById(`${modalId}-settings-btn`)?.addEventListener("click", () => {
23777
+ config.onSettingsClick?.();
23778
+ });
23779
+ }
23737
23780
  document.getElementById(`${modalId}-viz-total`)?.addEventListener("click", () => {
23738
23781
  currentVizMode = "total";
23739
23782
  chartInstance?.setVizMode("total");
@@ -23768,25 +23811,30 @@ function createConsumptionModal(config) {
23768
23811
  modalElement.__handleKeydown = handleKeydown;
23769
23812
  }
23770
23813
  function updateControlStyles() {
23771
- const colors = getThemeColors2();
23814
+ const colors = getThemeColors3();
23815
+ const activeColor = "#3e1a7d";
23772
23816
  const vizTotalBtn = document.getElementById(`${modalId}-viz-total`);
23773
23817
  const vizSeparateBtn = document.getElementById(`${modalId}-viz-separate`);
23774
23818
  if (vizTotalBtn) {
23775
- vizTotalBtn.style.background = currentVizMode === "total" ? "#3e1a7d" : "transparent";
23819
+ vizTotalBtn.classList.toggle("active", currentVizMode === "total");
23820
+ vizTotalBtn.style.background = currentVizMode === "total" ? activeColor : "transparent";
23776
23821
  vizTotalBtn.style.color = currentVizMode === "total" ? "white" : colors.text;
23777
23822
  }
23778
23823
  if (vizSeparateBtn) {
23779
- vizSeparateBtn.style.background = currentVizMode === "separate" ? "#3e1a7d" : "transparent";
23824
+ vizSeparateBtn.classList.toggle("active", currentVizMode === "separate");
23825
+ vizSeparateBtn.style.background = currentVizMode === "separate" ? activeColor : "transparent";
23780
23826
  vizSeparateBtn.style.color = currentVizMode === "separate" ? "white" : colors.text;
23781
23827
  }
23782
23828
  const typeLineBtn = document.getElementById(`${modalId}-type-line`);
23783
23829
  const typeBarBtn = document.getElementById(`${modalId}-type-bar`);
23784
23830
  if (typeLineBtn) {
23785
- typeLineBtn.style.background = currentChartType === "line" ? "#3e1a7d" : "transparent";
23831
+ typeLineBtn.classList.toggle("active", currentChartType === "line");
23832
+ typeLineBtn.style.background = currentChartType === "line" ? activeColor : "transparent";
23786
23833
  typeLineBtn.style.color = currentChartType === "line" ? "white" : colors.text;
23787
23834
  }
23788
23835
  if (typeBarBtn) {
23789
- typeBarBtn.style.background = currentChartType === "bar" ? "#3e1a7d" : "transparent";
23836
+ typeBarBtn.classList.toggle("active", currentChartType === "bar");
23837
+ typeBarBtn.style.background = currentChartType === "bar" ? activeColor : "transparent";
23790
23838
  typeBarBtn.style.color = currentChartType === "bar" ? "white" : colors.text;
23791
23839
  }
23792
23840
  }
@@ -23823,7 +23871,11 @@ function createConsumptionModal(config) {
23823
23871
  defaultChartType: currentChartType,
23824
23872
  defaultVizMode: currentVizMode
23825
23873
  });
23826
- await chartInstance.render();
23874
+ if (config.initialData) {
23875
+ chartInstance.update(config.initialData);
23876
+ } else {
23877
+ await chartInstance.render();
23878
+ }
23827
23879
  },
23828
23880
  close() {
23829
23881
  if (modalElement) {
@@ -25686,6 +25738,581 @@ var EXPORT_DEFAULT_COLORS = DEFAULT_COLORS4;
25686
25738
  var EXPORT_DOMAIN_ICONS = DOMAIN_ICONS;
25687
25739
  var EXPORT_DOMAIN_LABELS = DOMAIN_LABELS;
25688
25740
  var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
25741
+
25742
+ // src/components/DistributionChart/colorManager.ts
25743
+ var DEFAULT_SHOPPING_COLORS = [
25744
+ "#3b82f6",
25745
+ // Blue
25746
+ "#8b5cf6",
25747
+ // Purple
25748
+ "#f59e0b",
25749
+ // Amber
25750
+ "#ef4444",
25751
+ // Red
25752
+ "#10b981",
25753
+ // Emerald
25754
+ "#06b6d4",
25755
+ // Cyan
25756
+ "#ec4899",
25757
+ // Pink
25758
+ "#14b8a6",
25759
+ // Teal
25760
+ "#f97316",
25761
+ // Orange
25762
+ "#a855f7"
25763
+ // Violet
25764
+ ];
25765
+ var DEFAULT_ENERGY_GROUP_COLORS = {
25766
+ "Elevadores": "#3b82f6",
25767
+ "Escadas Rolantes": "#8b5cf6",
25768
+ "Climatiza\xE7\xE3o": "#f59e0b",
25769
+ "Climatizacao": "#f59e0b",
25770
+ // Without accent
25771
+ "Outros Equipamentos": "#ef4444",
25772
+ "Lojas": "#10b981"
25773
+ };
25774
+ var DEFAULT_WATER_GROUP_COLORS = {
25775
+ "Lojas": "#10b981",
25776
+ "\xC1rea Comum": "#0288d1",
25777
+ "Area Comum": "#0288d1"
25778
+ // Without accent
25779
+ };
25780
+ var DEFAULT_GAS_GROUP_COLORS = {
25781
+ "Cozinha": "#f59e0b",
25782
+ "Aquecimento": "#ef4444",
25783
+ "Outros": "#94a3b8"
25784
+ };
25785
+ function getDefaultGroupColors(domain) {
25786
+ switch (domain.toLowerCase()) {
25787
+ case "energy":
25788
+ return DEFAULT_ENERGY_GROUP_COLORS;
25789
+ case "water":
25790
+ return DEFAULT_WATER_GROUP_COLORS;
25791
+ case "gas":
25792
+ return DEFAULT_GAS_GROUP_COLORS;
25793
+ default:
25794
+ return DEFAULT_ENERGY_GROUP_COLORS;
25795
+ }
25796
+ }
25797
+ function assignShoppingColors(shoppingIds) {
25798
+ const colors = {};
25799
+ shoppingIds.forEach((id, index) => {
25800
+ colors[id] = DEFAULT_SHOPPING_COLORS[index % DEFAULT_SHOPPING_COLORS.length];
25801
+ });
25802
+ return colors;
25803
+ }
25804
+ function getShoppingColor(shoppingId, shoppingColors, fallbackIndex = 0) {
25805
+ if (shoppingColors && shoppingColors[shoppingId]) {
25806
+ return shoppingColors[shoppingId];
25807
+ }
25808
+ if (shoppingColors) {
25809
+ const normalizedId = shoppingId.toLowerCase();
25810
+ for (const [key, color] of Object.entries(shoppingColors)) {
25811
+ if (key.toLowerCase() === normalizedId || key.toLowerCase().includes(normalizedId)) {
25812
+ return color;
25813
+ }
25814
+ }
25815
+ }
25816
+ return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
25817
+ }
25818
+ function getGroupColor(groupName, groupColors, domain = "energy", fallbackIndex = 0) {
25819
+ if (groupColors && groupColors[groupName]) {
25820
+ return groupColors[groupName];
25821
+ }
25822
+ const defaultColors = getDefaultGroupColors(domain);
25823
+ if (defaultColors[groupName]) {
25824
+ return defaultColors[groupName];
25825
+ }
25826
+ return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
25827
+ }
25828
+ function getThemeColors2(theme) {
25829
+ if (theme === "dark") {
25830
+ return {
25831
+ text: "#f3f4f6",
25832
+ secondaryText: "#9ca3af",
25833
+ background: "#111827",
25834
+ cardBackground: "#1f2937",
25835
+ border: "#374151",
25836
+ grid: "#374151"
25837
+ };
25838
+ }
25839
+ return {
25840
+ text: "#1f2937",
25841
+ secondaryText: "#6b7280",
25842
+ background: "#f5f5f5",
25843
+ cardBackground: "#ffffff",
25844
+ border: "#e5e7eb",
25845
+ grid: "#e5e7eb"
25846
+ };
25847
+ }
25848
+ function getHashColor(str) {
25849
+ let hash = 0;
25850
+ for (let i = 0; i < str.length; i++) {
25851
+ const char = str.charCodeAt(i);
25852
+ hash = (hash << 5) - hash + char;
25853
+ hash = hash & hash;
25854
+ }
25855
+ return DEFAULT_SHOPPING_COLORS[Math.abs(hash) % DEFAULT_SHOPPING_COLORS.length];
25856
+ }
25857
+
25858
+ // src/components/DistributionChart/createDistributionChartWidget.ts
25859
+ 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>`;
25860
+ 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>`;
25861
+ function createDistributionChartWidget(config) {
25862
+ const widgetId = `distribution-${config.domain}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
25863
+ let chartInstance = null;
25864
+ let currentMode = config.defaultMode || "groups";
25865
+ let currentTheme = config.theme || "light";
25866
+ let currentData = null;
25867
+ let containerElement = null;
25868
+ let isLoading = false;
25869
+ const title = config.title || getDomainTitle(config.domain);
25870
+ const chartHeight = config.chartHeight || 300;
25871
+ const showHeader = config.showHeader !== false;
25872
+ const showModeSelector = config.showModeSelector !== false;
25873
+ const showSettingsButton = config.showSettingsButton ?? false;
25874
+ const showMaximizeButton = config.showMaximizeButton ?? false;
25875
+ const decimalPlaces = config.decimalPlaces ?? 2;
25876
+ const modes = config.modes || getDefaultModes(config.domain);
25877
+ const groupColors = config.groupColors || getDefaultGroupColors(config.domain);
25878
+ function getDomainTitle(domain) {
25879
+ const titles = {
25880
+ energy: "Distribui\xE7\xE3o de Energia",
25881
+ water: "Distribui\xE7\xE3o de \xC1gua",
25882
+ gas: "Distribui\xE7\xE3o de G\xE1s",
25883
+ temperature: "Distribui\xE7\xE3o de Temperatura"
25884
+ };
25885
+ return titles[domain.toLowerCase()] || `Distribui\xE7\xE3o de ${domain}`;
25886
+ }
25887
+ function getDefaultModes(domain) {
25888
+ if (domain === "water") {
25889
+ return [
25890
+ { value: "groups", label: "Lojas vs \xC1rea Comum" },
25891
+ { value: "stores", label: "Lojas por Shopping" },
25892
+ { value: "common", label: "\xC1rea Comum por Shopping" }
25893
+ ];
25894
+ }
25895
+ return [
25896
+ { value: "groups", label: "Por Grupos de Equipamentos" },
25897
+ { value: "elevators", label: "Elevadores por Shopping" },
25898
+ { value: "escalators", label: "Escadas Rolantes por Shopping" },
25899
+ { value: "hvac", label: "Climatiza\xE7\xE3o por Shopping" },
25900
+ { value: "others", label: "Outros Equipamentos por Shopping" },
25901
+ { value: "stores", label: "Lojas por Shopping" }
25902
+ ];
25903
+ }
25904
+ function $id(id) {
25905
+ if (config.$container) {
25906
+ return config.$container[0].querySelector(`#${id}`);
25907
+ }
25908
+ return document.getElementById(id);
25909
+ }
25910
+ function formatValue(value) {
25911
+ if (config.unitLarge && config.thresholdForLargeUnit && value >= config.thresholdForLargeUnit) {
25912
+ return `${(value / config.thresholdForLargeUnit).toFixed(decimalPlaces)} ${config.unitLarge}`;
25913
+ }
25914
+ return `${value.toFixed(decimalPlaces)} ${config.unit}`;
25915
+ }
25916
+ function getColor(key, index, isGroupMode2) {
25917
+ if (isGroupMode2) {
25918
+ return getGroupColor(key, groupColors, config.domain, index);
25919
+ }
25920
+ const shoppingColors = config.getShoppingColors?.();
25921
+ return getShoppingColor(key, shoppingColors, index);
25922
+ }
25923
+ function getColors2() {
25924
+ return getThemeColors2(currentTheme);
25925
+ }
25926
+ function isGroupMode() {
25927
+ return currentMode === "groups";
25928
+ }
25929
+ function renderHTML() {
25930
+ const colors = getColors2();
25931
+ const modeOptions = modes.map(
25932
+ (m) => `<option value="${m.value}" ${m.value === currentMode ? "selected" : ""}>${m.label}</option>`
25933
+ ).join("");
25934
+ const headerButtons = [];
25935
+ if (showSettingsButton) {
25936
+ headerButtons.push(`
25937
+ <button id="${widgetId}-settings-btn" class="myio-dist-btn" title="Configura\xE7\xF5es">
25938
+ ${settingsIcon}
25939
+ </button>
25940
+ `);
25941
+ }
25942
+ if (showMaximizeButton) {
25943
+ headerButtons.push(`
25944
+ <button id="${widgetId}-maximize-btn" class="myio-dist-btn" title="Expandir">
25945
+ ${maximizeIcon}
25946
+ </button>
25947
+ `);
25948
+ }
25949
+ return `
25950
+ <style>
25951
+ #${widgetId} {
25952
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
25953
+ }
25954
+ #${widgetId} .myio-dist-header {
25955
+ display: flex;
25956
+ justify-content: space-between;
25957
+ align-items: center;
25958
+ margin-bottom: 16px;
25959
+ flex-wrap: wrap;
25960
+ gap: 12px;
25961
+ }
25962
+ #${widgetId} .myio-dist-title {
25963
+ margin: 0;
25964
+ font-size: 16px;
25965
+ font-weight: 600;
25966
+ color: ${colors.text};
25967
+ }
25968
+ #${widgetId} .myio-dist-controls {
25969
+ display: flex;
25970
+ align-items: center;
25971
+ gap: 8px;
25972
+ }
25973
+ #${widgetId} .myio-dist-label {
25974
+ font-size: 12px;
25975
+ color: ${colors.secondaryText};
25976
+ }
25977
+ #${widgetId} .myio-dist-select {
25978
+ padding: 6px 10px;
25979
+ border-radius: 6px;
25980
+ border: 1px solid ${colors.border};
25981
+ background: ${colors.cardBackground};
25982
+ color: ${colors.text};
25983
+ font-size: 12px;
25984
+ cursor: pointer;
25985
+ min-width: 180px;
25986
+ }
25987
+ #${widgetId} .myio-dist-select:focus {
25988
+ outline: none;
25989
+ border-color: #3e1a7d;
25990
+ }
25991
+ #${widgetId} .myio-dist-btn {
25992
+ display: flex;
25993
+ align-items: center;
25994
+ justify-content: center;
25995
+ padding: 6px 8px;
25996
+ border: 1px solid ${colors.border};
25997
+ border-radius: 6px;
25998
+ background: transparent;
25999
+ color: ${colors.text};
26000
+ cursor: pointer;
26001
+ transition: all 0.2s;
26002
+ }
26003
+ #${widgetId} .myio-dist-btn:hover {
26004
+ background: #3e1a7d;
26005
+ border-color: #3e1a7d;
26006
+ color: white;
26007
+ }
26008
+ #${widgetId} .myio-dist-chart-container {
26009
+ position: relative;
26010
+ height: ${chartHeight}px;
26011
+ }
26012
+ #${widgetId} .myio-dist-loading {
26013
+ position: absolute;
26014
+ top: 0;
26015
+ left: 0;
26016
+ right: 0;
26017
+ bottom: 0;
26018
+ display: flex;
26019
+ align-items: center;
26020
+ justify-content: center;
26021
+ background: ${colors.cardBackground}ee;
26022
+ z-index: 10;
26023
+ }
26024
+ #${widgetId} .myio-dist-spinner {
26025
+ width: 32px;
26026
+ height: 32px;
26027
+ border: 3px solid ${colors.border};
26028
+ border-top-color: #3e1a7d;
26029
+ border-radius: 50%;
26030
+ animation: myio-dist-spin 0.8s linear infinite;
26031
+ }
26032
+ @keyframes myio-dist-spin {
26033
+ to { transform: rotate(360deg); }
26034
+ }
26035
+ #${widgetId} .myio-dist-empty {
26036
+ display: flex;
26037
+ flex-direction: column;
26038
+ align-items: center;
26039
+ justify-content: center;
26040
+ height: 100%;
26041
+ color: ${colors.secondaryText};
26042
+ font-size: 14px;
26043
+ }
26044
+ #${widgetId} .myio-dist-empty-icon {
26045
+ font-size: 48px;
26046
+ margin-bottom: 12px;
26047
+ opacity: 0.5;
26048
+ }
26049
+ </style>
26050
+
26051
+ <div id="${widgetId}" class="myio-distribution-widget" style="
26052
+ background: ${colors.cardBackground};
26053
+ border-radius: 12px;
26054
+ padding: 16px;
26055
+ height: 100%;
26056
+ display: flex;
26057
+ flex-direction: column;
26058
+ ">
26059
+ ${showHeader ? `
26060
+ <div class="myio-dist-header">
26061
+ <h4 class="myio-dist-title">${title}</h4>
26062
+ <div class="myio-dist-controls">
26063
+ ${showModeSelector && modes.length > 1 ? `
26064
+ <label for="${widgetId}-mode" class="myio-dist-label">Visualizar:</label>
26065
+ <select id="${widgetId}-mode" class="myio-dist-select">
26066
+ ${modeOptions}
26067
+ </select>
26068
+ ` : ""}
26069
+ ${headerButtons.join("")}
26070
+ </div>
26071
+ </div>
26072
+ ` : ""}
26073
+
26074
+ <div class="myio-dist-chart-container">
26075
+ <canvas id="${widgetId}-canvas"></canvas>
26076
+ <div id="${widgetId}-loading" class="myio-dist-loading" style="display: none;">
26077
+ <div class="myio-dist-spinner"></div>
26078
+ </div>
26079
+ </div>
26080
+ </div>
26081
+ `;
26082
+ }
26083
+ function setLoading(loading) {
26084
+ isLoading = loading;
26085
+ const loadingEl = $id(`${widgetId}-loading`);
26086
+ if (loadingEl) {
26087
+ loadingEl.style.display = loading ? "flex" : "none";
26088
+ }
26089
+ }
26090
+ function buildChartData(distribution) {
26091
+ const labels = [];
26092
+ const data = [];
26093
+ const backgroundColors = [];
26094
+ const total = Object.values(distribution).reduce((sum, val) => sum + val, 0);
26095
+ const isGroup = isGroupMode();
26096
+ const entries = Object.entries(distribution).filter(([_, value]) => value > 0).sort((a, b) => b[1] - a[1]);
26097
+ entries.forEach(([key, value], index) => {
26098
+ const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
26099
+ labels.push(`${key} (${formatValue(value)} - ${percentage}%)`);
26100
+ data.push(value);
26101
+ backgroundColors.push(getColor(key, index, isGroup));
26102
+ });
26103
+ return { labels, data, backgroundColors, total };
26104
+ }
26105
+ function renderEmptyState() {
26106
+ const container = $id(`${widgetId}-canvas`)?.parentElement;
26107
+ if (container) {
26108
+ const emptyEl = document.createElement("div");
26109
+ emptyEl.className = "myio-dist-empty";
26110
+ emptyEl.innerHTML = `
26111
+ <div class="myio-dist-empty-icon">\u{1F4CA}</div>
26112
+ <div>Sem dados dispon\xEDveis</div>
26113
+ `;
26114
+ const canvas = $id(`${widgetId}-canvas`);
26115
+ if (canvas) canvas.style.display = "none";
26116
+ const existingEmpty = container.querySelector(".myio-dist-empty");
26117
+ if (!existingEmpty) {
26118
+ container.appendChild(emptyEl);
26119
+ }
26120
+ }
26121
+ }
26122
+ function removeEmptyState() {
26123
+ const container = $id(`${widgetId}-canvas`)?.parentElement;
26124
+ if (container) {
26125
+ const emptyEl = container.querySelector(".myio-dist-empty");
26126
+ if (emptyEl) emptyEl.remove();
26127
+ const canvas = $id(`${widgetId}-canvas`);
26128
+ if (canvas) canvas.style.display = "block";
26129
+ }
26130
+ }
26131
+ async function updateChart() {
26132
+ const canvas = $id(`${widgetId}-canvas`);
26133
+ if (!canvas) {
26134
+ console.error(`[${config.domain.toUpperCase()}] Distribution canvas not found`);
26135
+ return;
26136
+ }
26137
+ setLoading(true);
26138
+ try {
26139
+ const distribution = await config.fetchDistribution(currentMode);
26140
+ if (!distribution || Object.keys(distribution).length === 0) {
26141
+ console.warn(`[${config.domain.toUpperCase()}] No distribution data for mode: ${currentMode}`);
26142
+ currentData = null;
26143
+ setLoading(false);
26144
+ renderEmptyState();
26145
+ return;
26146
+ }
26147
+ removeEmptyState();
26148
+ currentData = distribution;
26149
+ const { labels, data, backgroundColors, total } = buildChartData(distribution);
26150
+ const colors = getColors2();
26151
+ const Chart2 = window.Chart;
26152
+ if (!Chart2) {
26153
+ throw new Error("Chart.js not loaded");
26154
+ }
26155
+ if (chartInstance) {
26156
+ chartInstance.destroy();
26157
+ chartInstance = null;
26158
+ }
26159
+ const ctx = canvas.getContext("2d");
26160
+ if (!ctx) {
26161
+ throw new Error("Could not get canvas context");
26162
+ }
26163
+ chartInstance = new Chart2(ctx, {
26164
+ type: "bar",
26165
+ data: {
26166
+ labels,
26167
+ datasets: [
26168
+ {
26169
+ label: `Consumo (${config.unit})`,
26170
+ data,
26171
+ backgroundColor: backgroundColors
26172
+ }
26173
+ ]
26174
+ },
26175
+ options: {
26176
+ responsive: true,
26177
+ maintainAspectRatio: false,
26178
+ indexAxis: "y",
26179
+ // Horizontal bar chart
26180
+ animation: false,
26181
+ plugins: {
26182
+ legend: { display: false },
26183
+ tooltip: {
26184
+ callbacks: {
26185
+ label: (context) => {
26186
+ const value = context.parsed.x || 0;
26187
+ const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
26188
+ return `${formatValue(value)} (${percentage}%)`;
26189
+ }
26190
+ }
26191
+ }
26192
+ },
26193
+ scales: {
26194
+ x: {
26195
+ beginAtZero: true,
26196
+ ticks: {
26197
+ callback: (value) => formatValue(Number(value)),
26198
+ color: colors.secondaryText,
26199
+ font: { size: 11 }
26200
+ },
26201
+ grid: { color: colors.grid }
26202
+ },
26203
+ y: {
26204
+ ticks: {
26205
+ font: { size: 11 },
26206
+ color: colors.text
26207
+ },
26208
+ grid: { display: false }
26209
+ }
26210
+ }
26211
+ }
26212
+ });
26213
+ config.onDataLoaded?.(distribution);
26214
+ console.log(`[${config.domain.toUpperCase()}] Distribution chart updated for mode: ${currentMode}`);
26215
+ } catch (error) {
26216
+ console.error(`[${config.domain.toUpperCase()}] Error updating distribution chart:`, error);
26217
+ config.onError?.(error);
26218
+ renderEmptyState();
26219
+ } finally {
26220
+ setLoading(false);
26221
+ }
26222
+ }
26223
+ function setupListeners() {
26224
+ const modeSelect = $id(`${widgetId}-mode`);
26225
+ if (modeSelect) {
26226
+ modeSelect.addEventListener("change", async (e) => {
26227
+ currentMode = e.target.value;
26228
+ config.onModeChange?.(currentMode);
26229
+ await updateChart();
26230
+ });
26231
+ }
26232
+ if (showSettingsButton) {
26233
+ const settingsBtn = $id(`${widgetId}-settings-btn`);
26234
+ if (settingsBtn) {
26235
+ settingsBtn.addEventListener("click", () => {
26236
+ config.onSettingsClick?.();
26237
+ });
26238
+ }
26239
+ }
26240
+ if (showMaximizeButton) {
26241
+ const maximizeBtn = $id(`${widgetId}-maximize-btn`);
26242
+ if (maximizeBtn) {
26243
+ maximizeBtn.addEventListener("click", () => {
26244
+ config.onMaximizeClick?.();
26245
+ });
26246
+ }
26247
+ }
26248
+ }
26249
+ function updateThemeStyles() {
26250
+ const colors = getColors2();
26251
+ const widget = $id(widgetId);
26252
+ if (widget) {
26253
+ widget.style.background = colors.cardBackground;
26254
+ const title2 = widget.querySelector(".myio-dist-title");
26255
+ if (title2) title2.style.color = colors.text;
26256
+ const labels = widget.querySelectorAll(".myio-dist-label");
26257
+ labels.forEach((l) => l.style.color = colors.secondaryText);
26258
+ const select = widget.querySelector(".myio-dist-select");
26259
+ if (select) {
26260
+ select.style.background = colors.cardBackground;
26261
+ select.style.color = colors.text;
26262
+ select.style.borderColor = colors.border;
26263
+ }
26264
+ const buttons = widget.querySelectorAll(".myio-dist-btn");
26265
+ buttons.forEach((b) => {
26266
+ b.style.color = colors.text;
26267
+ b.style.borderColor = colors.border;
26268
+ });
26269
+ }
26270
+ }
26271
+ const instance = {
26272
+ async render() {
26273
+ containerElement = $id(config.containerId);
26274
+ if (!containerElement) {
26275
+ throw new Error(`Container #${config.containerId} not found`);
26276
+ }
26277
+ containerElement.innerHTML = renderHTML();
26278
+ setupListeners();
26279
+ await updateChart();
26280
+ },
26281
+ async setMode(mode) {
26282
+ currentMode = mode;
26283
+ const modeSelect = $id(`${widgetId}-mode`);
26284
+ if (modeSelect) {
26285
+ modeSelect.value = mode;
26286
+ }
26287
+ config.onModeChange?.(mode);
26288
+ await updateChart();
26289
+ },
26290
+ async refresh() {
26291
+ await updateChart();
26292
+ },
26293
+ setTheme(theme) {
26294
+ currentTheme = theme;
26295
+ updateThemeStyles();
26296
+ if (currentData) {
26297
+ updateChart();
26298
+ }
26299
+ },
26300
+ destroy() {
26301
+ if (chartInstance) {
26302
+ chartInstance.destroy();
26303
+ chartInstance = null;
26304
+ }
26305
+ if (containerElement) {
26306
+ containerElement.innerHTML = "";
26307
+ }
26308
+ currentData = null;
26309
+ },
26310
+ getChartInstance: () => chartInstance,
26311
+ getCurrentMode: () => currentMode,
26312
+ getCurrentData: () => currentData
26313
+ };
26314
+ return instance;
26315
+ }
25689
26316
  export {
25690
26317
  CHART_COLORS,
25691
26318
  DEFAULT_COLORS as CONSUMPTION_CHART_COLORS,
@@ -25693,6 +26320,10 @@ export {
25693
26320
  THEME_COLORS as CONSUMPTION_THEME_COLORS,
25694
26321
  ConnectionStatusType,
25695
26322
  DEFAULT_CLAMP_RANGE,
26323
+ DEFAULT_ENERGY_GROUP_COLORS,
26324
+ DEFAULT_GAS_GROUP_COLORS,
26325
+ DEFAULT_SHOPPING_COLORS,
26326
+ DEFAULT_WATER_GROUP_COLORS,
25696
26327
  DeviceStatusType,
25697
26328
  EXPORT_DEFAULT_COLORS,
25698
26329
  EXPORT_DOMAIN_ICONS,
@@ -25706,6 +26337,7 @@ export {
25706
26337
  addDetectionContext,
25707
26338
  addNamespace,
25708
26339
  aggregateByDay,
26340
+ assignShoppingColors,
25709
26341
  averageByDay,
25710
26342
  buildListItemsThingsboardByUniqueDatasource,
25711
26343
  buildMyioIngestionAuth,
@@ -25727,6 +26359,7 @@ export {
25727
26359
  createConsumptionChartWidget,
25728
26360
  createConsumptionModal,
25729
26361
  createDateRangePicker2 as createDateRangePicker,
26362
+ createDistributionChartWidget,
25730
26363
  createInputDateRangePickerInsideDIV,
25731
26364
  createModalHeader,
25732
26365
  decodePayload,
@@ -25765,11 +26398,16 @@ export {
25765
26398
  getAvailableContexts,
25766
26399
  getConnectionStatusIcon,
25767
26400
  getDateRangeArray,
26401
+ getDefaultGroupColors,
25768
26402
  getDeviceStatusIcon,
25769
26403
  getDeviceStatusInfo,
26404
+ getThemeColors2 as getDistributionThemeColors,
26405
+ getGroupColor,
26406
+ getHashColor,
25770
26407
  getModalHeaderStyles,
25771
26408
  getSaoPauloISOString,
25772
26409
  getSaoPauloISOStringFixed,
26410
+ getShoppingColor,
25773
26411
  getValueByDatakey,
25774
26412
  getValueByDatakeyLegacy,
25775
26413
  getWaterCategories,