# FUXA-SVG-Widgets **Repository Path**: ipcun/FUXA-SVG-Widgets ## Basic Information - **Project Name**: FUXA-SVG-Widgets - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-21 - **Last Updated**: 2025-11-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FUXA-SVG-Widgets A public collection of reusable **SVG widgets** for [FUXA](https://github.com/frangoteam/FUXA), the open‑source SCADA/HMI platform. This repository centralizes community widgets and a **complete authoring guide** so you can build, share, and reuse SVG components effectively. --- ## ✨ Highlights - **Plug‑and‑play** SVG widgets for dashboards/HMIs - **No external deps**: each widget is a single self‑contained `.svg` - **Configurable** via exported variables (`//!export-start` … `//!export-end`) - **Two‑way data**: receive tag values and send commands back to FUXA - **Responsive** by default (`viewBox`, `width/height 100%`) --- ## 📂 Repository Structure ``` FUXA-SVG-Widgets/ ├─ Control-Gauges/ ├─ controls/ ├─ dynamicSVG/ ├─ indicators/ ├─ Tanks/ ├─ .../ └─ screenshots/ ``` > Tip: keep each widget **self‑contained** in a single `.svg` file with embedded JS and optional inline CSS. --- ## 🚀 Quick Start (Use in FUXA) 1. **Clone or download** this repository. 2. Copy the desired widget `.svg` into your project’s **resources** folder. 3. In FUXA, open the **Widget Library** and place the SVG on your screen. 4. Configure exported variables (min/max/unit/color …) or **bind** them to Tags. --- ## 🖼 Example Preview Add your screenshot at `./screenshots/semicircle-gauge.png` so it renders on GitHub: ![Semicircle Gauge](./screenshots/semicircle-gauge.png) --- # 📖 Complete Widget Authoring Guide This guide consolidates everything you need to create robust SVG widgets for FUXA. ## 1) Widget Skeleton Widgets are **pure SVG files** with embedded JavaScript inside ``. ```xml 0 °C ``` **Key points** - The block between `//!export-start` and `//!export-end` defines **configurable** variables visible in FUXA. - Provide `init()` (called at load) and accessor functions like `setValue(...)` as needed. - Use stable element `id` attributes for parts you update. --- ## 2) Exported Variables (Configuration) Declare exported parameters **between** the markers below—FUXA reads and writes these. ```js //!export-start let _pn_min = 0; // number let _pn_max = 100; // number let _pn_value = 0; // number (bindable tag) let _ps_unit = "%"; // string let _ps_label = "Level"; // string let _pc_foreground = "#00aaff";// color hex let _pc_background = "#20232a";// color hex let _pb_showValue = true; // boolean let _pn_precision = 0; // number //!export-end ``` **Recommended prefixes** - `_pb_`: boolean - `_pn_`: number - `_ps_`: string - `_pc_`: color (hex/rgb) > These variables appear in the **property grid** and can be **bound** to Tags (read or write). --- ## 3) Data Flow: Receive & Send ### Receive values from FUXA Implement `putValue(id, value)` and react to updates for specific exported variables: ```js function putValue(id, value) { if (id === '_pn_value') setValue(value); if (id === '_ps_unit') { _ps_unit = value; update(); } if (id === '_ps_label') { _ps_label = value; update(); } } ``` ### Send values/commands to FUXA Call `postValue(exportedVarName, value)` from your widget (e.g., on click). ```js function increase() { const next = Math.min(_pn_max, _pn_value + 1); setValue(next); if (typeof postValue === 'function') { postValue('_pn_value', next); } } ``` > Use **exact** exported variable names when calling `postValue(...)` and when matching in `putValue(...)`. --- ## 4) Lifecycle & Cleanup If you use `setInterval`, `setTimeout`, or listeners, clean them up when the widget is removed (e.g., screen change). ```js let _blinkTimer = null; function startBlink() { _blinkTimer = setInterval(() => { // toggle class or color }, 500); } function clearBlink() { if (_blinkTimer) { clearInterval(_blinkTimer); _blinkTimer = null; } } // optional: observe removal (function () { const rootId = 'myWidget'; const root = document.getElementById(rootId); if (!root) return; const obs = new MutationObserver(muts => { for (const m of muts) for (const n of m.removedNodes) { if (n.id === rootId) { clearBlink(); obs.disconnect(); } } }); obs.observe(document.body, { childList: true, subtree: true }); })(); ``` --- ## 5) Pointer Events & Coordinates In scaled SVGs, convert screen → SVG coordinates to avoid drift: ```js function toSvgPoint(evt, svgEl) { const pt = svgEl.createSVGPoint(); pt.x = evt.clientX; pt.y = evt.clientY; return pt.matrixTransform(svgEl.getScreenCTM().inverse()); } ``` Examples: knob rotation, slider drag, area selection. --- ## 6) Responsive Layout & Styling - Always set `viewBox` and `width="100%" height="100%"`. - Inline CSS within the SVG is supported. - Prefer readable fonts; make sizes configurable if helpful. - Keep sufficient contrast; support dark/light backgrounds. ```xml ... ``` --- ## 7) Patterns & Examples ### 7.1 Threshold Indicator (color by value) ```xml ``` ### 7.2 Command Button (writes back to Tag) ```xml Start ``` ### 7.3 Semicircle Gauge (value + unit + label) ```xml 0 % Level ``` --- ## 8) Naming & Packaging Conventions - Use **clear filenames** and semantic ids (e.g., `valve-indicator.svg`, `knob-rotary.svg`). - Keep **exported variable names stable**—renaming breaks existing bindings. - If your widget depends on images/fonts, prefer **inline** SVG/CSS or `` to keep it self‑contained. --- ## 9) Testing Widgets (Standalone) You can test outside FUXA by embedding your SVG in a simple HTML and manually invoking `setValue(...)` in the devtools console. ```html ``` --- ## 10) Troubleshooting - **Nothing updates** → check ids and that `update()` manipulates existing nodes. - **Wrong pointer coords** → use `getScreenCTM().inverse()` as shown above. - **Blurry text** → use whole‑pixel font sizes or `shape-rendering="geometricPrecision"`. - **Performance** → throttle updates, avoid unnecessary DOM writes. --- ## 🤝 Contributing 1. Fork the repo. 2. Add your SVG to the right folder (`Control-Gauges`, `controls`, `dynamicSVG`, `indicators`, `Tanks`). 3. Include an optional screenshot and a short description. 4. Open a Pull Request. **Widget checklist** - Responsive (`viewBox`, `width="100%" height="100%"`). - Uses exported variables (`//!export-start`/`//!export-end`). - Implements `putValue(...)` for inputs and `postValue(...)` for outputs (when needed). - Self‑contained (no network calls / external fonts). --- ## 📜 License MIT License – free to use, modify, and share. --- ## 🔗 Useful Links - FUXA main repository: https://github.com/frangoteam/FUXA - Built‑in widget examples: https://github.com/frangoteam/FUXA/tree/master/server/_widgets - Original wiki reference: https://github.com/frangoteam/FUXA/wiki/HowTo-Widgets