myio-js-library 0.1.164 → 0.1.165
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 +181 -38
- package/dist/index.js +181 -38
- package/dist/myio-js-library.umd.js +181 -38
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20657,7 +20657,7 @@ function renderModal(container, state, modalId, error) {
|
|
|
20657
20657
|
const contentMaxHeight = isMaximized ? "100vh" : "95vh";
|
|
20658
20658
|
const contentBorderRadius = isMaximized ? "0" : "10px";
|
|
20659
20659
|
container.innerHTML = `
|
|
20660
|
-
<div class="myio-temp-modal-overlay" style="
|
|
20660
|
+
<div class="myio-temp-modal-overlay myio-modal-scope" style="
|
|
20661
20661
|
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
|
20662
20662
|
background: rgba(0, 0, 0, 0.5); z-index: 9998;
|
|
20663
20663
|
display: flex; justify-content: center; align-items: center;
|
|
@@ -20912,6 +20912,22 @@ function renderModal(container, state, modalId, error) {
|
|
|
20912
20912
|
background: rgba(255, 255, 255, 0.1) !important;
|
|
20913
20913
|
color: white !important;
|
|
20914
20914
|
}
|
|
20915
|
+
|
|
20916
|
+
/* DateRangePicker styles */
|
|
20917
|
+
${CSS_TOKENS}
|
|
20918
|
+
${DATERANGEPICKER_STYLES}
|
|
20919
|
+
|
|
20920
|
+
/* Fix DateRangePicker buttons alignment */
|
|
20921
|
+
.myio-modal-scope .daterangepicker .drp-buttons {
|
|
20922
|
+
display: flex;
|
|
20923
|
+
justify-content: flex-end;
|
|
20924
|
+
align-items: center;
|
|
20925
|
+
gap: 8px;
|
|
20926
|
+
}
|
|
20927
|
+
.myio-modal-scope .daterangepicker .drp-buttons .btn {
|
|
20928
|
+
display: inline-block;
|
|
20929
|
+
margin-left: 0;
|
|
20930
|
+
}
|
|
20915
20931
|
</style>
|
|
20916
20932
|
`;
|
|
20917
20933
|
}
|
|
@@ -24026,18 +24042,11 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24026
24042
|
|
|
24027
24043
|
.myio-chart-widget-title {
|
|
24028
24044
|
margin: 0;
|
|
24029
|
-
font-size:
|
|
24045
|
+
font-size: 14px;
|
|
24030
24046
|
font-weight: 600;
|
|
24031
24047
|
color: ${colors.text};
|
|
24032
24048
|
}
|
|
24033
24049
|
|
|
24034
|
-
.myio-chart-widget-controls {
|
|
24035
|
-
display: flex;
|
|
24036
|
-
align-items: center;
|
|
24037
|
-
gap: 12px;
|
|
24038
|
-
flex-wrap: wrap;
|
|
24039
|
-
}
|
|
24040
|
-
|
|
24041
24050
|
.myio-chart-widget-tabs {
|
|
24042
24051
|
display: flex;
|
|
24043
24052
|
gap: 2px;
|
|
@@ -24057,6 +24066,20 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24057
24066
|
border-radius: 6px;
|
|
24058
24067
|
transition: all 0.2s;
|
|
24059
24068
|
white-space: nowrap;
|
|
24069
|
+
display: flex;
|
|
24070
|
+
align-items: center;
|
|
24071
|
+
justify-content: center;
|
|
24072
|
+
gap: 4px;
|
|
24073
|
+
}
|
|
24074
|
+
|
|
24075
|
+
.myio-chart-widget-tab.icon-only {
|
|
24076
|
+
padding: 6px 10px;
|
|
24077
|
+
}
|
|
24078
|
+
|
|
24079
|
+
.myio-chart-widget-tab svg {
|
|
24080
|
+
width: 16px;
|
|
24081
|
+
height: 16px;
|
|
24082
|
+
pointer-events: none;
|
|
24060
24083
|
}
|
|
24061
24084
|
|
|
24062
24085
|
.myio-chart-widget-tab:hover {
|
|
@@ -24190,7 +24213,7 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24190
24213
|
background: ${colors.chartBackground};
|
|
24191
24214
|
border-radius: 10px;
|
|
24192
24215
|
width: 90%;
|
|
24193
|
-
max-width:
|
|
24216
|
+
max-width: 860px;
|
|
24194
24217
|
max-height: 90vh;
|
|
24195
24218
|
display: flex;
|
|
24196
24219
|
flex-direction: column;
|
|
@@ -24207,7 +24230,7 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24207
24230
|
overflow-y: auto;
|
|
24208
24231
|
display: flex;
|
|
24209
24232
|
flex-direction: column;
|
|
24210
|
-
gap:
|
|
24233
|
+
gap: 12px;
|
|
24211
24234
|
}
|
|
24212
24235
|
|
|
24213
24236
|
.myio-settings-section {
|
|
@@ -24250,10 +24273,10 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24250
24273
|
|
|
24251
24274
|
.myio-settings-input,
|
|
24252
24275
|
.myio-settings-select {
|
|
24253
|
-
padding:
|
|
24276
|
+
padding: 8px 12px;
|
|
24254
24277
|
border: 1px solid ${colors.border};
|
|
24255
24278
|
border-radius: 8px;
|
|
24256
|
-
font-size:
|
|
24279
|
+
font-size: 12px;
|
|
24257
24280
|
background: ${colors.chartBackground};
|
|
24258
24281
|
color: ${colors.text};
|
|
24259
24282
|
width: 100%;
|
|
@@ -24285,6 +24308,10 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24285
24308
|
border-radius: 6px;
|
|
24286
24309
|
transition: all 0.2s;
|
|
24287
24310
|
white-space: nowrap;
|
|
24311
|
+
display: flex;
|
|
24312
|
+
align-items: center;
|
|
24313
|
+
justify-content: center;
|
|
24314
|
+
gap: 6px;
|
|
24288
24315
|
}
|
|
24289
24316
|
|
|
24290
24317
|
.myio-settings-tab:hover {
|
|
@@ -24342,13 +24369,17 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24342
24369
|
}
|
|
24343
24370
|
|
|
24344
24371
|
.myio-settings-context-group {
|
|
24345
|
-
margin-bottom:
|
|
24372
|
+
margin-bottom: 12px;
|
|
24346
24373
|
}
|
|
24347
24374
|
|
|
24348
24375
|
.myio-settings-context-group:last-child {
|
|
24349
24376
|
margin-bottom: 0;
|
|
24350
24377
|
}
|
|
24351
24378
|
|
|
24379
|
+
.myio-settings-section + .myio-settings-section {
|
|
24380
|
+
margin-top: 12px;
|
|
24381
|
+
}
|
|
24382
|
+
|
|
24352
24383
|
/* Dropdown styles */
|
|
24353
24384
|
.myio-settings-dropdown-container {
|
|
24354
24385
|
position: relative;
|
|
@@ -24452,6 +24483,23 @@ function getWidgetStyles(theme, primaryColor) {
|
|
|
24452
24483
|
opacity: 1 !important;
|
|
24453
24484
|
transform: scale(1.2);
|
|
24454
24485
|
}
|
|
24486
|
+
|
|
24487
|
+
/* DateRangePicker styles (CSS tokens + premium styling) */
|
|
24488
|
+
${CSS_TOKENS}
|
|
24489
|
+
${DATERANGEPICKER_STYLES}
|
|
24490
|
+
|
|
24491
|
+
/* Fix DateRangePicker buttons alignment */
|
|
24492
|
+
.myio-modal-scope .daterangepicker .drp-buttons {
|
|
24493
|
+
display: flex;
|
|
24494
|
+
justify-content: flex-end;
|
|
24495
|
+
align-items: center;
|
|
24496
|
+
gap: 8px;
|
|
24497
|
+
}
|
|
24498
|
+
|
|
24499
|
+
.myio-modal-scope .daterangepicker .drp-buttons .btn {
|
|
24500
|
+
display: inline-block;
|
|
24501
|
+
margin-left: 0;
|
|
24502
|
+
}
|
|
24455
24503
|
`;
|
|
24456
24504
|
}
|
|
24457
24505
|
function createConsumptionChartWidget(config) {
|
|
@@ -24461,6 +24509,7 @@ function createConsumptionChartWidget(config) {
|
|
|
24461
24509
|
let styleElement = null;
|
|
24462
24510
|
let settingsModalElement = null;
|
|
24463
24511
|
let settingsHeaderInstance = null;
|
|
24512
|
+
let dateRangePickerInstance = null;
|
|
24464
24513
|
let currentTheme = config.theme ?? "light";
|
|
24465
24514
|
let currentChartType = config.defaultChartType ?? "line";
|
|
24466
24515
|
let currentVizMode = config.defaultVizMode ?? "total";
|
|
@@ -24472,6 +24521,8 @@ function createConsumptionChartWidget(config) {
|
|
|
24472
24521
|
let tempVizMode = currentVizMode;
|
|
24473
24522
|
let tempTheme = currentTheme;
|
|
24474
24523
|
let tempIdealRange = currentIdealRange;
|
|
24524
|
+
let tempStartDate = null;
|
|
24525
|
+
let tempEndDate = null;
|
|
24475
24526
|
let currentSuggestion = null;
|
|
24476
24527
|
const domainCfg = DOMAIN_CONFIG4[config.domain] || DOMAIN_CONFIG4.energy;
|
|
24477
24528
|
const primaryColor = config.colors?.primary || domainCfg.color;
|
|
@@ -24487,6 +24538,10 @@ function createConsumptionChartWidget(config) {
|
|
|
24487
24538
|
return `${domainName} dos \xFAltimos ${currentPeriod} dias`;
|
|
24488
24539
|
}
|
|
24489
24540
|
function renderHTML() {
|
|
24541
|
+
const consolidadoIcon = `<svg viewBox="0 0 16 16" fill="currentColor"><rect x="3" y="3" width="10" height="10" rx="2"/></svg>`;
|
|
24542
|
+
const porShoppingIcon = `<svg viewBox="0 0 16 16" fill="currentColor"><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>`;
|
|
24543
|
+
const lineChartIcon = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="2,12 5,7 9,9 14,3"/></svg>`;
|
|
24544
|
+
const barChartIcon = `<svg viewBox="0 0 16 16" fill="currentColor"><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>`;
|
|
24490
24545
|
return `
|
|
24491
24546
|
<div id="${widgetId}" class="myio-chart-widget ${currentTheme === "dark" ? "dark" : ""} ${config.className || ""}">
|
|
24492
24547
|
<div class="myio-chart-widget-header">
|
|
@@ -24495,18 +24550,16 @@ function createConsumptionChartWidget(config) {
|
|
|
24495
24550
|
<button id="${widgetId}-settings-btn" class="myio-chart-widget-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
|
|
24496
24551
|
` : ""}
|
|
24497
24552
|
<h4 id="${widgetId}-title" class="myio-chart-widget-title">${getTitle()}</h4>
|
|
24498
|
-
</div>
|
|
24499
|
-
<div class="myio-chart-widget-controls">
|
|
24500
24553
|
${showVizModeTabs ? `
|
|
24501
24554
|
<div class="myio-chart-widget-tabs" id="${widgetId}-viz-tabs">
|
|
24502
|
-
<button class="myio-chart-widget-tab ${currentVizMode === "total" ? "active" : ""}" data-viz="total"
|
|
24503
|
-
<button class="myio-chart-widget-tab ${currentVizMode === "separate" ? "active" : ""}" data-viz="separate"
|
|
24555
|
+
<button class="myio-chart-widget-tab icon-only ${currentVizMode === "total" ? "active" : ""}" data-viz="total" title="Consolidado">${consolidadoIcon}</button>
|
|
24556
|
+
<button class="myio-chart-widget-tab icon-only ${currentVizMode === "separate" ? "active" : ""}" data-viz="separate" title="Por Shopping">${porShoppingIcon}</button>
|
|
24504
24557
|
</div>
|
|
24505
24558
|
` : ""}
|
|
24506
24559
|
${showChartTypeTabs ? `
|
|
24507
24560
|
<div class="myio-chart-widget-tabs" id="${widgetId}-type-tabs">
|
|
24508
|
-
<button class="myio-chart-widget-tab ${currentChartType === "line" ? "active" : ""}" data-type="line"
|
|
24509
|
-
<button class="myio-chart-widget-tab ${currentChartType === "bar" ? "active" : ""}" data-type="bar"
|
|
24561
|
+
<button class="myio-chart-widget-tab icon-only ${currentChartType === "line" ? "active" : ""}" data-type="line" title="Gr\xE1fico de Linhas">${lineChartIcon}</button>
|
|
24562
|
+
<button class="myio-chart-widget-tab icon-only ${currentChartType === "bar" ? "active" : ""}" data-type="bar" title="Gr\xE1fico de Barras">${barChartIcon}</button>
|
|
24510
24563
|
</div>
|
|
24511
24564
|
` : ""}
|
|
24512
24565
|
${showMaximizeButton ? `
|
|
@@ -24543,19 +24596,22 @@ function createConsumptionChartWidget(config) {
|
|
|
24543
24596
|
function renderSettingsModal() {
|
|
24544
24597
|
const unit = config.unit ?? "";
|
|
24545
24598
|
const isTemperature = config.domain === "temperature";
|
|
24599
|
+
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>`;
|
|
24600
|
+
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>`;
|
|
24601
|
+
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>`;
|
|
24602
|
+
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>`;
|
|
24546
24603
|
settingsHeaderInstance = createModalHeader({
|
|
24547
24604
|
id: `${widgetId}-settings`,
|
|
24548
24605
|
title: "Configura\xE7\xF5es",
|
|
24549
24606
|
icon: "\u2699\uFE0F",
|
|
24550
24607
|
theme: tempTheme,
|
|
24551
|
-
backgroundColor: primaryColor,
|
|
24552
24608
|
showThemeToggle: false,
|
|
24553
24609
|
showMaximize: false,
|
|
24554
24610
|
showClose: true,
|
|
24555
24611
|
onClose: () => closeSettingsModal()
|
|
24556
24612
|
});
|
|
24557
24613
|
return `
|
|
24558
|
-
<div id="${widgetId}-settings-overlay" class="myio-settings-overlay hidden">
|
|
24614
|
+
<div id="${widgetId}-settings-overlay" class="myio-settings-overlay myio-modal-scope hidden">
|
|
24559
24615
|
<div class="myio-settings-card">
|
|
24560
24616
|
${settingsHeaderInstance.render()}
|
|
24561
24617
|
<div class="myio-settings-body">
|
|
@@ -24566,13 +24622,8 @@ function createConsumptionChartWidget(config) {
|
|
|
24566
24622
|
<div class="myio-settings-section-label">\u{1F4C5} Per\xEDodo</div>
|
|
24567
24623
|
<div class="myio-settings-row">
|
|
24568
24624
|
<div class="myio-settings-field" style="flex: 1;">
|
|
24569
|
-
<
|
|
24570
|
-
|
|
24571
|
-
<option value="14" ${tempPeriod === 14 ? "selected" : ""}>\xDAltimos 14 dias</option>
|
|
24572
|
-
<option value="30" ${tempPeriod === 30 ? "selected" : ""}>\xDAltimos 30 dias</option>
|
|
24573
|
-
<option value="60" ${tempPeriod === 60 ? "selected" : ""}>\xDAltimos 60 dias</option>
|
|
24574
|
-
<option value="90" ${tempPeriod === 90 ? "selected" : ""}>\xDAltimos 90 dias</option>
|
|
24575
|
-
</select>
|
|
24625
|
+
<input type="text" id="${widgetId}-settings-daterange" class="myio-settings-input"
|
|
24626
|
+
readonly placeholder="Selecione o per\xEDodo..." style="cursor: pointer;">
|
|
24576
24627
|
</div>
|
|
24577
24628
|
</div>
|
|
24578
24629
|
</div>
|
|
@@ -24701,8 +24752,8 @@ function createConsumptionChartWidget(config) {
|
|
|
24701
24752
|
<div class="myio-settings-field" style="flex: 1; min-width: 180px;">
|
|
24702
24753
|
<label class="myio-settings-field-label">Tipo de Gr\xE1fico</label>
|
|
24703
24754
|
<div class="myio-settings-tabs" id="${widgetId}-settings-chart-type">
|
|
24704
|
-
<button class="myio-settings-tab ${tempChartType === "line" ? "active" : ""}" data-type="line"
|
|
24705
|
-
<button class="myio-settings-tab ${tempChartType === "bar" ? "active" : ""}" data-type="bar"
|
|
24755
|
+
<button class="myio-settings-tab ${tempChartType === "line" ? "active" : ""}" data-type="line">${lineChartIcon} Linhas</button>
|
|
24756
|
+
<button class="myio-settings-tab ${tempChartType === "bar" ? "active" : ""}" data-type="bar">${barChartIcon} Barras</button>
|
|
24706
24757
|
</div>
|
|
24707
24758
|
</div>
|
|
24708
24759
|
|
|
@@ -24710,8 +24761,8 @@ function createConsumptionChartWidget(config) {
|
|
|
24710
24761
|
<div class="myio-settings-field" style="flex: 1; min-width: 200px;">
|
|
24711
24762
|
<label class="myio-settings-field-label">Agrupamento</label>
|
|
24712
24763
|
<div class="myio-settings-tabs" id="${widgetId}-settings-viz-mode">
|
|
24713
|
-
<button class="myio-settings-tab ${tempVizMode === "total" ? "active" : ""}" data-viz="total"
|
|
24714
|
-
<button class="myio-settings-tab ${tempVizMode === "separate" ? "active" : ""}" data-viz="separate"
|
|
24764
|
+
<button class="myio-settings-tab ${tempVizMode === "total" ? "active" : ""}" data-viz="total">${consolidadoIcon} Consolidado</button>
|
|
24765
|
+
<button class="myio-settings-tab ${tempVizMode === "separate" ? "active" : ""}" data-viz="separate">${porShoppingIcon} Por Shopping</button>
|
|
24715
24766
|
</div>
|
|
24716
24767
|
</div>
|
|
24717
24768
|
|
|
@@ -24853,18 +24904,21 @@ function createConsumptionChartWidget(config) {
|
|
|
24853
24904
|
peakDateEl.textContent = peakDate;
|
|
24854
24905
|
}
|
|
24855
24906
|
}
|
|
24856
|
-
function openSettingsModal() {
|
|
24907
|
+
async function openSettingsModal() {
|
|
24857
24908
|
tempPeriod = currentPeriod;
|
|
24858
24909
|
tempChartType = currentChartType;
|
|
24859
24910
|
tempVizMode = currentVizMode;
|
|
24860
24911
|
tempTheme = currentTheme;
|
|
24861
24912
|
tempIdealRange = currentIdealRange ? { ...currentIdealRange } : null;
|
|
24913
|
+
dateRangePickerInstance = null;
|
|
24862
24914
|
if (!settingsModalElement) {
|
|
24863
24915
|
settingsModalElement = document.createElement("div");
|
|
24864
24916
|
settingsModalElement.innerHTML = renderSettingsModal();
|
|
24865
24917
|
document.body.appendChild(settingsModalElement.firstElementChild);
|
|
24866
24918
|
settingsModalElement = document.getElementById(`${widgetId}-settings-overlay`);
|
|
24867
|
-
setupSettingsModalListeners();
|
|
24919
|
+
await setupSettingsModalListeners();
|
|
24920
|
+
} else {
|
|
24921
|
+
await setupSettingsModalListeners();
|
|
24868
24922
|
}
|
|
24869
24923
|
updateSettingsModalValues();
|
|
24870
24924
|
updateIdealRangeSuggestionTooltip();
|
|
@@ -24872,6 +24926,10 @@ function createConsumptionChartWidget(config) {
|
|
|
24872
24926
|
}
|
|
24873
24927
|
function closeSettingsModal() {
|
|
24874
24928
|
settingsModalElement?.classList.add("hidden");
|
|
24929
|
+
if (dateRangePickerInstance) {
|
|
24930
|
+
dateRangePickerInstance.destroy();
|
|
24931
|
+
dateRangePickerInstance = null;
|
|
24932
|
+
}
|
|
24875
24933
|
}
|
|
24876
24934
|
function updateSettingsModalValues() {
|
|
24877
24935
|
const periodSelect = document.getElementById(`${widgetId}-settings-period`);
|
|
@@ -24981,8 +25039,46 @@ function createConsumptionChartWidget(config) {
|
|
|
24981
25039
|
label: "Faixa Sugerida"
|
|
24982
25040
|
};
|
|
24983
25041
|
}
|
|
24984
|
-
function setupSettingsModalListeners() {
|
|
25042
|
+
async function setupSettingsModalListeners() {
|
|
24985
25043
|
settingsHeaderInstance?.attachListeners();
|
|
25044
|
+
const dateRangeInput = document.getElementById(`${widgetId}-settings-daterange`);
|
|
25045
|
+
if (dateRangeInput && !dateRangePickerInstance) {
|
|
25046
|
+
try {
|
|
25047
|
+
const endDate = /* @__PURE__ */ new Date();
|
|
25048
|
+
const startDate = /* @__PURE__ */ new Date();
|
|
25049
|
+
startDate.setDate(endDate.getDate() - tempPeriod);
|
|
25050
|
+
const presetStart = tempStartDate || startDate.toISOString();
|
|
25051
|
+
const presetEnd = tempEndDate || endDate.toISOString();
|
|
25052
|
+
dateRangePickerInstance = await createDateRangePicker2(dateRangeInput, {
|
|
25053
|
+
presetStart,
|
|
25054
|
+
presetEnd,
|
|
25055
|
+
includeTime: true,
|
|
25056
|
+
timePrecision: "hour",
|
|
25057
|
+
maxRangeDays: 90,
|
|
25058
|
+
locale: "pt-BR",
|
|
25059
|
+
parentEl: document.getElementById(`${widgetId}-settings-overlay`),
|
|
25060
|
+
onApply: (result) => {
|
|
25061
|
+
tempStartDate = result.startISO;
|
|
25062
|
+
tempEndDate = result.endISO;
|
|
25063
|
+
const start = new Date(result.startISO);
|
|
25064
|
+
const end = new Date(result.endISO);
|
|
25065
|
+
const diffTime = Math.abs(end.getTime() - start.getTime());
|
|
25066
|
+
const diffHours = diffTime / (1e3 * 60 * 60);
|
|
25067
|
+
const diffDays = Math.ceil(diffTime / (1e3 * 60 * 60 * 24));
|
|
25068
|
+
tempPeriod = diffDays || 7;
|
|
25069
|
+
const granularitySelect = document.getElementById(`${widgetId}-settings-granularity`);
|
|
25070
|
+
if (granularitySelect && diffHours <= 48) {
|
|
25071
|
+
granularitySelect.value = "1h";
|
|
25072
|
+
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
25073
|
+
if (dayPeriodField) dayPeriodField.style.display = "block";
|
|
25074
|
+
}
|
|
25075
|
+
console.log("[ConsumptionChartWidget] Date range applied:", { start: result.startISO, end: result.endISO, hours: diffHours, days: tempPeriod });
|
|
25076
|
+
}
|
|
25077
|
+
});
|
|
25078
|
+
} catch (error) {
|
|
25079
|
+
console.warn("[ConsumptionChartWidget] DateRangePicker initialization failed:", error);
|
|
25080
|
+
}
|
|
25081
|
+
}
|
|
24986
25082
|
document.getElementById(`${widgetId}-settings-overlay`)?.addEventListener("click", (e) => {
|
|
24987
25083
|
if (e.target.classList.contains("myio-settings-overlay")) {
|
|
24988
25084
|
closeSettingsModal();
|
|
@@ -25070,13 +25166,56 @@ function createConsumptionChartWidget(config) {
|
|
|
25070
25166
|
updateSettingsModalTabs();
|
|
25071
25167
|
}
|
|
25072
25168
|
});
|
|
25073
|
-
document.getElementById(`${widgetId}-settings-reset`)?.addEventListener("click", () => {
|
|
25169
|
+
document.getElementById(`${widgetId}-settings-reset`)?.addEventListener("click", async () => {
|
|
25074
25170
|
tempPeriod = config.defaultPeriod ?? 7;
|
|
25075
25171
|
tempChartType = config.defaultChartType ?? "line";
|
|
25076
25172
|
tempVizMode = config.defaultVizMode ?? "total";
|
|
25077
25173
|
tempTheme = config.theme ?? "light";
|
|
25078
25174
|
tempIdealRange = config.idealRange ?? null;
|
|
25079
|
-
|
|
25175
|
+
tempStartDate = null;
|
|
25176
|
+
tempEndDate = null;
|
|
25177
|
+
if (dateRangePickerInstance) {
|
|
25178
|
+
dateRangePickerInstance.destroy();
|
|
25179
|
+
dateRangePickerInstance = null;
|
|
25180
|
+
}
|
|
25181
|
+
const dateRangeInput2 = document.getElementById(`${widgetId}-settings-daterange`);
|
|
25182
|
+
if (dateRangeInput2) {
|
|
25183
|
+
const endDate = /* @__PURE__ */ new Date();
|
|
25184
|
+
const startDate = /* @__PURE__ */ new Date();
|
|
25185
|
+
startDate.setDate(endDate.getDate() - tempPeriod);
|
|
25186
|
+
try {
|
|
25187
|
+
dateRangePickerInstance = await createDateRangePicker2(dateRangeInput2, {
|
|
25188
|
+
presetStart: startDate.toISOString(),
|
|
25189
|
+
presetEnd: endDate.toISOString(),
|
|
25190
|
+
includeTime: true,
|
|
25191
|
+
timePrecision: "hour",
|
|
25192
|
+
maxRangeDays: 90,
|
|
25193
|
+
locale: "pt-BR",
|
|
25194
|
+
parentEl: document.getElementById(`${widgetId}-settings-overlay`),
|
|
25195
|
+
onApply: (result) => {
|
|
25196
|
+
tempStartDate = result.startISO;
|
|
25197
|
+
tempEndDate = result.endISO;
|
|
25198
|
+
const start = new Date(result.startISO);
|
|
25199
|
+
const end = new Date(result.endISO);
|
|
25200
|
+
const diffTime = Math.abs(end.getTime() - start.getTime());
|
|
25201
|
+
const diffHours = diffTime / (1e3 * 60 * 60);
|
|
25202
|
+
const diffDays = Math.ceil(diffTime / (1e3 * 60 * 60 * 24));
|
|
25203
|
+
tempPeriod = diffDays || 7;
|
|
25204
|
+
const granularitySelect2 = document.getElementById(`${widgetId}-settings-granularity`);
|
|
25205
|
+
if (granularitySelect2 && diffHours <= 48) {
|
|
25206
|
+
granularitySelect2.value = "1h";
|
|
25207
|
+
const dayPeriodField2 = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
25208
|
+
if (dayPeriodField2) dayPeriodField2.style.display = "block";
|
|
25209
|
+
}
|
|
25210
|
+
}
|
|
25211
|
+
});
|
|
25212
|
+
} catch (error) {
|
|
25213
|
+
console.warn("[ConsumptionChartWidget] DateRangePicker reset failed:", error);
|
|
25214
|
+
}
|
|
25215
|
+
}
|
|
25216
|
+
const granularitySelect = document.getElementById(
|
|
25217
|
+
`${widgetId}-settings-granularity`
|
|
25218
|
+
);
|
|
25080
25219
|
if (granularitySelect) granularitySelect.value = "1d";
|
|
25081
25220
|
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
25082
25221
|
if (dayPeriodField) dayPeriodField.style.display = "none";
|
|
@@ -25222,6 +25361,10 @@ function createConsumptionChartWidget(config) {
|
|
|
25222
25361
|
}
|
|
25223
25362
|
settingsHeaderInstance?.destroy();
|
|
25224
25363
|
settingsHeaderInstance = null;
|
|
25364
|
+
if (dateRangePickerInstance) {
|
|
25365
|
+
dateRangePickerInstance.destroy();
|
|
25366
|
+
dateRangePickerInstance = null;
|
|
25367
|
+
}
|
|
25225
25368
|
if (settingsModalElement) {
|
|
25226
25369
|
settingsModalElement.remove();
|
|
25227
25370
|
settingsModalElement = null;
|