Skip to content
Merged
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
167 changes: 167 additions & 0 deletions cypress/fixtures/flows/dashboard-gauge-autosize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
[
{
"id": "gauge-autosize-tab",
"type": "tab",
"label": "Gauge Autosize",
"disabled": false,
"info": ""
},
{
"id": "dashboard-ui-base",
"type": "ui-base",
"name": "UI Name",
"path": "/dashboard",
"includeClientData": true,
"acceptsClientConfig": ["ui-notification", "ui-control"]
},
{
"id": "dashboard-ui-theme",
"type": "ui-theme",
"name": "Theme",
"colors": {
"surface": "#ffffff",
"primary": "#0094ce",
"bgPage": "#eeeeee",
"groupBg": "#ffffff",
"groupOutline": "#cccccc"
}
},
{
"id": "dashboard-ui-page-1",
"type": "ui-page",
"name": "Page 1",
"ui": "dashboard-ui-base",
"path": "/page1",
"icon": "home",
"layout": "grid",
"theme": "dashboard-ui-theme",
"order": 1,
"className": "",
"visible": "true",
"disabled": false
},
{
"id": "dashboard-ui-group",
"type": "ui-group",
"name": "Gauges",
"page": "dashboard-ui-page-1",
"width": "6",
"height": "1",
"order": 1,
"showTitle": true,
"className": "",
"visible": "true",
"disabled": "false"
},
{
"id": "dashboard-ui-gauge-auto",
"type": "ui-gauge",
"z": "gauge-autosize-tab",
"group": "dashboard-ui-group",
"name": "auto",
"order": 1,
"value": "payload",
"valueType": "msg",
"width": "3",
"height": "0",
"gtype": "gauge-34",
"gstyle": "needle",
"title": "auto",
"alwaysShowTitle": true,
"floatingTitlePosition": "top-left",
"units": "%",
"icon": "",
"prefix": "",
"suffix": "",
"segments": [
{ "from": "0", "color": "#53a51c", "text": "", "textType": "label" },
{ "from": "60", "color": "#f6c000", "text": "", "textType": "label" },
{ "from": "80", "color": "#ca3838", "text": "", "textType": "label" }
],
"min": "0",
"max": "100",
"sizeThickness": "16",
"sizeGap": "4",
"sizeKeyThickness": "8",
"styleRounded": true,
"styleGlow": false,
"className": "",
"x": 400,
"y": 100,
"wires": [[]]
},
{
"id": "dashboard-ui-gauge-fixed",
"type": "ui-gauge",
"z": "gauge-autosize-tab",
"group": "dashboard-ui-group",
"name": "fixed",
"order": 2,
"value": "payload",
"valueType": "msg",
"width": "3",
"height": "4",
"gtype": "gauge-34",
"gstyle": "needle",
"title": "fixed",
"alwaysShowTitle": true,
"floatingTitlePosition": "top-left",
"units": "%",
"icon": "",
"prefix": "",
"suffix": "",
"segments": [
{ "from": "0", "color": "#53a51c", "text": "", "textType": "label" },
{ "from": "60", "color": "#f6c000", "text": "", "textType": "label" },
{ "from": "80", "color": "#ca3838", "text": "", "textType": "label" }
],
"min": "0",
"max": "100",
"sizeThickness": "16",
"sizeGap": "4",
"sizeKeyThickness": "8",
"styleRounded": true,
"styleGlow": false,
"className": "",
"x": 400,
"y": 160,
"wires": [[]]
},
{
"id": "dashboard-ui-gauge-half-auto",
"type": "ui-gauge",
"z": "gauge-autosize-tab",
"group": "dashboard-ui-group",
"name": "half-auto",
"order": 3,
"value": "payload",
"valueType": "msg",
"width": "3",
"height": "0",
"gtype": "gauge-half",
"gstyle": "needle",
"title": "half-auto",
"alwaysShowTitle": true,
"floatingTitlePosition": "top-left",
"units": "%",
"icon": "",
"prefix": "",
"suffix": "",
"segments": [
{ "from": "0", "color": "#53a51c", "text": "", "textType": "label" },
{ "from": "60", "color": "#f6c000", "text": "", "textType": "label" },
{ "from": "80", "color": "#ca3838", "text": "", "textType": "label" }
],
"min": "0",
"max": "100",
"sizeThickness": "16",
"sizeGap": "4",
"sizeKeyThickness": "8",
"styleRounded": true,
"styleGlow": false,
"className": "",
"x": 400,
"y": 220,
"wires": [[]]
}
]
18 changes: 18 additions & 0 deletions cypress/tests/widgets/gauge-autosize.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('Node-RED Dashboard 2.0 - Gauge auto-height (#1875)', () => {
beforeEach(() => {
cy.deployFixture('dashboard-gauge-autosize')
cy.visit('/dashboard/page1')
})

it('gives an auto-height gauge the default height instead of collapsing to one row', () => {
cy.get('#nrdb-ui-widget-dashboard-ui-gauge-auto').children().eq(0).should('have.css', 'grid-row-end', 'span 3')
})

it('leaves a fixed-height gauge unchanged', () => {
cy.get('#nrdb-ui-widget-dashboard-ui-gauge-fixed').children().eq(0).should('have.css', 'grid-row-end', 'span 4')
})

it('does not force a default height on an auto half-gauge (fix is scoped to gauge-34)', () => {
cy.get('#nrdb-ui-widget-dashboard-ui-gauge-half-auto').children().eq(0).should('not.have.css', 'grid-row-end', 'span 3')
})
})
3 changes: 3 additions & 0 deletions ui/src/layouts/Group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export default {
if (widget.type === 'ui-chart') {
return 8
}
if (widget.type === 'ui-gauge' && widget.props.gtype === 'gauge-34') {
return 3
}
}
return height
},
Expand Down
19 changes: 16 additions & 3 deletions ui/src/widgets/ui-gauge/types/UIGaugeDial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ export default {
this.sizes.titleHeight = this.$refs.title ? this.$refs.title.clientHeight : 0

this.width = this.$refs.container.clientWidth
this.height = this.props.height ? this.$refs.container.clientHeight - this.sizes.titleHeight : (this.props.gtype === 'gauge-half' ? 150 : 300)
const available = this.$refs.container.clientHeight - this.sizes.titleHeight
if (this.props.gtype === 'gauge-34' && !this.props.height) {
this.height = available > 0 ? available : 300
} else {
this.height = this.props.height ? available : (this.props.gtype === 'gauge-half' ? 150 : 300)
}

// heights for the SVG
const w = this.width
Expand All @@ -157,7 +162,8 @@ export default {

const limit = this.$refs['limits-min']
const labelRoom = limit ? Math.ceil(limit.getBBox().height) : 16
if (gaugeArea + labelRoom < h) {
this.capped = gaugeArea + labelRoom < h
if (this.capped) {
this.height = gaugeArea
this.$refs.gauge.style.flexGrow = '0'
this.$refs.gauge.setAttribute('height', gaugeArea + labelRoom)
Expand Down Expand Up @@ -329,7 +335,13 @@ export default {
// this.svg.select('#needle-container')

this.svg.select('#needle-container')
.style('transform-box', this.capped ? 'view-box' : null)
.style('transform-origin', () => {
if (this.capped) {
const cx = this.width / 2
const cy = this.props.gtype === 'gauge-half' ? this.height + this.sizes.fudge : this.height / 2
return `${cx}px ${cy}px`
}
return this.sizes.angle > Math.PI ? 'center center' : 'center bottom'
})
.transition().duration(duration)
Expand All @@ -342,7 +354,8 @@ export default {
const rotate = d3.interpolate(start, end)(t)
const deg = rotate * (180 / Math.PI)
// -6 is fudge factor to ensure needle is visible and doesn't have half hanging out of SVG window
return `translate(0, ${vue.props.gtype === 'gauge-half' ? vue.sizes.fudge.toString() : '0'}px)rotate(${deg}deg)`
const yOffset = (vue.props.gtype === 'gauge-half' && !vue.capped) ? vue.sizes.fudge : 0
return `translate(0, ${yOffset}px)rotate(${deg}deg)`
}
return tween
})
Expand Down
Loading