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
|
@@ -20345,7 +20345,7 @@ ${rangeText}`;
|
|
|
20345
20345
|
const contentMaxHeight = isMaximized ? "100vh" : "95vh";
|
|
20346
20346
|
const contentBorderRadius = isMaximized ? "0" : "10px";
|
|
20347
20347
|
container.innerHTML = `
|
|
20348
|
-
<div class="myio-temp-modal-overlay" style="
|
|
20348
|
+
<div class="myio-temp-modal-overlay myio-modal-scope" style="
|
|
20349
20349
|
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
|
20350
20350
|
background: rgba(0, 0, 0, 0.5); z-index: 9998;
|
|
20351
20351
|
display: flex; justify-content: center; align-items: center;
|
|
@@ -20600,6 +20600,22 @@ ${rangeText}`;
|
|
|
20600
20600
|
background: rgba(255, 255, 255, 0.1) !important;
|
|
20601
20601
|
color: white !important;
|
|
20602
20602
|
}
|
|
20603
|
+
|
|
20604
|
+
/* DateRangePicker styles */
|
|
20605
|
+
${CSS_TOKENS}
|
|
20606
|
+
${DATERANGEPICKER_STYLES}
|
|
20607
|
+
|
|
20608
|
+
/* Fix DateRangePicker buttons alignment */
|
|
20609
|
+
.myio-modal-scope .daterangepicker .drp-buttons {
|
|
20610
|
+
display: flex;
|
|
20611
|
+
justify-content: flex-end;
|
|
20612
|
+
align-items: center;
|
|
20613
|
+
gap: 8px;
|
|
20614
|
+
}
|
|
20615
|
+
.myio-modal-scope .daterangepicker .drp-buttons .btn {
|
|
20616
|
+
display: inline-block;
|
|
20617
|
+
margin-left: 0;
|
|
20618
|
+
}
|
|
20603
20619
|
</style>
|
|
20604
20620
|
`;
|
|
20605
20621
|
}
|
|
@@ -23714,18 +23730,11 @@ ${rangeText}`;
|
|
|
23714
23730
|
|
|
23715
23731
|
.myio-chart-widget-title {
|
|
23716
23732
|
margin: 0;
|
|
23717
|
-
font-size:
|
|
23733
|
+
font-size: 14px;
|
|
23718
23734
|
font-weight: 600;
|
|
23719
23735
|
color: ${colors.text};
|
|
23720
23736
|
}
|
|
23721
23737
|
|
|
23722
|
-
.myio-chart-widget-controls {
|
|
23723
|
-
display: flex;
|
|
23724
|
-
align-items: center;
|
|
23725
|
-
gap: 12px;
|
|
23726
|
-
flex-wrap: wrap;
|
|
23727
|
-
}
|
|
23728
|
-
|
|
23729
23738
|
.myio-chart-widget-tabs {
|
|
23730
23739
|
display: flex;
|
|
23731
23740
|
gap: 2px;
|
|
@@ -23745,6 +23754,20 @@ ${rangeText}`;
|
|
|
23745
23754
|
border-radius: 6px;
|
|
23746
23755
|
transition: all 0.2s;
|
|
23747
23756
|
white-space: nowrap;
|
|
23757
|
+
display: flex;
|
|
23758
|
+
align-items: center;
|
|
23759
|
+
justify-content: center;
|
|
23760
|
+
gap: 4px;
|
|
23761
|
+
}
|
|
23762
|
+
|
|
23763
|
+
.myio-chart-widget-tab.icon-only {
|
|
23764
|
+
padding: 6px 10px;
|
|
23765
|
+
}
|
|
23766
|
+
|
|
23767
|
+
.myio-chart-widget-tab svg {
|
|
23768
|
+
width: 16px;
|
|
23769
|
+
height: 16px;
|
|
23770
|
+
pointer-events: none;
|
|
23748
23771
|
}
|
|
23749
23772
|
|
|
23750
23773
|
.myio-chart-widget-tab:hover {
|
|
@@ -23878,7 +23901,7 @@ ${rangeText}`;
|
|
|
23878
23901
|
background: ${colors.chartBackground};
|
|
23879
23902
|
border-radius: 10px;
|
|
23880
23903
|
width: 90%;
|
|
23881
|
-
max-width:
|
|
23904
|
+
max-width: 860px;
|
|
23882
23905
|
max-height: 90vh;
|
|
23883
23906
|
display: flex;
|
|
23884
23907
|
flex-direction: column;
|
|
@@ -23895,7 +23918,7 @@ ${rangeText}`;
|
|
|
23895
23918
|
overflow-y: auto;
|
|
23896
23919
|
display: flex;
|
|
23897
23920
|
flex-direction: column;
|
|
23898
|
-
gap:
|
|
23921
|
+
gap: 12px;
|
|
23899
23922
|
}
|
|
23900
23923
|
|
|
23901
23924
|
.myio-settings-section {
|
|
@@ -23938,10 +23961,10 @@ ${rangeText}`;
|
|
|
23938
23961
|
|
|
23939
23962
|
.myio-settings-input,
|
|
23940
23963
|
.myio-settings-select {
|
|
23941
|
-
padding:
|
|
23964
|
+
padding: 8px 12px;
|
|
23942
23965
|
border: 1px solid ${colors.border};
|
|
23943
23966
|
border-radius: 8px;
|
|
23944
|
-
font-size:
|
|
23967
|
+
font-size: 12px;
|
|
23945
23968
|
background: ${colors.chartBackground};
|
|
23946
23969
|
color: ${colors.text};
|
|
23947
23970
|
width: 100%;
|
|
@@ -23973,6 +23996,10 @@ ${rangeText}`;
|
|
|
23973
23996
|
border-radius: 6px;
|
|
23974
23997
|
transition: all 0.2s;
|
|
23975
23998
|
white-space: nowrap;
|
|
23999
|
+
display: flex;
|
|
24000
|
+
align-items: center;
|
|
24001
|
+
justify-content: center;
|
|
24002
|
+
gap: 6px;
|
|
23976
24003
|
}
|
|
23977
24004
|
|
|
23978
24005
|
.myio-settings-tab:hover {
|
|
@@ -24030,13 +24057,17 @@ ${rangeText}`;
|
|
|
24030
24057
|
}
|
|
24031
24058
|
|
|
24032
24059
|
.myio-settings-context-group {
|
|
24033
|
-
margin-bottom:
|
|
24060
|
+
margin-bottom: 12px;
|
|
24034
24061
|
}
|
|
24035
24062
|
|
|
24036
24063
|
.myio-settings-context-group:last-child {
|
|
24037
24064
|
margin-bottom: 0;
|
|
24038
24065
|
}
|
|
24039
24066
|
|
|
24067
|
+
.myio-settings-section + .myio-settings-section {
|
|
24068
|
+
margin-top: 12px;
|
|
24069
|
+
}
|
|
24070
|
+
|
|
24040
24071
|
/* Dropdown styles */
|
|
24041
24072
|
.myio-settings-dropdown-container {
|
|
24042
24073
|
position: relative;
|
|
@@ -24140,6 +24171,23 @@ ${rangeText}`;
|
|
|
24140
24171
|
opacity: 1 !important;
|
|
24141
24172
|
transform: scale(1.2);
|
|
24142
24173
|
}
|
|
24174
|
+
|
|
24175
|
+
/* DateRangePicker styles (CSS tokens + premium styling) */
|
|
24176
|
+
${CSS_TOKENS}
|
|
24177
|
+
${DATERANGEPICKER_STYLES}
|
|
24178
|
+
|
|
24179
|
+
/* Fix DateRangePicker buttons alignment */
|
|
24180
|
+
.myio-modal-scope .daterangepicker .drp-buttons {
|
|
24181
|
+
display: flex;
|
|
24182
|
+
justify-content: flex-end;
|
|
24183
|
+
align-items: center;
|
|
24184
|
+
gap: 8px;
|
|
24185
|
+
}
|
|
24186
|
+
|
|
24187
|
+
.myio-modal-scope .daterangepicker .drp-buttons .btn {
|
|
24188
|
+
display: inline-block;
|
|
24189
|
+
margin-left: 0;
|
|
24190
|
+
}
|
|
24143
24191
|
`;
|
|
24144
24192
|
}
|
|
24145
24193
|
function createConsumptionChartWidget(config) {
|
|
@@ -24149,6 +24197,7 @@ ${rangeText}`;
|
|
|
24149
24197
|
let styleElement = null;
|
|
24150
24198
|
let settingsModalElement = null;
|
|
24151
24199
|
let settingsHeaderInstance = null;
|
|
24200
|
+
let dateRangePickerInstance = null;
|
|
24152
24201
|
let currentTheme = config.theme ?? "light";
|
|
24153
24202
|
let currentChartType = config.defaultChartType ?? "line";
|
|
24154
24203
|
let currentVizMode = config.defaultVizMode ?? "total";
|
|
@@ -24159,6 +24208,8 @@ ${rangeText}`;
|
|
|
24159
24208
|
let tempVizMode = currentVizMode;
|
|
24160
24209
|
let tempTheme = currentTheme;
|
|
24161
24210
|
let tempIdealRange = currentIdealRange;
|
|
24211
|
+
let tempStartDate = null;
|
|
24212
|
+
let tempEndDate = null;
|
|
24162
24213
|
let currentSuggestion = null;
|
|
24163
24214
|
const domainCfg = DOMAIN_CONFIG4[config.domain] || DOMAIN_CONFIG4.energy;
|
|
24164
24215
|
const primaryColor = config.colors?.primary || domainCfg.color;
|
|
@@ -24174,6 +24225,10 @@ ${rangeText}`;
|
|
|
24174
24225
|
return `${domainName} dos \xFAltimos ${currentPeriod} dias`;
|
|
24175
24226
|
}
|
|
24176
24227
|
function renderHTML() {
|
|
24228
|
+
const consolidadoIcon = `<svg viewBox="0 0 16 16" fill="currentColor"><rect x="3" y="3" width="10" height="10" rx="2"/></svg>`;
|
|
24229
|
+
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>`;
|
|
24230
|
+
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>`;
|
|
24231
|
+
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>`;
|
|
24177
24232
|
return `
|
|
24178
24233
|
<div id="${widgetId}" class="myio-chart-widget ${currentTheme === "dark" ? "dark" : ""} ${config.className || ""}">
|
|
24179
24234
|
<div class="myio-chart-widget-header">
|
|
@@ -24182,18 +24237,16 @@ ${rangeText}`;
|
|
|
24182
24237
|
<button id="${widgetId}-settings-btn" class="myio-chart-widget-btn" title="Configura\xE7\xF5es">\u2699\uFE0F</button>
|
|
24183
24238
|
` : ""}
|
|
24184
24239
|
<h4 id="${widgetId}-title" class="myio-chart-widget-title">${getTitle()}</h4>
|
|
24185
|
-
</div>
|
|
24186
|
-
<div class="myio-chart-widget-controls">
|
|
24187
24240
|
${showVizModeTabs ? `
|
|
24188
24241
|
<div class="myio-chart-widget-tabs" id="${widgetId}-viz-tabs">
|
|
24189
|
-
<button class="myio-chart-widget-tab ${currentVizMode === "total" ? "active" : ""}" data-viz="total"
|
|
24190
|
-
<button class="myio-chart-widget-tab ${currentVizMode === "separate" ? "active" : ""}" data-viz="separate"
|
|
24242
|
+
<button class="myio-chart-widget-tab icon-only ${currentVizMode === "total" ? "active" : ""}" data-viz="total" title="Consolidado">${consolidadoIcon}</button>
|
|
24243
|
+
<button class="myio-chart-widget-tab icon-only ${currentVizMode === "separate" ? "active" : ""}" data-viz="separate" title="Por Shopping">${porShoppingIcon}</button>
|
|
24191
24244
|
</div>
|
|
24192
24245
|
` : ""}
|
|
24193
24246
|
${showChartTypeTabs ? `
|
|
24194
24247
|
<div class="myio-chart-widget-tabs" id="${widgetId}-type-tabs">
|
|
24195
|
-
<button class="myio-chart-widget-tab ${currentChartType === "line" ? "active" : ""}" data-type="line"
|
|
24196
|
-
<button class="myio-chart-widget-tab ${currentChartType === "bar" ? "active" : ""}" data-type="bar"
|
|
24248
|
+
<button class="myio-chart-widget-tab icon-only ${currentChartType === "line" ? "active" : ""}" data-type="line" title="Gr\xE1fico de Linhas">${lineChartIcon}</button>
|
|
24249
|
+
<button class="myio-chart-widget-tab icon-only ${currentChartType === "bar" ? "active" : ""}" data-type="bar" title="Gr\xE1fico de Barras">${barChartIcon}</button>
|
|
24197
24250
|
</div>
|
|
24198
24251
|
` : ""}
|
|
24199
24252
|
${showMaximizeButton ? `
|
|
@@ -24230,19 +24283,22 @@ ${rangeText}`;
|
|
|
24230
24283
|
function renderSettingsModal() {
|
|
24231
24284
|
const unit = config.unit ?? "";
|
|
24232
24285
|
const isTemperature = config.domain === "temperature";
|
|
24286
|
+
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>`;
|
|
24287
|
+
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>`;
|
|
24288
|
+
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>`;
|
|
24289
|
+
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>`;
|
|
24233
24290
|
settingsHeaderInstance = createModalHeader({
|
|
24234
24291
|
id: `${widgetId}-settings`,
|
|
24235
24292
|
title: "Configura\xE7\xF5es",
|
|
24236
24293
|
icon: "\u2699\uFE0F",
|
|
24237
24294
|
theme: tempTheme,
|
|
24238
|
-
backgroundColor: primaryColor,
|
|
24239
24295
|
showThemeToggle: false,
|
|
24240
24296
|
showMaximize: false,
|
|
24241
24297
|
showClose: true,
|
|
24242
24298
|
onClose: () => closeSettingsModal()
|
|
24243
24299
|
});
|
|
24244
24300
|
return `
|
|
24245
|
-
<div id="${widgetId}-settings-overlay" class="myio-settings-overlay hidden">
|
|
24301
|
+
<div id="${widgetId}-settings-overlay" class="myio-settings-overlay myio-modal-scope hidden">
|
|
24246
24302
|
<div class="myio-settings-card">
|
|
24247
24303
|
${settingsHeaderInstance.render()}
|
|
24248
24304
|
<div class="myio-settings-body">
|
|
@@ -24253,13 +24309,8 @@ ${rangeText}`;
|
|
|
24253
24309
|
<div class="myio-settings-section-label">\u{1F4C5} Per\xEDodo</div>
|
|
24254
24310
|
<div class="myio-settings-row">
|
|
24255
24311
|
<div class="myio-settings-field" style="flex: 1;">
|
|
24256
|
-
<
|
|
24257
|
-
|
|
24258
|
-
<option value="14" ${tempPeriod === 14 ? "selected" : ""}>\xDAltimos 14 dias</option>
|
|
24259
|
-
<option value="30" ${tempPeriod === 30 ? "selected" : ""}>\xDAltimos 30 dias</option>
|
|
24260
|
-
<option value="60" ${tempPeriod === 60 ? "selected" : ""}>\xDAltimos 60 dias</option>
|
|
24261
|
-
<option value="90" ${tempPeriod === 90 ? "selected" : ""}>\xDAltimos 90 dias</option>
|
|
24262
|
-
</select>
|
|
24312
|
+
<input type="text" id="${widgetId}-settings-daterange" class="myio-settings-input"
|
|
24313
|
+
readonly placeholder="Selecione o per\xEDodo..." style="cursor: pointer;">
|
|
24263
24314
|
</div>
|
|
24264
24315
|
</div>
|
|
24265
24316
|
</div>
|
|
@@ -24388,8 +24439,8 @@ ${rangeText}`;
|
|
|
24388
24439
|
<div class="myio-settings-field" style="flex: 1; min-width: 180px;">
|
|
24389
24440
|
<label class="myio-settings-field-label">Tipo de Gr\xE1fico</label>
|
|
24390
24441
|
<div class="myio-settings-tabs" id="${widgetId}-settings-chart-type">
|
|
24391
|
-
<button class="myio-settings-tab ${tempChartType === "line" ? "active" : ""}" data-type="line"
|
|
24392
|
-
<button class="myio-settings-tab ${tempChartType === "bar" ? "active" : ""}" data-type="bar"
|
|
24442
|
+
<button class="myio-settings-tab ${tempChartType === "line" ? "active" : ""}" data-type="line">${lineChartIcon} Linhas</button>
|
|
24443
|
+
<button class="myio-settings-tab ${tempChartType === "bar" ? "active" : ""}" data-type="bar">${barChartIcon} Barras</button>
|
|
24393
24444
|
</div>
|
|
24394
24445
|
</div>
|
|
24395
24446
|
|
|
@@ -24397,8 +24448,8 @@ ${rangeText}`;
|
|
|
24397
24448
|
<div class="myio-settings-field" style="flex: 1; min-width: 200px;">
|
|
24398
24449
|
<label class="myio-settings-field-label">Agrupamento</label>
|
|
24399
24450
|
<div class="myio-settings-tabs" id="${widgetId}-settings-viz-mode">
|
|
24400
|
-
<button class="myio-settings-tab ${tempVizMode === "total" ? "active" : ""}" data-viz="total"
|
|
24401
|
-
<button class="myio-settings-tab ${tempVizMode === "separate" ? "active" : ""}" data-viz="separate"
|
|
24451
|
+
<button class="myio-settings-tab ${tempVizMode === "total" ? "active" : ""}" data-viz="total">${consolidadoIcon} Consolidado</button>
|
|
24452
|
+
<button class="myio-settings-tab ${tempVizMode === "separate" ? "active" : ""}" data-viz="separate">${porShoppingIcon} Por Shopping</button>
|
|
24402
24453
|
</div>
|
|
24403
24454
|
</div>
|
|
24404
24455
|
|
|
@@ -24539,18 +24590,21 @@ ${rangeText}`;
|
|
|
24539
24590
|
peakDateEl.textContent = peakDate;
|
|
24540
24591
|
}
|
|
24541
24592
|
}
|
|
24542
|
-
function openSettingsModal() {
|
|
24593
|
+
async function openSettingsModal() {
|
|
24543
24594
|
tempPeriod = currentPeriod;
|
|
24544
24595
|
tempChartType = currentChartType;
|
|
24545
24596
|
tempVizMode = currentVizMode;
|
|
24546
24597
|
tempTheme = currentTheme;
|
|
24547
24598
|
tempIdealRange = currentIdealRange ? { ...currentIdealRange } : null;
|
|
24599
|
+
dateRangePickerInstance = null;
|
|
24548
24600
|
if (!settingsModalElement) {
|
|
24549
24601
|
settingsModalElement = document.createElement("div");
|
|
24550
24602
|
settingsModalElement.innerHTML = renderSettingsModal();
|
|
24551
24603
|
document.body.appendChild(settingsModalElement.firstElementChild);
|
|
24552
24604
|
settingsModalElement = document.getElementById(`${widgetId}-settings-overlay`);
|
|
24553
|
-
setupSettingsModalListeners();
|
|
24605
|
+
await setupSettingsModalListeners();
|
|
24606
|
+
} else {
|
|
24607
|
+
await setupSettingsModalListeners();
|
|
24554
24608
|
}
|
|
24555
24609
|
updateSettingsModalValues();
|
|
24556
24610
|
updateIdealRangeSuggestionTooltip();
|
|
@@ -24558,6 +24612,10 @@ ${rangeText}`;
|
|
|
24558
24612
|
}
|
|
24559
24613
|
function closeSettingsModal() {
|
|
24560
24614
|
settingsModalElement?.classList.add("hidden");
|
|
24615
|
+
if (dateRangePickerInstance) {
|
|
24616
|
+
dateRangePickerInstance.destroy();
|
|
24617
|
+
dateRangePickerInstance = null;
|
|
24618
|
+
}
|
|
24561
24619
|
}
|
|
24562
24620
|
function updateSettingsModalValues() {
|
|
24563
24621
|
const periodSelect = document.getElementById(`${widgetId}-settings-period`);
|
|
@@ -24667,8 +24725,46 @@ ${rangeText}`;
|
|
|
24667
24725
|
label: "Faixa Sugerida"
|
|
24668
24726
|
};
|
|
24669
24727
|
}
|
|
24670
|
-
function setupSettingsModalListeners() {
|
|
24728
|
+
async function setupSettingsModalListeners() {
|
|
24671
24729
|
settingsHeaderInstance?.attachListeners();
|
|
24730
|
+
const dateRangeInput = document.getElementById(`${widgetId}-settings-daterange`);
|
|
24731
|
+
if (dateRangeInput && !dateRangePickerInstance) {
|
|
24732
|
+
try {
|
|
24733
|
+
const endDate = /* @__PURE__ */ new Date();
|
|
24734
|
+
const startDate = /* @__PURE__ */ new Date();
|
|
24735
|
+
startDate.setDate(endDate.getDate() - tempPeriod);
|
|
24736
|
+
const presetStart = tempStartDate || startDate.toISOString();
|
|
24737
|
+
const presetEnd = tempEndDate || endDate.toISOString();
|
|
24738
|
+
dateRangePickerInstance = await createDateRangePicker2(dateRangeInput, {
|
|
24739
|
+
presetStart,
|
|
24740
|
+
presetEnd,
|
|
24741
|
+
includeTime: true,
|
|
24742
|
+
timePrecision: "hour",
|
|
24743
|
+
maxRangeDays: 90,
|
|
24744
|
+
locale: "pt-BR",
|
|
24745
|
+
parentEl: document.getElementById(`${widgetId}-settings-overlay`),
|
|
24746
|
+
onApply: (result) => {
|
|
24747
|
+
tempStartDate = result.startISO;
|
|
24748
|
+
tempEndDate = result.endISO;
|
|
24749
|
+
const start = new Date(result.startISO);
|
|
24750
|
+
const end = new Date(result.endISO);
|
|
24751
|
+
const diffTime = Math.abs(end.getTime() - start.getTime());
|
|
24752
|
+
const diffHours = diffTime / (1e3 * 60 * 60);
|
|
24753
|
+
const diffDays = Math.ceil(diffTime / (1e3 * 60 * 60 * 24));
|
|
24754
|
+
tempPeriod = diffDays || 7;
|
|
24755
|
+
const granularitySelect = document.getElementById(`${widgetId}-settings-granularity`);
|
|
24756
|
+
if (granularitySelect && diffHours <= 48) {
|
|
24757
|
+
granularitySelect.value = "1h";
|
|
24758
|
+
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
24759
|
+
if (dayPeriodField) dayPeriodField.style.display = "block";
|
|
24760
|
+
}
|
|
24761
|
+
console.log("[ConsumptionChartWidget] Date range applied:", { start: result.startISO, end: result.endISO, hours: diffHours, days: tempPeriod });
|
|
24762
|
+
}
|
|
24763
|
+
});
|
|
24764
|
+
} catch (error) {
|
|
24765
|
+
console.warn("[ConsumptionChartWidget] DateRangePicker initialization failed:", error);
|
|
24766
|
+
}
|
|
24767
|
+
}
|
|
24672
24768
|
document.getElementById(`${widgetId}-settings-overlay`)?.addEventListener("click", (e) => {
|
|
24673
24769
|
if (e.target.classList.contains("myio-settings-overlay")) {
|
|
24674
24770
|
closeSettingsModal();
|
|
@@ -24756,13 +24852,56 @@ ${rangeText}`;
|
|
|
24756
24852
|
updateSettingsModalTabs();
|
|
24757
24853
|
}
|
|
24758
24854
|
});
|
|
24759
|
-
document.getElementById(`${widgetId}-settings-reset`)?.addEventListener("click", () => {
|
|
24855
|
+
document.getElementById(`${widgetId}-settings-reset`)?.addEventListener("click", async () => {
|
|
24760
24856
|
tempPeriod = config.defaultPeriod ?? 7;
|
|
24761
24857
|
tempChartType = config.defaultChartType ?? "line";
|
|
24762
24858
|
tempVizMode = config.defaultVizMode ?? "total";
|
|
24763
24859
|
tempTheme = config.theme ?? "light";
|
|
24764
24860
|
tempIdealRange = config.idealRange ?? null;
|
|
24765
|
-
|
|
24861
|
+
tempStartDate = null;
|
|
24862
|
+
tempEndDate = null;
|
|
24863
|
+
if (dateRangePickerInstance) {
|
|
24864
|
+
dateRangePickerInstance.destroy();
|
|
24865
|
+
dateRangePickerInstance = null;
|
|
24866
|
+
}
|
|
24867
|
+
const dateRangeInput2 = document.getElementById(`${widgetId}-settings-daterange`);
|
|
24868
|
+
if (dateRangeInput2) {
|
|
24869
|
+
const endDate = /* @__PURE__ */ new Date();
|
|
24870
|
+
const startDate = /* @__PURE__ */ new Date();
|
|
24871
|
+
startDate.setDate(endDate.getDate() - tempPeriod);
|
|
24872
|
+
try {
|
|
24873
|
+
dateRangePickerInstance = await createDateRangePicker2(dateRangeInput2, {
|
|
24874
|
+
presetStart: startDate.toISOString(),
|
|
24875
|
+
presetEnd: endDate.toISOString(),
|
|
24876
|
+
includeTime: true,
|
|
24877
|
+
timePrecision: "hour",
|
|
24878
|
+
maxRangeDays: 90,
|
|
24879
|
+
locale: "pt-BR",
|
|
24880
|
+
parentEl: document.getElementById(`${widgetId}-settings-overlay`),
|
|
24881
|
+
onApply: (result) => {
|
|
24882
|
+
tempStartDate = result.startISO;
|
|
24883
|
+
tempEndDate = result.endISO;
|
|
24884
|
+
const start = new Date(result.startISO);
|
|
24885
|
+
const end = new Date(result.endISO);
|
|
24886
|
+
const diffTime = Math.abs(end.getTime() - start.getTime());
|
|
24887
|
+
const diffHours = diffTime / (1e3 * 60 * 60);
|
|
24888
|
+
const diffDays = Math.ceil(diffTime / (1e3 * 60 * 60 * 24));
|
|
24889
|
+
tempPeriod = diffDays || 7;
|
|
24890
|
+
const granularitySelect2 = document.getElementById(`${widgetId}-settings-granularity`);
|
|
24891
|
+
if (granularitySelect2 && diffHours <= 48) {
|
|
24892
|
+
granularitySelect2.value = "1h";
|
|
24893
|
+
const dayPeriodField2 = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
24894
|
+
if (dayPeriodField2) dayPeriodField2.style.display = "block";
|
|
24895
|
+
}
|
|
24896
|
+
}
|
|
24897
|
+
});
|
|
24898
|
+
} catch (error) {
|
|
24899
|
+
console.warn("[ConsumptionChartWidget] DateRangePicker reset failed:", error);
|
|
24900
|
+
}
|
|
24901
|
+
}
|
|
24902
|
+
const granularitySelect = document.getElementById(
|
|
24903
|
+
`${widgetId}-settings-granularity`
|
|
24904
|
+
);
|
|
24766
24905
|
if (granularitySelect) granularitySelect.value = "1d";
|
|
24767
24906
|
const dayPeriodField = document.getElementById(`${widgetId}-settings-dayperiod-field`);
|
|
24768
24907
|
if (dayPeriodField) dayPeriodField.style.display = "none";
|
|
@@ -24908,6 +25047,10 @@ ${rangeText}`;
|
|
|
24908
25047
|
}
|
|
24909
25048
|
settingsHeaderInstance?.destroy();
|
|
24910
25049
|
settingsHeaderInstance = null;
|
|
25050
|
+
if (dateRangePickerInstance) {
|
|
25051
|
+
dateRangePickerInstance.destroy();
|
|
25052
|
+
dateRangePickerInstance = null;
|
|
25053
|
+
}
|
|
24911
25054
|
if (settingsModalElement) {
|
|
24912
25055
|
settingsModalElement.remove();
|
|
24913
25056
|
settingsModalElement = null;
|