Skip to content
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

Fix gauge when safari is zoomed #6492

Merged
merged 2 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 25 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,8 @@ const getValueInPercentage = (value: number, min: number, max: number) => {
return (100 * newVal) / newMax;
};

const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
bramkragten marked this conversation as resolved.
Show resolved Hide resolved

@customElement("ha-gauge")
export class Gauge extends LitElement {
@property({ type: Number }) public min = 0;
Expand Down Expand Up @@ -69,9 +72,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 +128,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