Skip to content
Open
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
22 changes: 22 additions & 0 deletions dual-gauge-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class DualGaugeCard extends HTMLElement {
if (!this.config.max) {
this.config.max = 100;
}

if (!this.config.fontsize) {
this.config.fontsize = 20;
}
if (!this.config.outer.fontsize) {
this.config.outer.fontsize = this.config.fontsize;
}
if (!this.config.inner.fontsize) {
this.config.inner.fontsize = this.config.fontsize;
}
Comment on lines +27 to +36
Copy link
Copy Markdown
Collaborator

@Rocka84 Rocka84 Mar 3, 2022

Choose a reason for hiding this comment

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

The default values for css-variables should be set via css. See my other suggestion.
What should happen here is to use the global value for the inner and/or outer gauge, if available and no individual values are set.

Suggested change
if (!this.config.fontsize) {
this.config.fontsize = 20;
}
if (!this.config.outer.fontsize) {
this.config.outer.fontsize = this.config.fontsize;
}
if (!this.config.inner.fontsize) {
this.config.inner.fontsize = this.config.fontsize;
}
if (this.config.fontsize && !this.config.outer.fontsize) {
this.config.outer.fontsize = this.config.fontsize;
}
if (this.config.fontsize && !this.config.inner.fontsize) {
this.config.inner.fontsize = this.config.fontsize;
}


if (!this.config.inner.min) {
this.config.inner.min = this.config.min;
Expand Down Expand Up @@ -234,6 +244,13 @@ class DualGaugeCard extends HTMLElement {
if (this.config.background_color) {
this._setCssVariable(this.nodes.content, 'gauge-background-color', this.config.background_color);
}

if (this.config.outer.fontsize) {
this._setCssVariable(this.nodes.content, 'outer-font-size', this.config.outer.fontsize + 'px');
}
if (this.config.inner.fontsize) {
this._setCssVariable(this.nodes.content, 'inner-font-size', this.config.inner.fontsize + 'px');
}

this._initStyles();
}
Expand All @@ -258,6 +275,9 @@ class DualGaugeCard extends HTMLElement {
--value-font-size: calc(var(--gauge-card-width) / 17);
--title-font-size: calc(var(--gauge-card-width) / 14);
--label-font-size: calc(var(--gauge-card-width) / 20);

--outer-font-size: var(--outer-font-size);
--inner-font-size: var(--inner-font-size);
Comment on lines +279 to +280
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This sets those variables to themselves, which doesn't do much.

Instead the default value should be set here and should be relative to --gauge-card-width, like the other font sizes.

Suggested change
--outer-font-size: var(--outer-font-size);
--inner-font-size: var(--inner-font-size);
--outer-font-size: calc(var(--gauge-card-width) / 15);
--inner-font-size: calc(var(--gauge-card-width) / 15);


width: var(--gauge-card-width);
padding: 16px;
Expand Down Expand Up @@ -344,12 +364,14 @@ class DualGaugeCard extends HTMLElement {

.gauge-value-outer, .gauge-label-outer {
color: var(--outer-color);
font-size: var(--outer-font-size);
}


.gauge-value-inner, .gauge-label-inner {
right: 0;
color: var(--inner-color);
font-size: var(--inner-font-size);
}


Expand Down