Skip to content

Commit

Permalink
Fix gauge when safari is zoomed (#6492)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
  • Loading branch information
bramkragten and balloob committed Aug 3, 2020
1 parent 209dd99 commit 8fb62eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/components/ha-gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "lit-element";
import { styleMap } from "lit-html/directives/style-map";
import { afterNextRender } from "../common/util/render-status";
import { ifDefined } from "lit-html/directives/if-defined";

const getAngle = (value: number, min: number, max: number) => {
const percentage = getValueInPercentage(normalize(value, min, max), min, max);
Expand All @@ -27,6 +28,9 @@ const getValueInPercentage = (value: number, min: number, max: number) => {
return (100 * newVal) / newMax;
};

// Workaround for https://github.com/home-assistant/frontend/issues/6467
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

@customElement("ha-gauge")
export class Gauge extends LitElement {
@property({ type: Number }) public min = 0;
Expand Down Expand Up @@ -69,9 +73,28 @@ export class Gauge extends LitElement {
></path>
<path
class="value"
style=${styleMap({ transform: `rotate(${this._angle}deg)` })}
d="M 90 50.001 A 40 40 0 0 1 10 50"
></path>
style=${ifDefined(
!isSafari
? styleMap({ transform: `rotate(${this._angle}deg)` })
: undefined
)}
transform=${ifDefined(
isSafari ? `rotate(${this._angle} 50 50)` : undefined
)}
>
${
isSafari
? svg`<animateTransform
attributeName="transform"
type="rotate"
from="0 50 50"
to="${this._angle} 50 50"
dur="1s"
/>`
: ""
}
</path>
</svg>
<svg class="text">
<text class="value-text">
Expand Down Expand Up @@ -106,8 +129,8 @@ export class Gauge extends LitElement {
fill: none;
stroke-width: 15;
stroke: var(--gauge-color);
transition: all 1000ms ease 0s;
transform-origin: 50% 100%;
transition: all 1s ease 0s;
}
.gauge {
display: block;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/hui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class HUIRoot extends LitElement {
</mwc-list-item>
`
: ""}
${this.hass!.user!.is_admin && !this.hass!.config.safe_mode
${this.hass!.user?.is_admin && !this.hass!.config.safe_mode
? html`
<mwc-list-item
aria-label=${this.hass!.localize(
Expand Down

0 comments on commit 8fb62eb

Please sign in to comment.