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.
@@ -23411,11 +23411,16 @@ ${rangeText}`;
23411
23411
  let isMaximized = false;
23412
23412
  const domainCfg = DOMAIN_CONFIG3[config.domain] || { name: config.domain, icon: "\u{1F4CA}" };
23413
23413
  const title = config.title || `${domainCfg.name} - Hist\xF3rico de Consumo`;
23414
- function getThemeColors2() {
23414
+ function getThemeColors3() {
23415
23415
  return THEME_COLORS[currentTheme];
23416
23416
  }
23417
+ 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>`;
23418
+ 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>`;
23419
+ 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>`;
23420
+ 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>`;
23421
+ const showSettingsButton = config.showSettingsButton ?? true;
23417
23422
  function renderModal4() {
23418
- const colors = getThemeColors2();
23423
+ const colors = getThemeColors3();
23419
23424
  const exportFormats = config.exportFormats || ["csv"];
23420
23425
  headerInstance = createModalHeader({
23421
23426
  id: modalId,
@@ -23448,7 +23453,55 @@ ${rangeText}`;
23448
23453
  instance.close();
23449
23454
  }
23450
23455
  });
23456
+ const btnBaseStyle = `
23457
+ display: flex;
23458
+ align-items: center;
23459
+ justify-content: center;
23460
+ gap: 6px;
23461
+ padding: 6px 12px;
23462
+ border: none;
23463
+ border-radius: 6px;
23464
+ font-size: 12px;
23465
+ font-weight: 500;
23466
+ cursor: pointer;
23467
+ transition: all 0.2s;
23468
+ white-space: nowrap;
23469
+ `.replace(/\s+/g, " ").trim();
23470
+ const tabBgColor = currentTheme === "dark" ? "#4b5563" : "#e5e7eb";
23471
+ const activeColor = "#3e1a7d";
23472
+ const inactiveTextColor = colors.text;
23451
23473
  return `
23474
+ <style>
23475
+ .myio-modal-tab-btn {
23476
+ ${btnBaseStyle}
23477
+ }
23478
+ .myio-modal-tab-btn:hover {
23479
+ opacity: 0.85;
23480
+ }
23481
+ .myio-modal-tab-btn.active {
23482
+ background: ${activeColor} !important;
23483
+ color: white !important;
23484
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
23485
+ }
23486
+ .myio-modal-tab-btn svg {
23487
+ pointer-events: none;
23488
+ }
23489
+ .myio-modal-settings-btn {
23490
+ background: transparent;
23491
+ border: 1px solid ${colors.border};
23492
+ font-size: 16px;
23493
+ cursor: pointer;
23494
+ padding: 6px 10px;
23495
+ border-radius: 6px;
23496
+ transition: all 0.2s;
23497
+ color: ${colors.text};
23498
+ }
23499
+ .myio-modal-settings-btn:hover {
23500
+ background: ${activeColor};
23501
+ border-color: ${activeColor};
23502
+ color: white;
23503
+ }
23504
+ </style>
23452
23505
  <div class="myio-consumption-modal-overlay" style="
23453
23506
  position: fixed;
23454
23507
  top: 0;
@@ -23479,59 +23532,44 @@ ${rangeText}`;
23479
23532
  <!-- Controls Bar -->
23480
23533
  <div class="myio-consumption-modal-controls" style="
23481
23534
  display: flex;
23482
- gap: 16px;
23535
+ gap: 12px;
23483
23536
  padding: 12px 16px;
23484
23537
  background: ${currentTheme === "dark" ? "#374151" : "#f7f7f7"};
23485
23538
  border-bottom: 1px solid ${colors.border};
23486
23539
  align-items: center;
23487
23540
  flex-wrap: wrap;
23488
23541
  ">
23542
+ <!-- Settings Button -->
23543
+ ${showSettingsButton ? `
23544
+ <button id="${modalId}-settings-btn" class="myio-modal-settings-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
23545
+ ` : ""}
23546
+
23489
23547
  <!-- Viz Mode Tabs -->
23490
- <div style="display: flex; gap: 2px; background: ${currentTheme === "dark" ? "#4b5563" : "#e5e7eb"}; border-radius: 8px; padding: 2px;">
23491
- <button id="${modalId}-viz-total" style="
23492
- padding: 6px 12px;
23493
- border: none;
23494
- border-radius: 6px;
23495
- font-size: 13px;
23496
- cursor: pointer;
23497
- transition: all 0.2s;
23498
- background: ${currentVizMode === "total" ? "#3e1a7d" : "transparent"};
23499
- color: ${currentVizMode === "total" ? "white" : colors.text};
23500
- ">Consolidado</button>
23501
- <button id="${modalId}-viz-separate" style="
23502
- padding: 6px 12px;
23503
- border: none;
23504
- border-radius: 6px;
23505
- font-size: 13px;
23506
- cursor: pointer;
23507
- transition: all 0.2s;
23508
- background: ${currentVizMode === "separate" ? "#3e1a7d" : "transparent"};
23509
- color: ${currentVizMode === "separate" ? "white" : colors.text};
23510
- ">Por Shopping</button>
23548
+ <div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
23549
+ <button id="${modalId}-viz-total" class="myio-modal-tab-btn ${currentVizMode === "total" ? "active" : ""}"
23550
+ data-viz="total" title="Consolidado"
23551
+ style="background: ${currentVizMode === "total" ? activeColor : "transparent"}; color: ${currentVizMode === "total" ? "white" : inactiveTextColor};">
23552
+ ${consolidadoIcon}
23553
+ </button>
23554
+ <button id="${modalId}-viz-separate" class="myio-modal-tab-btn ${currentVizMode === "separate" ? "active" : ""}"
23555
+ data-viz="separate" title="Por Shopping"
23556
+ style="background: ${currentVizMode === "separate" ? activeColor : "transparent"}; color: ${currentVizMode === "separate" ? "white" : inactiveTextColor};">
23557
+ ${porShoppingIcon}
23558
+ </button>
23511
23559
  </div>
23512
23560
 
23513
23561
  <!-- Chart Type Tabs -->
23514
- <div style="display: flex; gap: 2px; background: ${currentTheme === "dark" ? "#4b5563" : "#e5e7eb"}; border-radius: 8px; padding: 2px;">
23515
- <button id="${modalId}-type-line" style="
23516
- padding: 6px 12px;
23517
- border: none;
23518
- border-radius: 6px;
23519
- font-size: 13px;
23520
- cursor: pointer;
23521
- transition: all 0.2s;
23522
- background: ${currentChartType === "line" ? "#3e1a7d" : "transparent"};
23523
- color: ${currentChartType === "line" ? "white" : colors.text};
23524
- ">Linhas</button>
23525
- <button id="${modalId}-type-bar" style="
23526
- padding: 6px 12px;
23527
- border: none;
23528
- border-radius: 6px;
23529
- font-size: 13px;
23530
- cursor: pointer;
23531
- transition: all 0.2s;
23532
- background: ${currentChartType === "bar" ? "#3e1a7d" : "transparent"};
23533
- color: ${currentChartType === "bar" ? "white" : colors.text};
23534
- ">Barras</button>
23562
+ <div style="display: flex; gap: 2px; background: ${tabBgColor}; border-radius: 8px; padding: 3px;">
23563
+ <button id="${modalId}-type-line" class="myio-modal-tab-btn ${currentChartType === "line" ? "active" : ""}"
23564
+ data-type="line" title="Gr\xE1fico de Linhas"
23565
+ style="background: ${currentChartType === "line" ? activeColor : "transparent"}; color: ${currentChartType === "line" ? "white" : inactiveTextColor};">
23566
+ ${lineChartIcon}
23567
+ </button>
23568
+ <button id="${modalId}-type-bar" class="myio-modal-tab-btn ${currentChartType === "bar" ? "active" : ""}"
23569
+ data-type="bar" title="Gr\xE1fico de Barras"
23570
+ style="background: ${currentChartType === "bar" ? activeColor : "transparent"}; color: ${currentChartType === "bar" ? "white" : inactiveTextColor};">
23571
+ ${barChartIcon}
23572
+ </button>
23535
23573
  </div>
23536
23574
  </div>
23537
23575
 
@@ -23552,6 +23590,11 @@ ${rangeText}`;
23552
23590
  function setupListeners() {
23553
23591
  if (!modalElement) return;
23554
23592
  headerInstance?.attachListeners();
23593
+ if (showSettingsButton) {
23594
+ document.getElementById(`${modalId}-settings-btn`)?.addEventListener("click", () => {
23595
+ config.onSettingsClick?.();
23596
+ });
23597
+ }
23555
23598
  document.getElementById(`${modalId}-viz-total`)?.addEventListener("click", () => {
23556
23599
  currentVizMode = "total";
23557
23600
  chartInstance?.setVizMode("total");
@@ -23586,25 +23629,30 @@ ${rangeText}`;
23586
23629
  modalElement.__handleKeydown = handleKeydown;
23587
23630
  }
23588
23631
  function updateControlStyles() {
23589
- const colors = getThemeColors2();
23632
+ const colors = getThemeColors3();
23633
+ const activeColor = "#3e1a7d";
23590
23634
  const vizTotalBtn = document.getElementById(`${modalId}-viz-total`);
23591
23635
  const vizSeparateBtn = document.getElementById(`${modalId}-viz-separate`);
23592
23636
  if (vizTotalBtn) {
23593
- vizTotalBtn.style.background = currentVizMode === "total" ? "#3e1a7d" : "transparent";
23637
+ vizTotalBtn.classList.toggle("active", currentVizMode === "total");
23638
+ vizTotalBtn.style.background = currentVizMode === "total" ? activeColor : "transparent";
23594
23639
  vizTotalBtn.style.color = currentVizMode === "total" ? "white" : colors.text;
23595
23640
  }
23596
23641
  if (vizSeparateBtn) {
23597
- vizSeparateBtn.style.background = currentVizMode === "separate" ? "#3e1a7d" : "transparent";
23642
+ vizSeparateBtn.classList.toggle("active", currentVizMode === "separate");
23643
+ vizSeparateBtn.style.background = currentVizMode === "separate" ? activeColor : "transparent";
23598
23644
  vizSeparateBtn.style.color = currentVizMode === "separate" ? "white" : colors.text;
23599
23645
  }
23600
23646
  const typeLineBtn = document.getElementById(`${modalId}-type-line`);
23601
23647
  const typeBarBtn = document.getElementById(`${modalId}-type-bar`);
23602
23648
  if (typeLineBtn) {
23603
- typeLineBtn.style.background = currentChartType === "line" ? "#3e1a7d" : "transparent";
23649
+ typeLineBtn.classList.toggle("active", currentChartType === "line");
23650
+ typeLineBtn.style.background = currentChartType === "line" ? activeColor : "transparent";
23604
23651
  typeLineBtn.style.color = currentChartType === "line" ? "white" : colors.text;
23605
23652
  }
23606
23653
  if (typeBarBtn) {
23607
- typeBarBtn.style.background = currentChartType === "bar" ? "#3e1a7d" : "transparent";
23654
+ typeBarBtn.classList.toggle("active", currentChartType === "bar");
23655
+ typeBarBtn.style.background = currentChartType === "bar" ? activeColor : "transparent";
23608
23656
  typeBarBtn.style.color = currentChartType === "bar" ? "white" : colors.text;
23609
23657
  }
23610
23658
  }
@@ -25503,12 +25551,589 @@ ${rangeText}`;
25503
25551
  var EXPORT_DOMAIN_LABELS = DOMAIN_LABELS;
25504
25552
  var EXPORT_DOMAIN_UNITS = DOMAIN_UNITS;
25505
25553
 
25554
+ // src/components/DistributionChart/colorManager.ts
25555
+ var DEFAULT_SHOPPING_COLORS = [
25556
+ "#3b82f6",
25557
+ // Blue
25558
+ "#8b5cf6",
25559
+ // Purple
25560
+ "#f59e0b",
25561
+ // Amber
25562
+ "#ef4444",
25563
+ // Red
25564
+ "#10b981",
25565
+ // Emerald
25566
+ "#06b6d4",
25567
+ // Cyan
25568
+ "#ec4899",
25569
+ // Pink
25570
+ "#14b8a6",
25571
+ // Teal
25572
+ "#f97316",
25573
+ // Orange
25574
+ "#a855f7"
25575
+ // Violet
25576
+ ];
25577
+ var DEFAULT_ENERGY_GROUP_COLORS = {
25578
+ "Elevadores": "#3b82f6",
25579
+ "Escadas Rolantes": "#8b5cf6",
25580
+ "Climatiza\xE7\xE3o": "#f59e0b",
25581
+ "Climatizacao": "#f59e0b",
25582
+ // Without accent
25583
+ "Outros Equipamentos": "#ef4444",
25584
+ "Lojas": "#10b981"
25585
+ };
25586
+ var DEFAULT_WATER_GROUP_COLORS = {
25587
+ "Lojas": "#10b981",
25588
+ "\xC1rea Comum": "#0288d1",
25589
+ "Area Comum": "#0288d1"
25590
+ // Without accent
25591
+ };
25592
+ var DEFAULT_GAS_GROUP_COLORS = {
25593
+ "Cozinha": "#f59e0b",
25594
+ "Aquecimento": "#ef4444",
25595
+ "Outros": "#94a3b8"
25596
+ };
25597
+ function getDefaultGroupColors(domain) {
25598
+ switch (domain.toLowerCase()) {
25599
+ case "energy":
25600
+ return DEFAULT_ENERGY_GROUP_COLORS;
25601
+ case "water":
25602
+ return DEFAULT_WATER_GROUP_COLORS;
25603
+ case "gas":
25604
+ return DEFAULT_GAS_GROUP_COLORS;
25605
+ default:
25606
+ return DEFAULT_ENERGY_GROUP_COLORS;
25607
+ }
25608
+ }
25609
+ function assignShoppingColors(shoppingIds) {
25610
+ const colors = {};
25611
+ shoppingIds.forEach((id, index) => {
25612
+ colors[id] = DEFAULT_SHOPPING_COLORS[index % DEFAULT_SHOPPING_COLORS.length];
25613
+ });
25614
+ return colors;
25615
+ }
25616
+ function getShoppingColor(shoppingId, shoppingColors, fallbackIndex = 0) {
25617
+ if (shoppingColors && shoppingColors[shoppingId]) {
25618
+ return shoppingColors[shoppingId];
25619
+ }
25620
+ if (shoppingColors) {
25621
+ const normalizedId = shoppingId.toLowerCase();
25622
+ for (const [key, color] of Object.entries(shoppingColors)) {
25623
+ if (key.toLowerCase() === normalizedId || key.toLowerCase().includes(normalizedId)) {
25624
+ return color;
25625
+ }
25626
+ }
25627
+ }
25628
+ return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
25629
+ }
25630
+ function getGroupColor(groupName, groupColors, domain = "energy", fallbackIndex = 0) {
25631
+ if (groupColors && groupColors[groupName]) {
25632
+ return groupColors[groupName];
25633
+ }
25634
+ const defaultColors = getDefaultGroupColors(domain);
25635
+ if (defaultColors[groupName]) {
25636
+ return defaultColors[groupName];
25637
+ }
25638
+ return DEFAULT_SHOPPING_COLORS[Math.abs(fallbackIndex) % DEFAULT_SHOPPING_COLORS.length];
25639
+ }
25640
+ function getThemeColors2(theme) {
25641
+ if (theme === "dark") {
25642
+ return {
25643
+ text: "#f3f4f6",
25644
+ secondaryText: "#9ca3af",
25645
+ background: "#111827",
25646
+ cardBackground: "#1f2937",
25647
+ border: "#374151",
25648
+ grid: "#374151"
25649
+ };
25650
+ }
25651
+ return {
25652
+ text: "#1f2937",
25653
+ secondaryText: "#6b7280",
25654
+ background: "#f5f5f5",
25655
+ cardBackground: "#ffffff",
25656
+ border: "#e5e7eb",
25657
+ grid: "#e5e7eb"
25658
+ };
25659
+ }
25660
+ function getHashColor(str) {
25661
+ let hash = 0;
25662
+ for (let i = 0; i < str.length; i++) {
25663
+ const char = str.charCodeAt(i);
25664
+ hash = (hash << 5) - hash + char;
25665
+ hash = hash & hash;
25666
+ }
25667
+ return DEFAULT_SHOPPING_COLORS[Math.abs(hash) % DEFAULT_SHOPPING_COLORS.length];
25668
+ }
25669
+
25670
+ // src/components/DistributionChart/createDistributionChartWidget.ts
25671
+ 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>`;
25672
+ 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>`;
25673
+ function createDistributionChartWidget(config) {
25674
+ const widgetId = `distribution-${config.domain}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
25675
+ let chartInstance = null;
25676
+ let currentMode = config.defaultMode || "groups";
25677
+ let currentTheme = config.theme || "light";
25678
+ let currentData = null;
25679
+ let containerElement = null;
25680
+ const title = config.title || getDomainTitle(config.domain);
25681
+ const chartHeight = config.chartHeight || 300;
25682
+ const showHeader = config.showHeader !== false;
25683
+ const showModeSelector = config.showModeSelector !== false;
25684
+ const showSettingsButton = config.showSettingsButton ?? false;
25685
+ const showMaximizeButton = config.showMaximizeButton ?? false;
25686
+ const decimalPlaces = config.decimalPlaces ?? 2;
25687
+ const modes = config.modes || getDefaultModes(config.domain);
25688
+ const groupColors = config.groupColors || getDefaultGroupColors(config.domain);
25689
+ function getDomainTitle(domain) {
25690
+ const titles = {
25691
+ energy: "Distribui\xE7\xE3o de Energia",
25692
+ water: "Distribui\xE7\xE3o de \xC1gua",
25693
+ gas: "Distribui\xE7\xE3o de G\xE1s",
25694
+ temperature: "Distribui\xE7\xE3o de Temperatura"
25695
+ };
25696
+ return titles[domain.toLowerCase()] || `Distribui\xE7\xE3o de ${domain}`;
25697
+ }
25698
+ function getDefaultModes(domain) {
25699
+ if (domain === "water") {
25700
+ return [
25701
+ { value: "groups", label: "Lojas vs \xC1rea Comum" },
25702
+ { value: "stores", label: "Lojas por Shopping" },
25703
+ { value: "common", label: "\xC1rea Comum por Shopping" }
25704
+ ];
25705
+ }
25706
+ return [
25707
+ { value: "groups", label: "Por Grupos de Equipamentos" },
25708
+ { value: "elevators", label: "Elevadores por Shopping" },
25709
+ { value: "escalators", label: "Escadas Rolantes por Shopping" },
25710
+ { value: "hvac", label: "Climatiza\xE7\xE3o por Shopping" },
25711
+ { value: "others", label: "Outros Equipamentos por Shopping" },
25712
+ { value: "stores", label: "Lojas por Shopping" }
25713
+ ];
25714
+ }
25715
+ function $id(id) {
25716
+ if (config.$container) {
25717
+ return config.$container[0].querySelector(`#${id}`);
25718
+ }
25719
+ return document.getElementById(id);
25720
+ }
25721
+ function formatValue(value) {
25722
+ if (config.unitLarge && config.thresholdForLargeUnit && value >= config.thresholdForLargeUnit) {
25723
+ return `${(value / config.thresholdForLargeUnit).toFixed(decimalPlaces)} ${config.unitLarge}`;
25724
+ }
25725
+ return `${value.toFixed(decimalPlaces)} ${config.unit}`;
25726
+ }
25727
+ function getColor(key, index, isGroupMode2) {
25728
+ if (isGroupMode2) {
25729
+ return getGroupColor(key, groupColors, config.domain, index);
25730
+ }
25731
+ const shoppingColors = config.getShoppingColors?.();
25732
+ return getShoppingColor(key, shoppingColors, index);
25733
+ }
25734
+ function getColors2() {
25735
+ return getThemeColors2(currentTheme);
25736
+ }
25737
+ function isGroupMode() {
25738
+ return currentMode === "groups";
25739
+ }
25740
+ function renderHTML() {
25741
+ const colors = getColors2();
25742
+ const modeOptions = modes.map(
25743
+ (m) => `<option value="${m.value}" ${m.value === currentMode ? "selected" : ""}>${m.label}</option>`
25744
+ ).join("");
25745
+ const headerButtons = [];
25746
+ if (showSettingsButton) {
25747
+ headerButtons.push(`
25748
+ <button id="${widgetId}-settings-btn" class="myio-dist-btn" title="Configura\xE7\xF5es">
25749
+ ${settingsIcon}
25750
+ </button>
25751
+ `);
25752
+ }
25753
+ if (showMaximizeButton) {
25754
+ headerButtons.push(`
25755
+ <button id="${widgetId}-maximize-btn" class="myio-dist-btn" title="Expandir">
25756
+ ${maximizeIcon}
25757
+ </button>
25758
+ `);
25759
+ }
25760
+ return `
25761
+ <style>
25762
+ #${widgetId} {
25763
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
25764
+ }
25765
+ #${widgetId} .myio-dist-header {
25766
+ display: flex;
25767
+ justify-content: space-between;
25768
+ align-items: center;
25769
+ margin-bottom: 16px;
25770
+ flex-wrap: wrap;
25771
+ gap: 12px;
25772
+ }
25773
+ #${widgetId} .myio-dist-title {
25774
+ margin: 0;
25775
+ font-size: 16px;
25776
+ font-weight: 600;
25777
+ color: ${colors.text};
25778
+ }
25779
+ #${widgetId} .myio-dist-controls {
25780
+ display: flex;
25781
+ align-items: center;
25782
+ gap: 8px;
25783
+ }
25784
+ #${widgetId} .myio-dist-label {
25785
+ font-size: 12px;
25786
+ color: ${colors.secondaryText};
25787
+ }
25788
+ #${widgetId} .myio-dist-select {
25789
+ padding: 6px 10px;
25790
+ border-radius: 6px;
25791
+ border: 1px solid ${colors.border};
25792
+ background: ${colors.cardBackground};
25793
+ color: ${colors.text};
25794
+ font-size: 12px;
25795
+ cursor: pointer;
25796
+ min-width: 180px;
25797
+ }
25798
+ #${widgetId} .myio-dist-select:focus {
25799
+ outline: none;
25800
+ border-color: #3e1a7d;
25801
+ }
25802
+ #${widgetId} .myio-dist-btn {
25803
+ display: flex;
25804
+ align-items: center;
25805
+ justify-content: center;
25806
+ padding: 6px 8px;
25807
+ border: 1px solid ${colors.border};
25808
+ border-radius: 6px;
25809
+ background: transparent;
25810
+ color: ${colors.text};
25811
+ cursor: pointer;
25812
+ transition: all 0.2s;
25813
+ }
25814
+ #${widgetId} .myio-dist-btn:hover {
25815
+ background: #3e1a7d;
25816
+ border-color: #3e1a7d;
25817
+ color: white;
25818
+ }
25819
+ #${widgetId} .myio-dist-chart-container {
25820
+ position: relative;
25821
+ height: ${chartHeight}px;
25822
+ }
25823
+ #${widgetId} .myio-dist-loading {
25824
+ position: absolute;
25825
+ top: 0;
25826
+ left: 0;
25827
+ right: 0;
25828
+ bottom: 0;
25829
+ display: flex;
25830
+ align-items: center;
25831
+ justify-content: center;
25832
+ background: ${colors.cardBackground}ee;
25833
+ z-index: 10;
25834
+ }
25835
+ #${widgetId} .myio-dist-spinner {
25836
+ width: 32px;
25837
+ height: 32px;
25838
+ border: 3px solid ${colors.border};
25839
+ border-top-color: #3e1a7d;
25840
+ border-radius: 50%;
25841
+ animation: myio-dist-spin 0.8s linear infinite;
25842
+ }
25843
+ @keyframes myio-dist-spin {
25844
+ to { transform: rotate(360deg); }
25845
+ }
25846
+ #${widgetId} .myio-dist-empty {
25847
+ display: flex;
25848
+ flex-direction: column;
25849
+ align-items: center;
25850
+ justify-content: center;
25851
+ height: 100%;
25852
+ color: ${colors.secondaryText};
25853
+ font-size: 14px;
25854
+ }
25855
+ #${widgetId} .myio-dist-empty-icon {
25856
+ font-size: 48px;
25857
+ margin-bottom: 12px;
25858
+ opacity: 0.5;
25859
+ }
25860
+ </style>
25861
+
25862
+ <div id="${widgetId}" class="myio-distribution-widget" style="
25863
+ background: ${colors.cardBackground};
25864
+ border-radius: 12px;
25865
+ padding: 16px;
25866
+ height: 100%;
25867
+ display: flex;
25868
+ flex-direction: column;
25869
+ ">
25870
+ ${showHeader ? `
25871
+ <div class="myio-dist-header">
25872
+ <h4 class="myio-dist-title">${title}</h4>
25873
+ <div class="myio-dist-controls">
25874
+ ${showModeSelector && modes.length > 1 ? `
25875
+ <label for="${widgetId}-mode" class="myio-dist-label">Visualizar:</label>
25876
+ <select id="${widgetId}-mode" class="myio-dist-select">
25877
+ ${modeOptions}
25878
+ </select>
25879
+ ` : ""}
25880
+ ${headerButtons.join("")}
25881
+ </div>
25882
+ </div>
25883
+ ` : ""}
25884
+
25885
+ <div class="myio-dist-chart-container">
25886
+ <canvas id="${widgetId}-canvas"></canvas>
25887
+ <div id="${widgetId}-loading" class="myio-dist-loading" style="display: none;">
25888
+ <div class="myio-dist-spinner"></div>
25889
+ </div>
25890
+ </div>
25891
+ </div>
25892
+ `;
25893
+ }
25894
+ function setLoading(loading) {
25895
+ const loadingEl = $id(`${widgetId}-loading`);
25896
+ if (loadingEl) {
25897
+ loadingEl.style.display = loading ? "flex" : "none";
25898
+ }
25899
+ }
25900
+ function buildChartData(distribution) {
25901
+ const labels = [];
25902
+ const data = [];
25903
+ const backgroundColors = [];
25904
+ const total = Object.values(distribution).reduce((sum, val) => sum + val, 0);
25905
+ const isGroup = isGroupMode();
25906
+ const entries = Object.entries(distribution).filter(([_, value]) => value > 0).sort((a, b) => b[1] - a[1]);
25907
+ entries.forEach(([key, value], index) => {
25908
+ const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
25909
+ labels.push(`${key} (${formatValue(value)} - ${percentage}%)`);
25910
+ data.push(value);
25911
+ backgroundColors.push(getColor(key, index, isGroup));
25912
+ });
25913
+ return { labels, data, backgroundColors, total };
25914
+ }
25915
+ function renderEmptyState() {
25916
+ const container = $id(`${widgetId}-canvas`)?.parentElement;
25917
+ if (container) {
25918
+ const emptyEl = document.createElement("div");
25919
+ emptyEl.className = "myio-dist-empty";
25920
+ emptyEl.innerHTML = `
25921
+ <div class="myio-dist-empty-icon">\u{1F4CA}</div>
25922
+ <div>Sem dados dispon\xEDveis</div>
25923
+ `;
25924
+ const canvas = $id(`${widgetId}-canvas`);
25925
+ if (canvas) canvas.style.display = "none";
25926
+ const existingEmpty = container.querySelector(".myio-dist-empty");
25927
+ if (!existingEmpty) {
25928
+ container.appendChild(emptyEl);
25929
+ }
25930
+ }
25931
+ }
25932
+ function removeEmptyState() {
25933
+ const container = $id(`${widgetId}-canvas`)?.parentElement;
25934
+ if (container) {
25935
+ const emptyEl = container.querySelector(".myio-dist-empty");
25936
+ if (emptyEl) emptyEl.remove();
25937
+ const canvas = $id(`${widgetId}-canvas`);
25938
+ if (canvas) canvas.style.display = "block";
25939
+ }
25940
+ }
25941
+ async function updateChart() {
25942
+ const canvas = $id(`${widgetId}-canvas`);
25943
+ if (!canvas) {
25944
+ console.error(`[${config.domain.toUpperCase()}] Distribution canvas not found`);
25945
+ return;
25946
+ }
25947
+ setLoading(true);
25948
+ try {
25949
+ const distribution = await config.fetchDistribution(currentMode);
25950
+ if (!distribution || Object.keys(distribution).length === 0) {
25951
+ console.warn(`[${config.domain.toUpperCase()}] No distribution data for mode: ${currentMode}`);
25952
+ currentData = null;
25953
+ setLoading(false);
25954
+ renderEmptyState();
25955
+ return;
25956
+ }
25957
+ removeEmptyState();
25958
+ currentData = distribution;
25959
+ const { labels, data, backgroundColors, total } = buildChartData(distribution);
25960
+ const colors = getColors2();
25961
+ const Chart2 = window.Chart;
25962
+ if (!Chart2) {
25963
+ throw new Error("Chart.js not loaded");
25964
+ }
25965
+ if (chartInstance) {
25966
+ chartInstance.destroy();
25967
+ chartInstance = null;
25968
+ }
25969
+ const ctx = canvas.getContext("2d");
25970
+ if (!ctx) {
25971
+ throw new Error("Could not get canvas context");
25972
+ }
25973
+ chartInstance = new Chart2(ctx, {
25974
+ type: "bar",
25975
+ data: {
25976
+ labels,
25977
+ datasets: [
25978
+ {
25979
+ label: `Consumo (${config.unit})`,
25980
+ data,
25981
+ backgroundColor: backgroundColors
25982
+ }
25983
+ ]
25984
+ },
25985
+ options: {
25986
+ responsive: true,
25987
+ maintainAspectRatio: false,
25988
+ indexAxis: "y",
25989
+ // Horizontal bar chart
25990
+ animation: false,
25991
+ plugins: {
25992
+ legend: { display: false },
25993
+ tooltip: {
25994
+ callbacks: {
25995
+ label: (context) => {
25996
+ const value = context.parsed.x || 0;
25997
+ const percentage = total > 0 ? (value / total * 100).toFixed(1) : "0";
25998
+ return `${formatValue(value)} (${percentage}%)`;
25999
+ }
26000
+ }
26001
+ }
26002
+ },
26003
+ scales: {
26004
+ x: {
26005
+ beginAtZero: true,
26006
+ ticks: {
26007
+ callback: (value) => formatValue(Number(value)),
26008
+ color: colors.secondaryText,
26009
+ font: { size: 11 }
26010
+ },
26011
+ grid: { color: colors.grid }
26012
+ },
26013
+ y: {
26014
+ ticks: {
26015
+ font: { size: 11 },
26016
+ color: colors.text
26017
+ },
26018
+ grid: { display: false }
26019
+ }
26020
+ }
26021
+ }
26022
+ });
26023
+ config.onDataLoaded?.(distribution);
26024
+ console.log(`[${config.domain.toUpperCase()}] Distribution chart updated for mode: ${currentMode}`);
26025
+ } catch (error) {
26026
+ console.error(`[${config.domain.toUpperCase()}] Error updating distribution chart:`, error);
26027
+ config.onError?.(error);
26028
+ renderEmptyState();
26029
+ } finally {
26030
+ setLoading(false);
26031
+ }
26032
+ }
26033
+ function setupListeners() {
26034
+ const modeSelect = $id(`${widgetId}-mode`);
26035
+ if (modeSelect) {
26036
+ modeSelect.addEventListener("change", async (e) => {
26037
+ currentMode = e.target.value;
26038
+ config.onModeChange?.(currentMode);
26039
+ await updateChart();
26040
+ });
26041
+ }
26042
+ if (showSettingsButton) {
26043
+ const settingsBtn = $id(`${widgetId}-settings-btn`);
26044
+ if (settingsBtn) {
26045
+ settingsBtn.addEventListener("click", () => {
26046
+ config.onSettingsClick?.();
26047
+ });
26048
+ }
26049
+ }
26050
+ if (showMaximizeButton) {
26051
+ const maximizeBtn = $id(`${widgetId}-maximize-btn`);
26052
+ if (maximizeBtn) {
26053
+ maximizeBtn.addEventListener("click", () => {
26054
+ config.onMaximizeClick?.();
26055
+ });
26056
+ }
26057
+ }
26058
+ }
26059
+ function updateThemeStyles() {
26060
+ const colors = getColors2();
26061
+ const widget = $id(widgetId);
26062
+ if (widget) {
26063
+ widget.style.background = colors.cardBackground;
26064
+ const title2 = widget.querySelector(".myio-dist-title");
26065
+ if (title2) title2.style.color = colors.text;
26066
+ const labels = widget.querySelectorAll(".myio-dist-label");
26067
+ labels.forEach((l) => l.style.color = colors.secondaryText);
26068
+ const select = widget.querySelector(".myio-dist-select");
26069
+ if (select) {
26070
+ select.style.background = colors.cardBackground;
26071
+ select.style.color = colors.text;
26072
+ select.style.borderColor = colors.border;
26073
+ }
26074
+ const buttons = widget.querySelectorAll(".myio-dist-btn");
26075
+ buttons.forEach((b) => {
26076
+ b.style.color = colors.text;
26077
+ b.style.borderColor = colors.border;
26078
+ });
26079
+ }
26080
+ }
26081
+ const instance = {
26082
+ async render() {
26083
+ containerElement = $id(config.containerId);
26084
+ if (!containerElement) {
26085
+ throw new Error(`Container #${config.containerId} not found`);
26086
+ }
26087
+ containerElement.innerHTML = renderHTML();
26088
+ setupListeners();
26089
+ await updateChart();
26090
+ },
26091
+ async setMode(mode) {
26092
+ currentMode = mode;
26093
+ const modeSelect = $id(`${widgetId}-mode`);
26094
+ if (modeSelect) {
26095
+ modeSelect.value = mode;
26096
+ }
26097
+ config.onModeChange?.(mode);
26098
+ await updateChart();
26099
+ },
26100
+ async refresh() {
26101
+ await updateChart();
26102
+ },
26103
+ setTheme(theme) {
26104
+ currentTheme = theme;
26105
+ updateThemeStyles();
26106
+ if (currentData) {
26107
+ updateChart();
26108
+ }
26109
+ },
26110
+ destroy() {
26111
+ if (chartInstance) {
26112
+ chartInstance.destroy();
26113
+ chartInstance = null;
26114
+ }
26115
+ if (containerElement) {
26116
+ containerElement.innerHTML = "";
26117
+ }
26118
+ currentData = null;
26119
+ },
26120
+ getChartInstance: () => chartInstance,
26121
+ getCurrentMode: () => currentMode,
26122
+ getCurrentData: () => currentData
26123
+ };
26124
+ return instance;
26125
+ }
26126
+
25506
26127
  exports.CHART_COLORS = CHART_COLORS;
25507
26128
  exports.CONSUMPTION_CHART_COLORS = DEFAULT_COLORS;
25508
26129
  exports.CONSUMPTION_CHART_DEFAULTS = DEFAULT_CONFIG;
25509
26130
  exports.CONSUMPTION_THEME_COLORS = THEME_COLORS;
25510
26131
  exports.ConnectionStatusType = ConnectionStatusType;
25511
26132
  exports.DEFAULT_CLAMP_RANGE = DEFAULT_CLAMP_RANGE;
26133
+ exports.DEFAULT_ENERGY_GROUP_COLORS = DEFAULT_ENERGY_GROUP_COLORS;
26134
+ exports.DEFAULT_GAS_GROUP_COLORS = DEFAULT_GAS_GROUP_COLORS;
26135
+ exports.DEFAULT_SHOPPING_COLORS = DEFAULT_SHOPPING_COLORS;
26136
+ exports.DEFAULT_WATER_GROUP_COLORS = DEFAULT_WATER_GROUP_COLORS;
25512
26137
  exports.DeviceStatusType = DeviceStatusType;
25513
26138
  exports.EXPORT_DEFAULT_COLORS = EXPORT_DEFAULT_COLORS;
25514
26139
  exports.EXPORT_DOMAIN_ICONS = EXPORT_DOMAIN_ICONS;
@@ -25521,6 +26146,7 @@ ${rangeText}`;
25521
26146
  exports.addDetectionContext = addDetectionContext;
25522
26147
  exports.addNamespace = addNamespace;
25523
26148
  exports.aggregateByDay = aggregateByDay;
26149
+ exports.assignShoppingColors = assignShoppingColors;
25524
26150
  exports.averageByDay = averageByDay;
25525
26151
  exports.buildListItemsThingsboardByUniqueDatasource = buildListItemsThingsboardByUniqueDatasource;
25526
26152
  exports.buildMyioIngestionAuth = buildMyioIngestionAuth;
@@ -25542,6 +26168,7 @@ ${rangeText}`;
25542
26168
  exports.createConsumptionChartWidget = createConsumptionChartWidget;
25543
26169
  exports.createConsumptionModal = createConsumptionModal;
25544
26170
  exports.createDateRangePicker = createDateRangePicker2;
26171
+ exports.createDistributionChartWidget = createDistributionChartWidget;
25545
26172
  exports.createInputDateRangePickerInsideDIV = createInputDateRangePickerInsideDIV;
25546
26173
  exports.createModalHeader = createModalHeader;
25547
26174
  exports.decodePayload = decodePayload;
@@ -25580,11 +26207,16 @@ ${rangeText}`;
25580
26207
  exports.getAvailableContexts = getAvailableContexts;
25581
26208
  exports.getConnectionStatusIcon = getConnectionStatusIcon;
25582
26209
  exports.getDateRangeArray = getDateRangeArray;
26210
+ exports.getDefaultGroupColors = getDefaultGroupColors;
25583
26211
  exports.getDeviceStatusIcon = getDeviceStatusIcon;
25584
26212
  exports.getDeviceStatusInfo = getDeviceStatusInfo;
26213
+ exports.getDistributionThemeColors = getThemeColors2;
26214
+ exports.getGroupColor = getGroupColor;
26215
+ exports.getHashColor = getHashColor;
25585
26216
  exports.getModalHeaderStyles = getModalHeaderStyles;
25586
26217
  exports.getSaoPauloISOString = getSaoPauloISOString;
25587
26218
  exports.getSaoPauloISOStringFixed = getSaoPauloISOStringFixed;
26219
+ exports.getShoppingColor = getShoppingColor;
25588
26220
  exports.getValueByDatakey = getValueByDatakey;
25589
26221
  exports.getValueByDatakeyLegacy = getValueByDatakeyLegacy;
25590
26222
  exports.getWaterCategories = getWaterCategories;