: asapien/superpulse

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
# TVA Control

Standalone Chart.js control for the Superpulse TVA parameter graph and area scans.

## Files

Copy these together:

- `tva-control.js`
- `tva-control.css`

The host page must load Chart.js before `tva-control.js`.

## Usage

```html
<link rel="stylesheet" href="tva-control.css" />
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="tva-control.js"></script>

<div id="tva" class="tva-control-container"><canvas></canvas></div>
<script>
  const tva = createTvaControl({
    container: document.getElementById("tva"),
    data: {
      complaintsOpen: 0,
      invoiceActions: 2,
      deliveryPersonLeave: 0,
      refillSpreadDays: 12,
      pendencyDays: 2.7,
      bpclDepositLakhs: 3,
      updatedAt: {
        // Example: force this parameter stale when its refresh window is 30 min.
        bpclDepositLakhs: Date.now() - 31 * 60 * 1000,
      },
      refillSpreadAreas: { "KK NAGAR": 12, "WEST MAMBALAM": 9 },
      pendencyAreas: { "KK NAGAR": 3.4, "WEST MAMBALAM": 2.9 },
    },
  });

  tva.update({ bpclDepositLakhs: 4 });
</script>
```

## API

```js
const control = createTvaControl({ canvas?, container?, data })
control.update(partialData)
control.setData(fullData)
control.getData()
control.refreshTheme()
control.destroy()
```

No default areas are built into the control. Pass all parameters and area rows as JSON from the host app.

Freshness is controlled per parameter in init JSON with `refreshMinutes`. When a continuous update includes a parameter key, its internal refresh timer resets. To mark a value as old/stale explicitly, pass `updatedAt` timestamps in the data JSON.

The control keeps two separate state concepts: display mode (`pulseGraph`, `pulseBar`, `pulseGraphMax`) and chart view (parameter graph or an `areaScanView`). Host pages can add their own breadcrumbs/navbar outside the widget if they want hierarchy.

A warning level can leave an ambient glow behind its plot point. It is JSON-controlled and can be disabled for low-end devices:

```js
ambientGlow: { enabled: true, alpha: 0.14, radius: 74, blur: 42 },
warningLevels: [
  { key: 'amber', label: 'AMBER ALERT', priority: 1, glowAlpha: 0.12 },
  { key: 'red', label: 'CRITICAL', priority: 2, glowAlpha: 0.16 },
  { key: 'double-red', label: 'DOUBLE RED', priority: 3, glowRadius: 88, glowBlur: 54 }
]
```

Per-level `glowColor`, `glowAlpha`, `glowRadius`, `glowBlur`, or `ambientGlow: false`/`glow: false` override the global glow behavior. The glow color defaults to the configured warning level color. The effect is drawn as a large radial background wash, not a foreground marker overlay.

A warning level can pulse the control border when it is the highest active level:

```js
warningLevels: [{ key: "double-red", label: "DOUBLE RED", priority: 3, borderBlink: true }];
```

Aliases `blinkBorder` and `borderAlert` are also accepted.

Visual theme values are owned by `tva-control.css`. To switch themes, set `data-tva-theme="dark"` or `data-tva-theme="light"` on the control container and call `control.refreshTheme()` so canvas-rendered colors are re-read from CSS.

See `tva-control-demo.html` for a complete standalone example.