From 2cb21a43c5ffe59a39c20e4b1172a3acdf702c56 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Thu, 2 Jan 2025 22:04:14 +0100 Subject: [PATCH] fix tab color when all tracks have a different one --- gpx/src/gpx.ts | 22 +++++++++---------- .../file-list/FileListNodeLabel.svelte | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 9ffd286a..567655b9 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -185,18 +185,18 @@ export class GPXFile extends GPXTreeNode { }); } - getStyle(): MergedLineStyles { + getStyle(defaultColor?: string): MergedLineStyles { return this.trk.map((track) => track.getStyle()).reduce((acc, style) => { - if (style) { - if (style["gpx_style:color"] && !acc.color.includes(style["gpx_style:color"])) { - acc.color.push(style["gpx_style:color"]); - } - if (style["gpx_style:opacity"] && !acc.opacity.includes(style["gpx_style:opacity"])) { - acc.opacity.push(style["gpx_style:opacity"]); - } - if (style["gpx_style:width"] && !acc.width.includes(style["gpx_style:width"])) { - acc.width.push(style["gpx_style:width"]); - } + if (style && style["gpx_style:color"] && !acc.color.includes(style["gpx_style:color"])) { + acc.color.push(style["gpx_style:color"]); + } else if (defaultColor && !acc.color.includes(defaultColor)) { + acc.color.push(defaultColor); + } + if (style && style["gpx_style:opacity"] && !acc.opacity.includes(style["gpx_style:opacity"])) { + acc.opacity.push(style["gpx_style:opacity"]); + } + if (style && style["gpx_style:width"] && !acc.width.includes(style["gpx_style:width"])) { + acc.width.push(style["gpx_style:width"]); } return acc; }, { diff --git a/website/src/lib/components/file-list/FileListNodeLabel.svelte b/website/src/lib/components/file-list/FileListNodeLabel.svelte index 83dac4f6..810d21cd 100644 --- a/website/src/lib/components/file-list/FileListNodeLabel.svelte +++ b/website/src/lib/components/file-list/FileListNodeLabel.svelte @@ -69,13 +69,14 @@ nodeColors = []; if (node instanceof GPXFile) { - let style = node.getStyle(); + let defaultColor = undefined; let layer = gpxLayers.get(item.getFileId()); if (layer) { - style.color.push(layer.layerColor); + defaultColor = layer.layerColor; } + let style = node.getStyle(defaultColor); style.color.forEach((c) => { if (!nodeColors.includes(c)) { nodeColors.push(c);