myio-js-library 0.1.139 → 0.1.141
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/README.md +180 -0
- package/dist/index.cjs +1748 -4
- package/dist/index.d.cts +167 -1
- package/dist/index.js +1737 -4
- package/dist/myio-js-library.umd.js +1737 -4
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2500,6 +2500,186 @@ For complete technical specifications, see: [RFC-0015-MyIO-DemandModal-Component
|
|
|
2500
2500
|
|
|
2501
2501
|
---
|
|
2502
2502
|
|
|
2503
|
+
### Temperature Modal Components (RFC-0085)
|
|
2504
|
+
|
|
2505
|
+
Two specialized components for temperature telemetry visualization from ThingsBoard devices.
|
|
2506
|
+
|
|
2507
|
+
#### `openTemperatureModal(params: TemperatureModalParams): Promise<TemperatureModalInstance>`
|
|
2508
|
+
|
|
2509
|
+
Opens a temperature modal for a **single device** with historical data visualization, statistics, and granularity control.
|
|
2510
|
+
|
|
2511
|
+
**Parameters:**
|
|
2512
|
+
- `params: TemperatureModalParams` - Configuration object:
|
|
2513
|
+
- `token: string` - JWT token for ThingsBoard API (required)
|
|
2514
|
+
- `deviceId: string` - ThingsBoard device UUID (required)
|
|
2515
|
+
- `startDate: string` - ISO datetime string (required)
|
|
2516
|
+
- `endDate: string` - ISO datetime string (required)
|
|
2517
|
+
- `label?: string` - Device label (default: "Sensor de Temperatura")
|
|
2518
|
+
- `currentTemperature?: number` - Current temperature value
|
|
2519
|
+
- `temperatureMin?: number` - Minimum threshold for visual range
|
|
2520
|
+
- `temperatureMax?: number` - Maximum threshold for visual range
|
|
2521
|
+
- `temperatureStatus?: 'ok' | 'above' | 'below'` - Status indicator
|
|
2522
|
+
- `granularity?: 'hour' | 'day'` - Initial granularity (default: 'hour')
|
|
2523
|
+
- `theme?: 'dark' | 'light'` - Initial theme (default: 'light')
|
|
2524
|
+
- `clampRange?: { min: number; max: number }` - Outlier clamping (default: 15-40°C)
|
|
2525
|
+
- `locale?: 'pt-BR' | 'en-US'` - Locale for formatting
|
|
2526
|
+
- `onClose?: () => void` - Callback when modal closes
|
|
2527
|
+
|
|
2528
|
+
**Returns:** Promise resolving to `TemperatureModalInstance`:
|
|
2529
|
+
- `destroy(): void` - Close and clean up modal
|
|
2530
|
+
- `updateData(startDate, endDate, granularity?): Promise<void>` - Refresh data
|
|
2531
|
+
|
|
2532
|
+
**Key Features:**
|
|
2533
|
+
- **Granularity Control**: Hour (30-min intervals) or Day (daily averages)
|
|
2534
|
+
- **Theme Toggle**: Dark/Light mode with localStorage persistence
|
|
2535
|
+
- **Interpolation**: Fills 30-minute gaps using repeat-last strategy
|
|
2536
|
+
- **Statistics Cards**: Current, Average, Min/Max, Ideal Range
|
|
2537
|
+
- **Canvas Chart**: Timeline visualization with threshold lines
|
|
2538
|
+
- **CSV Export**: Full data with statistics summary
|
|
2539
|
+
- **DateTime Picker**: Start/end datetime selection
|
|
2540
|
+
|
|
2541
|
+
**Usage Example:**
|
|
2542
|
+
```javascript
|
|
2543
|
+
import { openTemperatureModal } from 'myio-js-library';
|
|
2544
|
+
|
|
2545
|
+
const modal = await openTemperatureModal({
|
|
2546
|
+
token: 'eyJhbGciOiJIUzI1NiJ9...',
|
|
2547
|
+
deviceId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
|
|
2548
|
+
startDate: '2025-01-01T00:00:00',
|
|
2549
|
+
endDate: '2025-01-31T23:59:59',
|
|
2550
|
+
label: 'Câmara Fria - Loja 001',
|
|
2551
|
+
temperatureMin: 2,
|
|
2552
|
+
temperatureMax: 8,
|
|
2553
|
+
granularity: 'hour',
|
|
2554
|
+
theme: 'dark',
|
|
2555
|
+
onClose: () => console.log('Modal closed')
|
|
2556
|
+
});
|
|
2557
|
+
|
|
2558
|
+
// Update data with new date range
|
|
2559
|
+
await modal.updateData('2025-02-01T00:00:00', '2025-02-28T23:59:59', 'day');
|
|
2560
|
+
|
|
2561
|
+
// Clean up
|
|
2562
|
+
modal.destroy();
|
|
2563
|
+
```
|
|
2564
|
+
|
|
2565
|
+
---
|
|
2566
|
+
|
|
2567
|
+
#### `openTemperatureComparisonModal(params: TemperatureComparisonModalParams): Promise<TemperatureComparisonModalInstance>`
|
|
2568
|
+
|
|
2569
|
+
Opens a temperature comparison modal for **multiple devices** with multi-line chart visualization.
|
|
2570
|
+
|
|
2571
|
+
**Parameters:**
|
|
2572
|
+
- `params: TemperatureComparisonModalParams` - Configuration object:
|
|
2573
|
+
- `token: string` - JWT token for ThingsBoard API (required)
|
|
2574
|
+
- `devices: TemperatureDevice[]` - Array of devices to compare (required)
|
|
2575
|
+
- `id: string` - Device UUID
|
|
2576
|
+
- `label: string` - Device label for legend
|
|
2577
|
+
- `tbId?: string` - Alternative ThingsBoard ID
|
|
2578
|
+
- `startDate: string` - ISO datetime string (required)
|
|
2579
|
+
- `endDate: string` - ISO datetime string (required)
|
|
2580
|
+
- `granularity?: 'hour' | 'day'` - Initial granularity (default: 'hour')
|
|
2581
|
+
- `theme?: 'dark' | 'light'` - Initial theme (default: 'dark')
|
|
2582
|
+
- `clampRange?: { min: number; max: number }` - Outlier clamping
|
|
2583
|
+
- `locale?: 'pt-BR' | 'en-US'` - Locale for formatting
|
|
2584
|
+
- `onClose?: () => void` - Callback when modal closes
|
|
2585
|
+
|
|
2586
|
+
**Returns:** Promise resolving to `TemperatureComparisonModalInstance`:
|
|
2587
|
+
- `destroy(): void` - Close and clean up modal
|
|
2588
|
+
- `updateData(startDate, endDate, granularity?): Promise<void>` - Refresh data
|
|
2589
|
+
|
|
2590
|
+
**Key Features:**
|
|
2591
|
+
- **Multi-Device Comparison**: Up to 8 devices with distinct colors
|
|
2592
|
+
- **Color-Coded Legend**: Automatic color assignment with labels
|
|
2593
|
+
- **Statistics Per Device**: Avg, Min, Max, Count for each sensor
|
|
2594
|
+
- **Granularity Control**: Hour (30-min intervals) or Day (daily averages)
|
|
2595
|
+
- **Theme Toggle**: Dark/Light mode with persistence
|
|
2596
|
+
- **Parallel Data Fetching**: Promise.all for efficient loading
|
|
2597
|
+
- **CSV Export**: All devices data with statistics summary
|
|
2598
|
+
|
|
2599
|
+
**Usage Example:**
|
|
2600
|
+
```javascript
|
|
2601
|
+
import { openTemperatureComparisonModal } from 'myio-js-library';
|
|
2602
|
+
|
|
2603
|
+
const modal = await openTemperatureComparisonModal({
|
|
2604
|
+
token: 'eyJhbGciOiJIUzI1NiJ9...',
|
|
2605
|
+
devices: [
|
|
2606
|
+
{ id: 'device-uuid-1', label: 'Câmara Fria 1' },
|
|
2607
|
+
{ id: 'device-uuid-2', label: 'Câmara Fria 2' },
|
|
2608
|
+
{ id: 'device-uuid-3', label: 'Freezer Principal' }
|
|
2609
|
+
],
|
|
2610
|
+
startDate: '2025-01-01T00:00:00',
|
|
2611
|
+
endDate: '2025-01-31T23:59:59',
|
|
2612
|
+
granularity: 'hour',
|
|
2613
|
+
theme: 'dark',
|
|
2614
|
+
onClose: () => console.log('Comparison modal closed')
|
|
2615
|
+
});
|
|
2616
|
+
```
|
|
2617
|
+
|
|
2618
|
+
**UMD Usage (ThingsBoard widgets):**
|
|
2619
|
+
```html
|
|
2620
|
+
<script src="https://unpkg.com/myio-js-library@latest/dist/myio-js-library.umd.min.js"></script>
|
|
2621
|
+
<script>
|
|
2622
|
+
const { openTemperatureModal, openTemperatureComparisonModal } = MyIOLibrary;
|
|
2623
|
+
|
|
2624
|
+
// Single device
|
|
2625
|
+
await openTemperatureModal({
|
|
2626
|
+
token: jwtToken,
|
|
2627
|
+
deviceId: selectedDevice.id,
|
|
2628
|
+
startDate: startISO,
|
|
2629
|
+
endDate: endISO,
|
|
2630
|
+
label: selectedDevice.label
|
|
2631
|
+
});
|
|
2632
|
+
|
|
2633
|
+
// Multiple devices comparison
|
|
2634
|
+
await openTemperatureComparisonModal({
|
|
2635
|
+
token: jwtToken,
|
|
2636
|
+
devices: selectedDevices.map(d => ({ id: d.id, label: d.label })),
|
|
2637
|
+
startDate: startISO,
|
|
2638
|
+
endDate: endISO
|
|
2639
|
+
});
|
|
2640
|
+
</script>
|
|
2641
|
+
```
|
|
2642
|
+
|
|
2643
|
+
**Utility Functions:**
|
|
2644
|
+
```javascript
|
|
2645
|
+
import {
|
|
2646
|
+
fetchTemperatureData,
|
|
2647
|
+
clampTemperature,
|
|
2648
|
+
calculateStats,
|
|
2649
|
+
interpolateTemperature,
|
|
2650
|
+
aggregateByDay,
|
|
2651
|
+
formatTemperature,
|
|
2652
|
+
exportTemperatureCSV,
|
|
2653
|
+
DEFAULT_CLAMP_RANGE,
|
|
2654
|
+
CHART_COLORS
|
|
2655
|
+
} from 'myio-js-library';
|
|
2656
|
+
|
|
2657
|
+
// Fetch raw temperature data
|
|
2658
|
+
const data = await fetchTemperatureData(token, deviceId, startTs, endTs);
|
|
2659
|
+
|
|
2660
|
+
// Clamp outliers
|
|
2661
|
+
const clamped = clampTemperature(35.5, { min: 15, max: 40 }); // 35.5
|
|
2662
|
+
|
|
2663
|
+
// Calculate statistics
|
|
2664
|
+
const stats = calculateStats(data, DEFAULT_CLAMP_RANGE);
|
|
2665
|
+
// { avg: 23.5, min: 18.2, max: 28.7, count: 1440 }
|
|
2666
|
+
|
|
2667
|
+
// Interpolate to 30-minute intervals
|
|
2668
|
+
const interpolated = interpolateTemperature(data, {
|
|
2669
|
+
intervalMinutes: 30,
|
|
2670
|
+
startTs: startTimestamp,
|
|
2671
|
+
endTs: endTimestamp
|
|
2672
|
+
});
|
|
2673
|
+
|
|
2674
|
+
// Aggregate by day
|
|
2675
|
+
const daily = aggregateByDay(data);
|
|
2676
|
+
// [{ date: '2025-01-25', avg: 23.5, min: 18.2, max: 28.7, count: 48 }, ...]
|
|
2677
|
+
```
|
|
2678
|
+
|
|
2679
|
+
For complete technical specifications, see: [RFC-0085-Temperature-Modal-Component](src/docs/rfcs/RFC-0085-Temperature-Modal-Component.md)
|
|
2680
|
+
|
|
2681
|
+
---
|
|
2682
|
+
|
|
2503
2683
|
### Goals Panel Component
|
|
2504
2684
|
|
|
2505
2685
|
#### `openGoalsPanel(params: GoalsPanelParams): GoalsPanelInstance`
|