Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/flows/basic-layout-after.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,51 @@
[]
]
},
{
"id": "ca93de861ac43763",
"type": "ui-gauge",
"z": "94d6d107f1742efb",
"name": "My Favorite Gauge",
"group": "f663864dda246564",
"order": 12,
"width": 0,
"height": 0,
"gtype": "gauge-half",
"title": "gauge",
"label": "units",
"min": 0,
"max": 10,
"diff": false,
"className": "",
"x": 350,
"y": 320,
"wires": [

],
"units": "units",
"segments": [
{
"from": 0,
"colors": "#00b500"
},
{
"from": 4,
"color": "#e6e600"
},
{
"from": 7,
"color": "#ca3838"
}
],
"prefix": "",
"suffix": " %",
"icon": "",
"sizeThickness": 16,
"sizeGap": 4,
"sizeKeyThickness": 8,
"styleRounded": true,
"styleGlow": false
},
{
"id": "856a31bba370e7fc",
"type": "ui-group",
Expand Down
28 changes: 28 additions & 0 deletions tests/flows/basic-layout-before.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@
[]
]
},
{
"id": "7fd46d95e548d6f4",
"type": "ui_gauge",
"z": "94d6d107f1742efb",
"name": "My Favorite Gauge",
"group": "856a31bba370e7fc",
"order": 12,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "gauge",
"label": "units",
"format": "{{value}} %",
"min": 0,
"max": 10,
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"diff": false,
"className": "",
"x": 350,
"y": 320,
"wires": []
},
{
"id": "856a31bba370e7fc",
"type": "ui_group",
Expand Down
13 changes: 13 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ describe('Dashboard Migration Script', function () {
})
})

describe('UI Gauge:', function () {
const input = utils.getByType(migratedFlow, 'ui-gauge')[0]
const input1 = utils.getByType(basicLayoutAfter, 'ui-gauge')[0]

const excludeFromChecks = ['id', 'group']
Object.keys(input).forEach((prop) => {
if (!excludeFromChecks.includes(prop)) {
it('should set ' + prop + ' correctly ', function () {
input[prop].should.eql(input1[prop])
})
}
})
})
describe('Unsupported UI Nodes:', function () {
it('should should be disabled in the NR Editor', function () {
const template0 = utils.getByType(migratedFlow, 'ui_template')[0]
Expand Down
3 changes: 2 additions & 1 deletion transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
uiSlider: require('./nodes/ui-slider'),
uiSwitch: require('./nodes/ui-switch'),
uiText: require('./nodes/ui-text'),
uiTextInput: require('./nodes/ui-text-input')
uiTextInput: require('./nodes/ui-text-input'),
uiGauge: require('./nodes/ui-gauge')
}
3 changes: 2 additions & 1 deletion transformers/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"ui_slider": "uiSlider",
"ui_switch": "uiSwitch",
"ui_text": "uiText",
"ui_text_input": "uiTextInput"
"ui_text_input": "uiTextInput",
"ui_gauge": "uiGauge"
}
63 changes: 63 additions & 0 deletions transformers/nodes/ui-gauge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module.exports = function (node, baseId, themeId) {
node.type = 'ui-gauge'

// update properties
node.units = node.label
node.segments = [{}, {}, {}]
node.segments[0].from = node.min
node.segments[0].colors = node.colors[0]
if (node.seg1 !== '') {
node.segments[1].from = node.seg1
} else {
node.segments[1].from = (node.max - node.min) * 0.4 + node.min
}
node.segments[1].color = node.colors[1]

if (node.seg2 !== '') {
node.segments[2].from = node.seg2
} else {
node.segments[2].from = node.max - (node.max - node.min) * 0.3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does the 0.3 (and 0.4 above) come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default "optional" marks that are empty in the D1.0 Node. Those values are required for D2.0. 40% and 70% of the range of the default in D2.0 ranges (0,4,7,10). The D2.0 node doesn't have a granular transition setting for each color, it is each point the user defines.

}
node.segments[2].color = node.colors[2]

switch (node.gtype) {
case 'gage': // gauge
node.gtype = 'gauge-half'
break
case 'wave': // level
node.gtype = 'gauge-tank'
break
default:
node.gtype = 'gauge-34'
break
}

const str = node.format
const indexpre = str.indexOf('{{value}}')
if (indexpre !== -1) {
const resultpre = str.substring(0, indexpre)
node.prefix = resultpre
const indexsuf = indexpre + 9
const resultsuf = str.substring(indexsuf)
node.suffix = resultsuf
} else {
node.prefix = ''
node.suffix = ''
};

// new properties
node.icon = ''
node.sizeThickness = 16
node.sizeGap = 4
node.sizeKeyThickness = 8
node.styleRounded = true
node.styleGlow = false

// remove properties
delete node.seg1
delete node.seg2
delete node.colors
delete node.format

return node
}