npm package: @record-evolution/widget-gauge
Description: REWidget widget-gauge
Author: widget-gauge
Latest version: 1.7.30

# \<widget-gauge>

![thumbnail](thumbnail.png)

<br>

# The usage

## Installation & Usage

```bash
npm i widget-gauge
```

```html
<script type="module">
    import 'widget-gauge'
</script>

<widget-gauge-1.6.0 inputData="default-data"></widget-gauge-1.6.0>
```

## Development

> Make sure to always keep the widget tag name in sync with the version string in the package.json. i.e in `demo/index.html` you need to replace the version string here. `<widget-gauge-1.6.3>`

To use the widget locally during development clone the widget repo and start the dev server:

```bash
npm run start
```

This runs a local development server that serves the basic demo located in `demo/index.html`

If you want to use the widget inside another project X, then add the widget as npm module to the project X as usual. i.e. in the folder of X

```bash
npm i widget-gauge
```

To avoid releasing the widget-gauge on every change and updating the node_modules in your project X you can "link" the package locally. This replaces the already imported widget-gauge package with your local widget-gauge git repo. Since this node module is linked all changes you make in your local widget-gauge repo will immediately be visible in project X.

Go to your local widget-gauge git repo and do

```bash
npm run link
```

This create a global symbolic link on your environment and links your local package into the project X folder. (You may need to adjust the project X folder in your package.json) To reinstall the original npm version of the widget do

```bash
npm run unlink
```

<br>
<br>

## Releasing a new version

To release a new version of the widget commit all your changes and run

```js
npm run types
npm run release
```

Note that `npm run release` automatically increases the path version number. If you want a minor update, then either adjuste the version in the package.json manually or use `minor` instead of `patch` in the `npm run release` command.

After the version tag has been successfully published to github, our github action kicks in and creates a release on github and publishes the release on npm as well.

Now you need to tell the IronFlock system that a new version of the widget should be offered. You do this by executing with the new version string you created.

```sql
select swarm.f_update_widget_master('{"package_name": "widget-gauge", "version": "1.5.21"}'::jsonb);
```

To make it work locally you need to `npm run build` to get the correct version string in your build files locally, then restart the node web server container.

> It the widget is part of the demo dashboard-template.yml, then also adjust the version numbers there!

# About Widgets

## Overview

The Gauge-Widget is part of the widget series for the IoT dashboard builder. While the Record Evolution platform provides various IoT functionalities, building Dashboards is one of them. As of now, around 10 widgets are available for usage and each widget is publicly accessible on Github.

## Building custom widgets

In order to make use of your own custom widgets we provided a [boilerplate](https://github.com/RecordEvolution/REWidgets) function that will set up the file structure required by us including a builder for development and production. As we’re big supporters of the [Web component](https://www.webcomponents.org/introduction) standard the repository is following their guidelines and is built with the JavaScript framework [Lit](https://lit.dev/). And can therefore be integrated into any other project regardless of the library.

## Widget data

The main files in the repository that describe and provide your widget with data are the definition-schema.json and the default-data.json. As you can see both files are JSON files and therefore rely on the [JSON schema](https://json-schema.org/learn/getting-started-step-by-step) format in order to have a standardized representation of the data and a simple validation logic.

### defenition-schema.json

The definition-schema describes the data structure your widget code will consume. Once the widget is released to our platform the [JSON schema](https://json-schema.org/learn/getting-started-step-by-step) will be rendered into an input form and therefore significantly reduces complexity for the user when mapping data according to the definition schema. While our schema relies on the JSON schema standard we provided some extra features to simplify things. This includes the sorting of input fields with the order value.
Extra data types for colors and enum fields in order to render color picker and dropdown elements.

```json
{
    "title": "Configure the Widget",
    "type": "object",
    "properties": {
        "settings": {
            "title": "Global Settings",
            "type": "object",
            "order": 1,
            "properties": {
                "title": {
                    "title": "Title",
                    "type": "string",
                    "order": 1
                }
            }
        },
        "dataseries": {
            "title": "Dataseries",
            "type": "array",
            "order": 2,
            "items": {
                "type": "object",
                "properties": {
                    "backgroundColor": {
                        "title": "Color",
                        "type": "color",
                        "order": 3
                    },
                    "data": {
                        "title": "Data",
                        "description": "The data used to draw this data series.",
                        "type": "array",
                        "order": 4,
                        "items": {
                            "type": "object",
                            "properties": {
                                "x": {
                                    "type": "string",
                                    "required": true,
                                    "order": 1
                                },
                                "y": {
                                    "type": "number",
                                    "required": true,
                                    "order": 2
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```

### default-data.json

As the file name already describes the default-data provides some fallback data that follows the given definition structure. The following format represents the data according to the provided definition-schema shown above:

```json
{
    "settings": {
        "title": "New widget"
    },
    "dataseries": [
        {
            "backgroundColors": ["#AAC8A7", "#F1C27B", "#FF9B9B"],
            "data": [
                {
                    "value": 90,
                    "pivot": "Frankfurt"
                }
            ]
        },
        {
            "backgroundColors": ["red", "green", "blue"],
            "data": [
                {
                    "value": 34
                }
            ]
        }
    ]
}
```