Skip to content

Commit b162946

Browse files
committed
updated placement logic
1 parent 828dee6 commit b162946

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

simple-weather-clock.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class SimpleWeatherClock extends HTMLElement {
1414
}
1515
1616
.card-content {
17-
width: ${this.config.displaywidth};
18-
height: ${this.config.displayheight};
17+
width: ${this.config.displaywidth}px;
18+
height: ${this.config.displayheight}px;
1919
background-color: ${this.config.background};
2020
font-family: ${this.config.font}, serif;
2121
font-weight: ${this.config.fontweight};
@@ -27,17 +27,17 @@ class SimpleWeatherClock extends HTMLElement {
2727
grid-template-areas:
2828
"clock clock clock"
2929
"info info info";
30-
padding-top: ${0 + this.config.offset}px;
30+
padding-top: ${this.config.offset}px;
3131
}
3232
3333
.clock {
3434
grid-area: clock;
3535
justify-self: center;
3636
align-self: baseline;
3737
color: ${this.config.clockcolor};
38-
font-size: ${this.config.clockfontsize};
38+
font-size: ${this.config.clockfontsize}px;
3939
height: 160px;
40-
padding-top: ${100 + this.config.clockadjust}px;
40+
padding-top: ${this.config.clockpadding}px;
4141
}
4242
4343
.info {
@@ -50,9 +50,9 @@ class SimpleWeatherClock extends HTMLElement {
5050
"info-top info-top info-top"
5151
"info-bottom info-bottom info-bottom";
5252
grid-area: info;
53-
padding-left: ${15 + this.config.infoedge}px;
54-
padding-right: ${15 + this.config.infoedge}px;
55-
margin-top: ${0 - this.config.infoadjust}px;
53+
padding-left: ${this.config.infopadding}px;
54+
padding-right: ${this.config.infopadding}px;
55+
margin-top: ${this.config.infoadjust}px;
5656
}
5757
5858
.info-top {
@@ -72,7 +72,7 @@ class SimpleWeatherClock extends HTMLElement {
7272
justify-self: start;
7373
align-self: start;
7474
color: ${this.config.topleftcolor};
75-
font-size: ${this.config.infofontsize};
75+
font-size: ${this.config.infofontsize}px;
7676
padding-top: 30px;
7777
height: 55px;
7878
}
@@ -82,7 +82,7 @@ class SimpleWeatherClock extends HTMLElement {
8282
justify-self: center;
8383
align-self: start;
8484
color: ${this.config.topcentercolor};
85-
font-size: ${this.config.infofontsize};
85+
font-size: ${this.config.infofontsize}px;
8686
padding-top: 30px;
8787
height: 55px;
8888
}
@@ -92,7 +92,7 @@ class SimpleWeatherClock extends HTMLElement {
9292
justify-self: end;
9393
align-self: start;
9494
color: ${this.config.toprightcolor};
95-
font-size: ${this.config.infofontsize};
95+
font-size: ${this.config.infofontsize}px;
9696
padding-top: 30px;
9797
height: 55px;
9898
}
@@ -106,15 +106,15 @@ class SimpleWeatherClock extends HTMLElement {
106106
grid-template-areas:
107107
"info-bottom-left info-bottom-center info-bottom-right";
108108
grid-area: info-bottom;
109-
margin-top: ${-20 - this.config.infobottomadjust + this.config.infospacing + this.config.clockspacing}px;
109+
margin-top: ${this.config.infobottommargin}px;
110110
}
111111
112112
.info-bottom-left {
113113
grid-area: info-bottom-left;
114114
justify-self: start;
115115
align-self: start;
116116
color: ${this.config.bottomleftcolor};
117-
font-size: ${this.config.infofontsize};
117+
font-size: ${this.config.infofontsize}px;
118118
padding-top: 30px;
119119
height: 55px;
120120
}
@@ -124,7 +124,7 @@ class SimpleWeatherClock extends HTMLElement {
124124
justify-self: center;
125125
align-self: start;
126126
color: ${this.config.bottomcentercolor};
127-
font-size: ${this.config.infofontsize};
127+
font-size: ${this.config.infofontsize}px;
128128
padding-top: 30px;
129129
height: 55px;
130130
}
@@ -134,7 +134,7 @@ class SimpleWeatherClock extends HTMLElement {
134134
justify-self: end;
135135
align-self: start;
136136
color: ${this.config.bottomrightcolor};
137-
font-size: ${this.config.infofontsize};
137+
font-size: ${this.config.infofontsize}px;
138138
padding-top: 30px;
139139
height: 55px;
140140
}
@@ -203,10 +203,15 @@ class SimpleWeatherClock extends HTMLElement {
203203
if (!config.clock) {
204204
throw new Error('Please define clock entity');
205205
}
206+
206207
const dcfs = 260;
207208
const difs = 85;
208-
209+
const cp = 100;
210+
const ip = 15;
211+
const ibmt = -20;
212+
var eba = 0;
209213
const cardConfig = Object.assign({}, config);
214+
210215
if (!cardConfig.background) cardConfig.background = "#000000";
211216
if (!cardConfig.font) cardConfig.font = "IBM Plex Mono";
212217
if (!cardConfig.fontweight) cardConfig.fontweight = 700;
@@ -218,33 +223,33 @@ class SimpleWeatherClock extends HTMLElement {
218223
if (!cardConfig.bottomleftcolor) cardConfig.bottomleftcolor = "#008001";
219224
if (!cardConfig.bottomcentercolor) cardConfig.bottomcentercolor = "#1f90ff";
220225
if (!cardConfig.bottomrightcolor) cardConfig.bottomrightcolor = "#bdb76b";
221-
if (!cardConfig.displaywidth) cardConfig.displaywidth = "800px";
222-
if (!cardConfig.displayheight) cardConfig.displayheight = "480px";
223-
if (!cardConfig.offset) cardConfig.offset = "0px";
224-
if (!cardConfig.clockspacing) cardConfig.clockspacing = "0px";
225-
if (!cardConfig.infospacing) cardConfig.infospacing = "0px";
226-
if (!cardConfig.infoedge) cardConfig.infoedge = "0px";
226+
if (!cardConfig.displaywidth) cardConfig.displaywidth = 800;
227+
if (!cardConfig.displayheight) cardConfig.displayheight = 480;
228+
if (!cardConfig.offset) cardConfig.offset = 0;
229+
if (!cardConfig.clockspacing) cardConfig.clockspacing = 0;
230+
if (!cardConfig.infospacing) cardConfig.infospacing = 0;
231+
if (!cardConfig.infoedge) {
232+
cardConfig.infopadding = ip;
233+
} else {
234+
cardConfig.infopadding = ip + cardConfig.infoedge
235+
}
227236
if (!cardConfig.clockfontsize) {
228-
cardConfig.clockfontsize = dcfs + "px";
229-
cardConfig.clockadjust = 0;
237+
cardConfig.clockfontsize = dcfs;
238+
cardConfig.clockpadding = cp;
230239
} else {
231-
cardConfig.clockadjust = Math.round((Number(cardConfig.clockfontsize.slice(0,-2)) - dcfs)/3.0)
240+
const ca = Math.round((cardConfig.clockfontsize - dcfs) / 3.0)
241+
cardConfig.clockpadding = cp + ca
232242
}
233243
if (!cardConfig.infofontsize) {
234-
cardConfig.infofontsize = difs + "px";
244+
cardConfig.infofontsize = difs;
235245
cardConfig.infoadjust = 0;
236-
cardConfig.infobottomadjust = 0;
237246
} else {
238-
cardConfig.infoadjust = Math.round((Number(cardConfig.infofontsize.slice(0,-2)) - difs)/2.0);
239-
cardConfig.infobottomadjust = Number(cardConfig.infofontsize.slice(0,-2)) - difs;
247+
cardConfig.infoadjust = Math.round((cardConfig.infofontsize - difs) / 2.0);
248+
eba = cardConfig.infofontsize - difs;
240249
}
241-
cardConfig.offset = parseInt(cardConfig.offset.slice(0,-2));
242-
cardConfig.clockspacing = parseInt(cardConfig.clockspacing.slice(0,-2));
243-
cardConfig.infospacing = parseInt(cardConfig.infospacing.slice(0,-2));
244-
cardConfig.infoedge = parseInt(cardConfig.infoedge.slice(0,-2));
245-
250+
cardConfig.infobottommargin = ibmt - eba + cardConfig.infospacing + cardConfig.clockspacing
251+
246252
this.config = cardConfig;
247-
248253
}
249254

250255
getCardSize() {

0 commit comments

Comments
 (0)