Skip to content

Commit d182513

Browse files
committed
Simplify single-item types in legend
1 parent 731f55c commit d182513

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

frontend/src/lib/components/legend/legend-content.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@
7979
</div>
8080

8181
<template v-for="(type, idx) in items" :key="type.key">
82-
<hr v-if="idx > 0">
83-
<h3 @click="toggleFilter(type)" :class="{ filtered: type.filtered }">{{type.name}}</h3>
82+
<hr v-if="idx > 0 && (type.items.length > 1 || items[idx - 1].items.length > 1)">
8483
<dl>
8584
<template v-for="(item, idx) in type.items" :key="item.key">
8685
<dt
87-
:class="[ 'fm-legend-icon', 'fm-' + type.type, { filtered: item.filtered, first: (item.first && idx !== 0), bright: item.bright } ]"
86+
:class="[ 'fm-legend-icon', 'fm-' + type.type, { filtered: item.filtered, first: (item.first && idx !== 0), bright: item.bright, main: idx === 0 } ]"
8887
@click="toggleFilter(type, item)"
8988
v-html-async="makeIcon(type, item)"
9089
@mouseenter="togglePopover(item.key, true)"
@@ -93,7 +92,7 @@
9392
></dt>
9493
<dd
9594
class="text-break"
96-
:class="[ 'fm-' + type.type, { filtered: item.filtered, first: (item.first && idx !== 0), bright: item.bright } ]"
95+
:class="[ 'fm-' + type.type, { filtered: item.filtered, first: (item.first && idx !== 0), bright: item.bright, main: idx === 0 } ]"
9796
@click="toggleFilter(type, item)"
9897
:style="item.strikethrough ? {'text-decoration': 'line-through'} : {}"
9998
@mouseenter="togglePopover(item.key, true)"
@@ -176,6 +175,11 @@
176175
cursor: pointer;
177176
}
178177
178+
dt, dd {
179+
display: inline-flex;
180+
align-items: center;
181+
}
182+
179183
dt.fm-marker {
180184
grid-column: 1 / 2;
181185
}
@@ -201,6 +205,11 @@
201205
}
202206
}
203207
208+
.main {
209+
font-size: 1.1em;
210+
font-weight: bold;
211+
}
212+
204213
.filtered {
205214
opacity: 0.5;
206215
}

frontend/src/lib/components/legend/legend-utils.ts

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,37 @@ export function getLegendItems(context: FacilMapContext): LegendType[] {
4141
const items: LegendItem[] = [ ];
4242
const fields: Record<string, string[]> = Object.create(null);
4343

44-
if (
45-
type.colourFixed ||
46-
(type.type == "marker" && type.iconFixed && type.defaultIcon && (iconList.includes(type.defaultIcon) || type.defaultIcon.length == 1)) ||
47-
(type.type == "marker" && type.shapeFixed) ||
48-
(type.type == "line" && type.widthFixed) ||
49-
(type.type === "line" && type.strokeFixed)
50-
) {
51-
const item: LegendItem = {
52-
key: `legend-item-${type.id}`,
53-
value: type.name,
54-
label: formatTypeName(type.name),
55-
filtered: true
56-
};
57-
58-
if (type.colourFixed) {
59-
item.colour = type.defaultColour ? `#${type.defaultColour}` : undefined;
60-
}
61-
if (type.type == "marker" && type.iconFixed && type.defaultIcon && (iconList.includes(type.defaultIcon) || type.defaultIcon.length == 1)) {
62-
item.icon = type.defaultIcon;
63-
}
64-
if (type.type == "marker" && type.shapeFixed) {
65-
item.shape = type.defaultShape ?? "";
66-
}
67-
if (type.type == "line" && type.widthFixed) {
68-
item.width = type.defaultWidth ?? undefined;
69-
}
70-
if (type.type === "line" && type.strokeFixed) {
71-
item.stroke = type.defaultStroke;
44+
const mainItem: LegendItem = {
45+
key: `legend-item-${type.id}`,
46+
value: type.name,
47+
label: formatTypeName(type.name),
48+
filtered: true
49+
};
50+
51+
if (type.colourFixed) {
52+
mainItem.colour = type.defaultColour ? `#${type.defaultColour}` : undefined;
53+
}
54+
if (type.type == "marker" && type.iconFixed && type.defaultIcon && (iconList.includes(type.defaultIcon) || type.defaultIcon.length == 1)) {
55+
mainItem.icon = type.defaultIcon;
56+
}
57+
if (type.type == "marker") {
58+
if (type.shapeFixed) {
59+
mainItem.shape = type.defaultShape ?? "";
60+
} else {
61+
mainItem.shape = "drop";
7262
}
63+
}
64+
if (type.type == "line" && type.widthFixed) {
65+
mainItem.width = type.defaultWidth ?? undefined;
66+
}
67+
if (type.type === "line" && type.strokeFixed) {
68+
mainItem.stroke = type.defaultStroke;
69+
}
7370

74-
if (item.colour)
75-
item.bright = isBright(item.colour);
71+
if (mainItem.colour)
72+
mainItem.bright = isBright(mainItem.colour);
7673

77-
items.push(item);
78-
}
74+
items.push(mainItem);
7975

8076
for (const field of type.fields) {
8177
if (
@@ -147,20 +143,6 @@ export function getLegendItems(context: FacilMapContext): LegendType[] {
147143
});
148144
}
149145

150-
if(items.length == 0) {
151-
const item: LegendItem = {
152-
key: `legend-item-${type.id}`,
153-
value: type.name,
154-
label: formatTypeName(type.name),
155-
filtered: true
156-
};
157-
158-
if(type.type == "marker")
159-
item.shape = "drop";
160-
161-
items.push(item);
162-
}
163-
164146
const legendType: LegendType = {
165147
key: `legend-type-${type.id}`,
166148
type: type.type,

0 commit comments

Comments
 (0)