Skip to content

Commit 642b9ab

Browse files
author
Marko Petzold
committed
optimize font sizes
1 parent 43d2306 commit 642b9ab

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/default-data.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"dataseries": [
3+
{
4+
"label": "Temperature",
5+
"unit": "°C",
6+
"precision": 1,
7+
"value": 83,
8+
"sections": {
9+
"sectionLimits": [],
10+
"backgroundColors": []
11+
},
12+
"advanced": {
13+
"averageLatest": 1
14+
}
15+
},
316
{
417
"label": "Temperature",
518
"unit": "°C",

src/widget-gauge.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class WidgetGauge extends LitElement {
4545
boxes?: HTMLDivElement[]
4646
origWidth: number = 600
4747
origHeight: number = 350
48+
textContainerHeight: number = 36
4849
template: EChartsOption
4950
modifier: number = 1
5051
version: string = 'versionplaceholder'
@@ -254,7 +255,10 @@ export class WidgetGauge extends LitElement {
254255
this.gaugeContainer.style.gridTemplateColumns = `repeat(${fit.c}, 1fr)`
255256

256257
this.boxes?.forEach((box) =>
257-
box.setAttribute('style', `width:${modifier * chartW}px; height:${modifier * (chartH - 27)}px`)
258+
box.setAttribute(
259+
'style',
260+
`width:${modifier * chartW}px; height:${modifier * (chartH - this.textContainerHeight)}px`
261+
)
258262
)
259263

260264
this.modifier = modifier
@@ -347,13 +351,14 @@ export class WidgetGauge extends LitElement {
347351
ga.data[0].value = ds.needleValue
348352
ga.data[0].name = ds.unit
349353
// unit style
350-
ga.title.fontSize = 20 * modifier
354+
355+
ga.title.fontSize = 32 * modifier
351356
ga.title.color = ds.valueColor || this.themeTitleColor
352357
ga.title.opacity = 1
353358
// value style
354359
ga.detail.color = ds.valueColor || this.themeTitleColor
355360
ga.detail.opacity = 1
356-
ga.detail.fontSize = 40 * modifier
361+
ga.detail.fontSize = 60 * modifier
357362

358363
ga.detail.formatter = (val: number) =>
359364
isNaN(val) ? '-' : val.toFixed(Math.floor(ds.precision ?? 0))
@@ -388,7 +393,7 @@ export class WidgetGauge extends LitElement {
388393
ga2.axisLine.lineStyle.color = colorSections?.length
389394
? colorSections
390395
: ga2.axisLine.lineStyle.color
391-
ga2.axisLabel.fontSize = 20 * modifier
396+
ga2.axisLabel.fontSize = 24 * modifier
392397
// ga2.axisLabel.color = ds.valueColor
393398
ga2.axisLabel.distance = -24 * modifier
394399
ga2.splitLine.length = 16 * modifier
@@ -407,9 +412,9 @@ export class WidgetGauge extends LitElement {
407412

408413
const titleElement = this.canvasList.get(ds.label)?.title
409414
if (titleElement) {
410-
titleElement.style.fontSize = String(20 * modifier) + 'px'
415+
titleElement.style.fontSize = String(36 * modifier) + 'px'
411416
titleElement.style.maxWidth = String(300 * modifier) + 'px'
412-
titleElement.style.height = String(27 * modifier) + 'px'
417+
titleElement.style.height = String(this.textContainerHeight * modifier) + 'px'
413418
titleElement.textContent = ds.label ?? ''
414419
}
415420

@@ -509,6 +514,7 @@ export class WidgetGauge extends LitElement {
509514
overflow: hidden;
510515
text-overflow: ellipsis;
511516
white-space: nowrap;
517+
line-height: 1;
512518
}
513519
p {
514520
margin: 10px 0 0 0;

0 commit comments

Comments
 (0)