Adjustments after testing

This commit is contained in:
Gunnar Skjold
2026-04-09 08:51:17 +02:00
parent 9803f62a4d
commit 9e1727fed9
5 changed files with 64 additions and 37 deletions

File diff suppressed because one or more lines are too long

View File

@@ -14,6 +14,29 @@
let vertSwitch = 30;
let titleHeight = 0;
function fitText(node, maxWidth) {
let raf;
function fit(w) {
cancelAnimationFrame(raf);
node.style.fontSize = '';
if (!w) return;
raf = requestAnimationFrame(() => {
try {
const bbox = node.getBBox();
if (bbox.width > 0 && bbox.width > w) {
const fs = parseFloat(getComputedStyle(node).fontSize) || 12;
node.style.fontSize = (fs * w / bbox.width) + 'px';
}
} catch(e) { /* element not in layout tree */ }
});
}
fit(maxWidth);
return {
update: fit,
destroy() { cancelAnimationFrame(raf); }
};
}
$: {
heightAvailable = height-titleHeight;
let innerWidth = width - (config.padding.left + config.padding.right);
@@ -74,7 +97,7 @@
{#if !isNaN(xScale(i))}
<g class="tick" transform="translate({xScale(i)},{heightAvailable})">
{#if barWidth > 20 || i%2 == 0 || !config.x.ticks[i-1].label}
<text x="{barWidth/2}" y="-4">{point.label}</text>
<text x="{barWidth/2}" y="-4" text-anchor="middle" use:fitText={barWidth * 0.85}>{point.label}</text>
{/if}
</g>
{/if}
@@ -101,7 +124,7 @@
text-anchor="{barWidth < vertSwitch || point.labelAngle ? 'left' : 'middle'}"
fill="{yScale(point.value) > yScale(0)-labelOffset && !config.dark ? point.color : 'white'}"
transform="translate({xScale(i) + barWidth/2} {yScale(point.value) > yScale(0) - labelOffset ? yScale(point.value) - labelOffset : yScale(point.value) + 10}) rotate({point.labelAngle ? point.labelAngle : barWidth < vertSwitch ? 90 : 0})"
use:fitText={!point.labelAngle && barWidth >= vertSwitch ? barWidth * 0.95 : null}
>{point.label}</text>
{/if}
{/if}
@@ -122,6 +145,7 @@
text-anchor="{'middle'}"
fill="{yScale(-point.value2) < yScale(0) + 15 && !config.dark ? point.color2 ? point.color2 : point.color : 'white'}"
transform="translate({xScale(i) + (barWidth/2)} {yScale(-point.value2) < yScale(0) + 15 ? yScale(-point.value2) + 15 : yScale(-point.value2) - 14}) rotate({barWidth < vertSwitch ? 90 : 0})"
use:fitText={barWidth >= vertSwitch ? barWidth * 0.95 : null}
>{point.label2}</text>
{#if point.title2}
<title>{point.title2}</title>

View File

@@ -38,15 +38,17 @@
}
if(tariffData && tariffData.p) {
for(i = 0; i < tariffData.p.length; i++) {
let peak = tariffData.p[i];
const sortedPeaks = [...tariffData.p].sort((a, b) => a.d - b.d);
for(i = 0; i < sortedPeaks.length; i++) {
let peak = sortedPeaks[i];
let title = "";
let daylabel = "-";
if(peak.d > 0) {
daylabel = zeropad(peak.d) + ".";
title = zeropad(peak.d) + "." + (translations.months ? translations.months?.[new Date().getMonth()] : zeropad(new Date().getMonth()+1));
if(tariffData.p.length < 4) {
if(sortedPeaks.length < 4) {
daylabel = title;
}
}
@@ -98,7 +100,7 @@
config = {
title: title,
dark: document.documentElement.classList.contains('dark'),
padding: { top: 20, right: 20, bottom: 20, left: 20 },
padding: { top: 20, right: 30, bottom: 20, left: 20 },
y: {
min: min,
max: max,

View File

@@ -17,29 +17,29 @@ export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/data.json": "http://192.168.21.122",
"/energyprice.json": "http://192.168.21.122",
"/importprice.json": "http://192.168.21.122",
"/exportprice.json": "http://192.168.21.122",
"/dayplot.json": "http://192.168.21.122",
"/monthplot.json": "http://192.168.21.122",
"/temperature.json": "http://192.168.21.122",
"/sysinfo.json": "http://192.168.21.122",
"/configuration.json": "http://192.168.21.122",
"/tariff.json": "http://192.168.21.122",
"/realtime.json": "http://192.168.21.122",
"/priceconfig.json": "http://192.168.21.122",
"/translations.json": "http://192.168.21.122",
"/cloudkey.json": "http://192.168.21.122",
"/wifiscan.json": "http://192.168.21.122",
"/save": "http://192.168.21.122",
"/reboot": "http://192.168.21.122",
"/configfile": "http://192.168.21.122",
"/upgrade": "http://192.168.21.122",
"/mqtt-ca": "http://192.168.21.122",
"/mqtt-cert": "http://192.168.21.122",
"/mqtt-key": "http://192.168.21.122",
"/logo.svg": "http://192.168.21.122",
"/data.json": "http://192.168.233.49",
"/energyprice.json": "http://192.168.233.49",
"/importprice.json": "http://192.168.233.49",
"/exportprice.json": "http://192.168.233.49",
"/dayplot.json": "http://192.168.233.49",
"/monthplot.json": "http://192.168.233.49",
"/temperature.json": "http://192.168.233.49",
"/sysinfo.json": "http://192.168.233.49",
"/configuration.json": "http://192.168.233.49",
"/tariff.json": "http://192.168.233.49",
"/realtime.json": "http://192.168.233.49",
"/priceconfig.json": "http://192.168.233.49",
"/translations.json": "http://192.168.233.49",
"/cloudkey.json": "http://192.168.233.49",
"/wifiscan.json": "http://192.168.233.49",
"/save": "http://192.168.233.49",
"/reboot": "http://192.168.233.49",
"/configfile": "http://192.168.233.49",
"/upgrade": "http://192.168.233.49",
"/mqtt-ca": "http://192.168.233.49",
"/mqtt-cert": "http://192.168.233.49",
"/mqtt-key": "http://192.168.233.49",
"/logo.svg": "http://192.168.233.49",
}
}
})