Skip to content

Commit

Permalink
Corrections for readme; added translations; updated adapter configura…
Browse files Browse the repository at this point in the history
…tion dialog
  • Loading branch information
MyHomeMyData committed Sep 30, 2024
1 parent f71483d commit 7d3c450
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 48 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ But if you have a very specific idea in mind for a more complex chart, flexchart

### Using the adapter

This adapter brings it's functionality as a web extension. Therefore it is mandatory to have installed and running the web adapter (`web.0`). It's assumed you're using the standard port 8082 for web adapter.
This adapter brings it's functionality as a web extension. Therefore it is mandatory to have installed and running the [web adapter](https://www.iobroker.net/#en/adapters/adapterref/iobroker.ws/README.md) (`web.0`). It's assumed you're using the standard port 8082 for web adapter.

Wenn flexcharts adapter is active you can access it via http://localhost:8082/echarts.html (replace `localhost` by address of your ioBroker server).
Wenn flexcharts adapter is active you can access it via http://localhost:8082/flexcharts/echarts.html (replace `localhost` by address of your ioBroker server).

You may use this address in iFrame widgets of vis or jarvis or other visualizations. Of course you can also use it directly in a browser tab.

To make it work, you have to provide additional parameters to tell the adapter about the source of data. Two options are availabe:
* `source=state` => You provide chart data in an ioBroker state (json)
* `source=script` => You provide chart data via a script (javascript or blockly)

There is a built-in demo chart available: http://localhost:8082/echarts.html?source=state&id=flexcharts.0.info.chart1
There is a built-in demo chart available: http://localhost:8082/flexcharts/echarts.html?source=state&id=flexcharts.0.info.chart1

To use dark mode of ECharts add `&darkmode`, e.g. http://localhost:8082/echarts.html?source=state&id=flexcharts.0.info.chart1&darkmode
To use dark mode of ECharts add `&darkmode`, e.g. http://localhost:8082/flexcharts/echarts.html?source=state&id=flexcharts.0.info.chart1&darkmode

### Use ioBroker state as source for an echart

Example: `http://localhost:8082/echarts.html?source=state&id=0_userdata.0.echarts.chart1`
Example: `http://localhost:8082/flexcharts/echarts.html?source=state&id=0_userdata.0.echarts.chart1`

<!--
Would this be better to read:
Example: http://localhost:8082/echarts.html?<mark style="background-color: #ffff00">source=state</mark>&<mark style="background-color: #00c000">&id=0_userdata.0.echarts.chart1</mark>
Example: http://localhost:8082/flexcharts/echarts.html?<mark style="background-color: #ffff00">source=state</mark>&<mark style="background-color: #00c000">&id=0_userdata.0.echarts.chart1</mark>
-->

Flexcharts will evaluate state `0_userdata.0.echarts.chart1` as data for eChart. Try it: Create such a state and copy json data of example shown above (`{ "tooltip": { ...`) as state content, then access given address with a browser.
Expand Down Expand Up @@ -114,18 +114,18 @@ function chart1(callback) {
}
```

Start the script and access this address in a browser: `http://localhost:8082/echarts.html?source=script`
Start the script and access this address in a browser: `http://localhost:8082/flexcharts/echarts.html?source=script`

<!--
Would this be better to read:
Start the script and access this in a browser: http://localhost:8082/echarts.html?<mark style="background-color: #ffff00">source=script</mark>
Start the script and access this in a browser: http://localhost:8082/flexcharts/echarts.html?<mark style="background-color: #ffff00">source=script</mark>
-->

Same chart should show up as in previous example.

Pls. note, **you have to use the `onMessage()` functionality to receive the trigger from the adapter**. Default vaule for the message is `flexcharts` as shown in example above. You may use different messages by providing an additional parameter, e.g. to uses message `mycharts` add `&message=mycharts` to http address: `http://localhost:8082/echarts.html?source=script&message=mycharts`
Pls. note, **you have to use the `onMessage()` functionality to receive the trigger from the adapter**. Default vaule for the message is `flexcharts` as shown in example above. You may use different messages by providing an additional parameter, e.g. to uses message `mycharts` add `&message=mycharts` to http address: `http://localhost:8082/flexcharts/echarts.html?source=script&message=mycharts`

Additional paramters can be forwarded to the script and will be available within the script in variable `data`. Try following command: `http://localhost:8082/echarts.html?source=script&chart=chart1&params={"period":"daily"}`
Additional paramters can be forwarded to the script and will be available within the script in variable `data`. Try following command: `http://localhost:8082/flexcharts/echarts.html?source=script&chart=chart1&params={"period":"daily"}`

This should give a log entry in the example script: `data = {"source":"script","chart":"chart1","params":"{\"period\":\"daily\"}"}`

Expand All @@ -139,7 +139,7 @@ More to come. Stay tuned.
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
* (MyHomeMyData) Use web extension instead of creating own web server.
* (MyHomeMyData) Use web extension instead of creating own web server. Use http://localhost:8082/flexcharts/echarts.html instead of http://localhost:3100/echarts.html

### 0.0.4 (2024-09-13)
* (MyHomeMyData) Changed default port to 3100 to avoid conflict with camera adapter
Expand Down
4 changes: 3 additions & 1 deletion admin/i18n/de/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Adaptereinstellungen für flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Es gibt nichts zu konfigurieren. Der Adapter wird als Web-Extension des Web-Adapters ausgeführt.",
"Please make sure you have running an instance of web adapter (web.0)": "Bitte stellen Sie sicher, dass Sie eine Instanz des Web Adapters (web.0) ausführen."
}
4 changes: 3 additions & 1 deletion admin/i18n/en/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Adapter settings for flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "There is nothing to configure. Adapter runs as web extension of web adapter.",
"Please make sure you have running an instance of web adapter (web.0)": "Please make sure you have running an instance of web adapter (web.0)"
}
4 changes: 3 additions & 1 deletion admin/i18n/es/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Ajustes del adaptador para flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "No hay nada que configurar. El adaptador se ejecuta como una extensión web del adaptador web.",
"Please make sure you have running an instance of web adapter (web.0)": "Asegúrese de haber ejecutado una instancia de Web Adaptor (web.0)"
}
4 changes: 3 additions & 1 deletion admin/i18n/fr/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Paramètres d'adaptateur pour flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Il n'y a rien à configurer. L'adaptateur s'exécute en tant qu'extension Web de l'adaptateur Web.",
"Please make sure you have running an instance of web adapter (web.0)": "Veuillez vous assurer que vous exécutez une instance de l'adaptateur Web (web.0)"
}
4 changes: 3 additions & 1 deletion admin/i18n/it/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Impostazioni dell'adattatore per flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Non c'è niente da configurare. L'adattatore viene eseguito come estensione Web dell'adattatore Web.",
"Please make sure you have running an instance of web adapter (web.0)": "Assicurati di avere in esecuzione un'istanza dell'adattatore web (web.0)"
}
4 changes: 3 additions & 1 deletion admin/i18n/nl/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"flexcharts adapter settings": "Adapterinstellingen voor flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Er valt niets te configureren. Adapter draait als webextensie van webadapter.",
"Please make sure you have running an instance of web adapter (web.0)": "Zorg ervoor dat u een exemplaar van de webadapter (web.0) gebruikt"
}
5 changes: 4 additions & 1 deletion admin/i18n/pl/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"flexcharts adapter settings": "Ustawienia adaptera dla flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Nie ma nic do skonfigurowania. Adapter działa jako rozszerzenie sieciowe adaptera internetowego.",
"Please make sure you have running an instance of web adaper (web.0)": "Upewnij się, że masz uruchomioną instancję adaptera internetowego (web.0)",
"Please make sure you have running an instance of web adapter (web.0)": "Upewnij się, że masz uruchomioną instancję adaptera internetowego (web.0)"
}
5 changes: 4 additions & 1 deletion admin/i18n/pt/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"flexcharts adapter settings": "Configurações do adaptador para flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Não há nada para configurar. O adaptador é executado como uma extensão da web do adaptador da web.",
"Please make sure you have running an instance of web adaper (web.0)": "Certifique-se de ter executado uma instância do adaptador web (web.0)",
"Please make sure you have running an instance of web adapter (web.0)": "Certifique-se de estar executando uma instância do adaptador web (web.0)"
}
5 changes: 4 additions & 1 deletion admin/i18n/ru/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"flexcharts adapter settings": "Настройки адаптера для flexcharts",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Настраивать нечего. Адаптер работает как веб-расширение веб-адаптера.",
"Please make sure you have running an instance of web adaper (web.0)": "Убедитесь, что у вас запущен экземпляр веб-адапера (web.0).",
"Please make sure you have running an instance of web adapter (web.0)": "Убедитесь, что у вас запущен экземпляр веб-адаптера (web.0)."
}
5 changes: 4 additions & 1 deletion admin/i18n/uk/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"flexcharts adapter settings": "Параметри адаптера для гнучких діаграм",
"port": "порт"
"port": "порт",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "Нема чого налаштовувати. Адаптер працює як веб-розширення веб-адаптера.",
"Please make sure you have running an instance of web adaper (web.0)": "Переконайтеся, що ви запустили екземпляр веб-адаперу (web.0)",
"Please make sure you have running an instance of web adapter (web.0)": "Переконайтеся, що ви запустили екземпляр веб-адаптера (web.0)"
}
5 changes: 4 additions & 1 deletion admin/i18n/zh-cn/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"flexcharts adapter settings": "flexcharts的适配器设置",
"port": "port"
"port": "port",
"There is nothing to configure. Adapter runs as web extension of web adapter.": "没有什么可配置的。适配器作为 Web 适配器的 Web 扩展运行。",
"Please make sure you have running an instance of web adaper (web.0)": "请确保您正在运行 web adaper (web.0) 的实例",
"Please make sure you have running an instance of web adapter (web.0)": "请确保您正在运行 Web 适配器 (web.0) 的实例"
}
11 changes: 8 additions & 3 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
"i18n": true,
"type": "panel",
"items": {
"port": {
"type": "number",
"label": "port",
"infotext1": {
"type": "staticText",
"text": "There is nothing to configure. Adapter runs as web extension of web adapter.",
"newLine": true
},
"infotext2": {
"type": "staticText",
"text": "Please make sure you have running an instance of web adapter (web.0)",
"newLine": true
}
}
Expand Down
3 changes: 1 addition & 2 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@
"write": true,
"def": "{\"series\":[{\"type\":\"gauge\",\"startAngle\":90,\"endAngle\":-270,\"pointer\":{\"show\":false},\"progress\":{\"show\":true,\"overlap\":false,\"roundCap\":true,\"clip\":false,\"itemStyle\":{\"borderWidth\":1,\"borderColor\":\"#464646\"}},\"axisLine\":{\"lineStyle\":{\"width\":40}},\"splitLine\":{\"show\":false,\"distance\":0,\"length\":10},\"axisTick\":{\"show\":false},\"axisLabel\":{\"show\":false,\"distance\":50},\"data\":[{\"value\":20,\"name\":\"Perfect\",\"title\":{\"offsetCenter\":[\"0%\",\"-30%\"]},\"detail\":{\"valueAnimation\":true,\"offsetCenter\":[\"0%\",\"-20%\"]}},{\"value\":40,\"name\":\"Good\",\"title\":{\"offsetCenter\":[\"0%\",\"0%\"]},\"detail\":{\"valueAnimation\":true,\"offsetCenter\":[\"0%\",\"10%\"]}},{\"value\":60,\"name\":\"Commonly\",\"title\":{\"offsetCenter\":[\"0%\",\"30%\"]},\"detail\":{\"valueAnimation\":true,\"offsetCenter\":[\"0%\",\"40%\"]}}],\"title\":{\"text\":\"Demo Chart: Gauge\",\"fontSize\":14},\"detail\":{\"width\":50,\"height\":14,\"fontSize\":14,\"color\":\"inherit\",\"borderColor\":\"inherit\",\"borderRadius\":20,\"borderWidth\":1,\"formatter\":\"{value}%\"}}]}"
},
"native": {
}
"native": {}
}
]
}
22 changes: 1 addition & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
const utils = require('@iobroker/adapter-core');
const adapterName = require('./package.json').name.split('.').pop();

const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');

// Load your modules here, e.g.:
// const fs = require("fs");

class Flexcharts extends utils.Adapter {

/**
Expand All @@ -28,8 +20,6 @@ class Flexcharts extends utils.Adapter {
name: 'flexcharts',
});

this.webServer = null;

this.on('ready', this.onReady.bind(this));
this.on('unload', this.onUnload.bind(this));
}
Expand All @@ -42,7 +32,7 @@ class Flexcharts extends utils.Adapter {
this.setState('info.connection', false, true);

console.log('Adapter runs as a part of web service');
this.log.warn('Adapter runs as a part of web service');
this.log.warn('Adapter runs as a part of web service. Adapter instance will stay inactive.');
this.setForeignState(`system.adapter.${this.namespace}.alive`, false, true, () =>
setTimeout(() => this.terminate ? this.terminate() : process.exit(), 1000));
}
Expand All @@ -54,16 +44,6 @@ class Flexcharts extends utils.Adapter {
onUnload(callback) {
try {
this.log.debug(`Unloading instance.`);
if (this.webServer) {
this.webServer.removeAllListeners();
this.webServer.close();
}
// Here you must clear all timeouts or intervals that may still be active
// clearTimeout(timeout1);
// clearTimeout(timeout2);
// ...
// clearInterval(interval1);

callback();
} catch (e) {
callback();
Expand Down

0 comments on commit 7d3c450

Please sign in to comment.