-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI Gauge - Dynamic Properties Support #1238
Changes from all commits
4df26fa
9771ca7
adf6be1
dffec96
cc04849
68e21e7
7afa023
460b5a7
be99891
28953b9
d035a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,75 @@ description: Display real-time metrics with ui-gauge in Node-RED Dashboard 2.0 f | |
props: | ||
Group: Defines which group of the UI Dashboard this widget will render in. | ||
Size: Controls the width of the dropdown with respect to the parent group. Maximum value is the width of the group. | ||
Type: Defines the shape of the gauge, "Tile", "Battery", "Water Tank", "Half Gauge" or "3/4 Gauge" | ||
Style: Defines the style of arc rendered, "Needle" or "Rounded" | ||
Range (min): The smallest value that can be shown on the gauge | ||
Range (max): The largest value that can be shown on the gauge | ||
Segments: Defines the barriers by which the arc is color coded. These segments can also be shown on the gauge. | ||
Label: Text shown above the gauge, labelling what the gauge is showing. | ||
Prefix: Text to be added _before_ the value in the middle of the gauge. | ||
Suffix: Text to be shown _after_ the value in the middle of the gauge. | ||
Units: Small text to be shown below the value in the middle of the gauge. | ||
Icon: Icon to be shown below the value in the middle of the gauge. Uses <a href="https://pictogrammers.com/library/mdi/">Material Designs Icon</a>, no need to include the <code>mdi-</code> prefix. | ||
Type: | ||
description: Defines the shape of the gauge, "Tile", "Battery", "Water Tank", "Half Gauge" or "3/4 Gauge" | ||
dynamic: true | ||
Style: | ||
description: Defines the style of arc rendered, "Needle" or "Rounded" | ||
dynamic: true | ||
Range (min): | ||
description: The smallest value that can be shown on the gauge | ||
dynamic: true | ||
Range (max): | ||
description: The largest value that can be shown on the gauge | ||
dynamic: true | ||
Segments: | ||
description: Defines the barriers by which the arc is color coded. These segments can also be shown on the gauge. | ||
dynamic: true | ||
Label: | ||
description: Text shown above the gauge, labelling what the gauge is showing. | ||
dynamic: true | ||
Prefix: | ||
description: Text to be added _before_ the value in the middle of the gauge. | ||
dynamic: true | ||
Suffix: | ||
description: Text to be shown _after_ the value in the middle of the gauge. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this state "only applicable to for 3/4 and Half gauges"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, updated |
||
dynamic: true | ||
Units: | ||
description: Small text to be shown below the value in the middle of the gauge. | ||
dynamic: true | ||
Icon: | ||
description: Icon to be shown below the value in the middle of the gauge. Uses <a href="https://pictogrammers.com/library/mdi/">Material Designs Icon</a>, no need to include the <code>mdi-</code> prefix. | ||
dynamic: true | ||
Sizes (Gauge): (px) How thick the arc and backdrop of the gauge are rendered. | ||
Sizes (Gap): (px) How big the gap/padding is between the Gauge and the "Segments" | ||
Sizes (Segments): (px) How thick the segments are rendered. | ||
controls: | ||
enabled: | ||
example: true | false | ||
description: Allow control over whether or not the number-input is enabled | ||
dynamic: | ||
Label: | ||
payload: msg.ui_update.title | ||
structure: ["String"] | ||
Icon: | ||
payload: msg.ui_update.icon | ||
structure: ["String"] | ||
Type: | ||
payload: msg.ui_update.gtype | ||
structure: ["String"] | ||
examples: ['gauge-tile', 'gauge-battery', 'gauge-tank', 'gauge-half', 'gauge-34'] | ||
Style: | ||
payload: msg.ui_update.gstyle | ||
structure: ["String"] | ||
Min: | ||
payload: msg.ui_update.min | ||
structure: ["Number"] | ||
Max: | ||
payload: msg.ui_update.max | ||
structure: ["Number"] | ||
Segments: | ||
payload: msg.ui_update.segments | ||
structure: ["Array<{color: String, from: Number}>"] | ||
Prefix: | ||
payload: msg.ui_update.prefix | ||
structure: ["String"] | ||
Suffix: | ||
payload: msg.ui_update.suffix | ||
structure: ["String"] | ||
Units: | ||
payload: msg.ui_update.units | ||
structure: ["String"] | ||
--- | ||
|
||
|
||
|
@@ -43,6 +99,14 @@ Values for the gauges can be set by sending a numerical value in `msg.payload`. | |
|
||
<PropsTable/> | ||
|
||
## Dynamic Properties | ||
|
||
<DynamicPropsTable/> | ||
|
||
## Controls | ||
|
||
<ControlsTable/> | ||
|
||
## Examples | ||
|
||
### Half Gauge - Rounded | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,41 @@ <h3>Properties (Half & 3/4 Gauges Only)</h3> | |
<dt>Sizes (Segments) <span class="property-type">number</span></dt> | ||
<dd>A numerical value, in pixels, that defines the thickness of the segments rendered in the gauge.</dd> | ||
</dl> | ||
<h3>Dynamic Properties (Inputs)</h3> | ||
<p>Any of the following can be appended to a <code>msg.ui_update</code> in order to override or set properties on this node at runtime.</p> | ||
<dl class="message-properties"> | ||
<dt class="optional">title <span class="property-type">string</span></dt> | ||
<dd>Update the label rendered above the Gauge</dd> | ||
<dt class="optional">segments <span class="property-type">array</span></dt> | ||
<dd> | ||
Change the options available in the dropdown at runtime | ||
<ul> | ||
<li><code>Array<{color: String, from: Number}></code></li> | ||
</ul> | ||
</dd> | ||
<dt class="optional">gstyle <span class="property-type">see detail</span></dt> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be And what is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should be gtype and documented gstyle |
||
<dd>Modify the type of Gauge rendered, with the following options: | ||
<ul> | ||
<li><code>gauge-battery</code></li> | ||
<li><code>gauge-34</code></li> | ||
<li><code>gauge-half</code></li> | ||
<li><code>gauge-tile</code></li> | ||
<li><code>gauge-tank</code></li> | ||
</ul> | ||
</dd> | ||
<dt class="optional">min <span class="property-type">number</span></dt> | ||
<dd>Change the minimum value the gauge supports</dd> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to mention "Not used by tile gauge"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<dt class="optional">max <span class="property-type">number</span></dt> | ||
<dd>Change the maximum value the gauge supports</dd> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to mention "Not used by tile gauge"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned above we may need to conditionally show the range except the "Tile Gauge" type it we mention it here |
||
<dt class="optional">prefix <span class="property-type">string</span></dt> | ||
<dd>Change the text rendered after the Gauge's value</dd> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this mean to say "before" or "above? (it is the exact same text as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this state "only applicable to for 3/4 and Half gauges"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, also "gstyle", "units" and "icon". Updated them as well |
||
<dt class="optional">suffix <span class="property-type">string</span></dt> | ||
<dd>Change the text rendered after the Gauge's value</dd> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this state "only applicable to for 3/4 and Half gauges"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're correct. I've corrected it in the helper documentation |
||
<dt class="optional">units <span class="property-type">array</span></dt> | ||
<dd>Controls the "unit" display underneath the gauge's value for 3/4 and Half gauges.</dd> | ||
<dt class="optional">icon <span class="property-type">string</span></dt> | ||
<dd>Modify which icon is rendered within the gauge (must be a Material Design icon)</dd> | ||
<dt class="optional">class <span class="property-type">string</span></dt> | ||
<dd>Add a CSS class, or more, to the Button at runtime.</dd> | ||
</dl> | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<template> | ||
<ui-gauge-tile v-if="props.gtype === 'gauge-tile'" :id="id" :props="props" :value="value" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced conditional gauge type from dynamic component except 3/4 and half as doesn't support for dynamic component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all gauge types seem to be reacting to dynamic prop changes. What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took all three "ui-gauge-battery", "ui-gauge-tank" and "ui-gauge-dial" into one |
||
<ui-gauge-battery v-else-if="props.gtype === 'gauge-battery'" :id="id" :props="props" :value="value" /> | ||
<ui-gauge-tank v-else-if="props.gtype === 'gauge-tank'" :id="id" :props="props" :value="value" /> | ||
<ui-gauge-dial v-else :id="id" :props="props" :value="value" /> | ||
<component :is="`ui-${gtype}`" v-if="['gauge-tile', 'gauge-battery', 'gauge-tank'].includes(gtype)" :id="id" :props="dynamicProps" :value="value" /> | ||
<ui-gauge-dial v-else :id="id" :props="dynamicProps" :value="value" /> | ||
</template> | ||
|
||
<script> | ||
|
@@ -32,12 +30,73 @@ export default { | |
value: function () { | ||
return this.messages[this.id]?.payload | ||
}, | ||
title () { | ||
return this.getProperty('title') | ||
}, | ||
gtype () { | ||
return this.getProperty('gtype') | ||
}, | ||
gstyle () { | ||
return this.getProperty('gstyle') | ||
}, | ||
prefix () { | ||
return this.getProperty('prefix') | ||
}, | ||
suffix () { | ||
return this.getProperty('suffix') | ||
}, | ||
units () { | ||
return this.getProperty('units') | ||
}, | ||
icon () { | ||
return this.props.icon?.replace(/^mdi-/, '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is. Users can pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it currently seems to support both formats. Stripping the 'mdi-' prefix seems to have no effect on the outcome. Tested with only a couple of icons but proved the point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joepavitt @cstns |
||
return this.getProperty('icon') | ||
}, | ||
segments () { | ||
return this.getProperty('segments') | ||
}, | ||
min () { | ||
return this.getProperty('min') | ||
}, | ||
max () { | ||
return this.getProperty('max') | ||
}, | ||
dynamicProps () { | ||
const props = { | ||
...this.props, | ||
title: this.title, | ||
gtype: this.gtype, | ||
gstyle: this.gstyle, | ||
prefix: this.prefix, | ||
suffix: this.suffix, | ||
units: this.units, | ||
icon: this.icon, | ||
segments: this.segments, | ||
min: this.min, | ||
max: this.max | ||
} | ||
return props | ||
} | ||
}, | ||
created () { | ||
this.$dataTracker(this.id) | ||
this.$dataTracker(this.id, null, null, this.onDynamicProperties) | ||
}, | ||
methods: { | ||
onDynamicProperties (msg) { | ||
const updates = msg.ui_update | ||
if (!updates) { | ||
return | ||
} | ||
this.updateDynamicProperty('title', updates.title) | ||
this.updateDynamicProperty('gtype', updates.gtype) | ||
this.updateDynamicProperty('gstyle', updates.gstyle) | ||
this.updateDynamicProperty('prefix', updates.prefix) | ||
this.updateDynamicProperty('suffix', updates.suffix) | ||
this.updateDynamicProperty('units', updates.units) | ||
this.updateDynamicProperty('icon', updates.icon) | ||
this.updateDynamicProperty('segments', updates.segments) | ||
this.updateDynamicProperty('min', updates.min) | ||
this.updateDynamicProperty('max', updates.max) | ||
} | ||
} | ||
} | ||
</script> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this state "only applicable to for 3/4 and Half gauges"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're correct and also "Style", "Units" and "Icon".
I've updated them in the markdown