Add checkbox to enable / disable physics for the ZHA network visualization page (#11017)

This commit is contained in:
David F. Mulcahey 2022-01-11 20:01:50 -05:00 committed by GitHub
parent 8291cf9daa
commit 8f68bcbba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -59,6 +59,8 @@ export class ZHANetworkVisualizationPage extends LitElement {
private _autoZoom = true; private _autoZoom = true;
private _enablePhysics = true;
protected firstUpdated(changedProperties: PropertyValues): void { protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties); super.firstUpdated(changedProperties);
@ -184,11 +186,21 @@ export class ZHANetworkVisualizationPage extends LitElement {
)} )}
> >
<ha-checkbox <ha-checkbox
@change=${this._handleCheckboxChange} @change=${this._handleAutoZoomCheckboxChange}
.checked=${this._autoZoom} .checked=${this._autoZoom}
> >
</ha-checkbox> </ha-checkbox>
</ha-formfield> </ha-formfield>
<ha-formfield
.label=${this.hass!.localize(
"ui.panel.config.zha.visualization.enable_physics"
)}
><ha-checkbox
@change=${this._handlePhysicsCheckboxChange}
.checked=${this._enablePhysics}
>
</ha-checkbox
></ha-formfield>
<mwc-button @click=${this._refreshTopology}> <mwc-button @click=${this._refreshTopology}>
${this.hass!.localize( ${this.hass!.localize(
"ui.panel.config.zha.visualization.refresh_topology" "ui.panel.config.zha.visualization.refresh_topology"
@ -374,10 +386,28 @@ export class ZHANetworkVisualizationPage extends LitElement {
return false; return false;
}; };
private _handleCheckboxChange(ev: Event) { private _handleAutoZoomCheckboxChange(ev: Event) {
this._autoZoom = (ev.target as HaCheckbox).checked; this._autoZoom = (ev.target as HaCheckbox).checked;
} }
private _handlePhysicsCheckboxChange(ev: Event) {
this._enablePhysics = (ev.target as HaCheckbox).checked;
this._network!.setOptions(
this._enablePhysics
? {
physics: {
barnesHut: {
springConstant: 0,
avoidOverlap: 10,
damping: 0.09,
},
},
}
: { physics: false }
);
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
css` css`

View File

@ -2762,6 +2762,7 @@
"highlight_label": "Highlight Devices", "highlight_label": "Highlight Devices",
"zoom_label": "Zoom To Device", "zoom_label": "Zoom To Device",
"auto_zoom": "Auto Zoom", "auto_zoom": "Auto Zoom",
"enable_physics": "Enable Physics",
"refresh_topology": "Refresh Topology" "refresh_topology": "Refresh Topology"
}, },
"group_binding": { "group_binding": {