@tekkare/romulus 0.1.370 → 0.1.371
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
| `results` | - | prop morte : aucune carte ne la lisait |
|
|
35
35
|
-->
|
|
36
36
|
<script setup lang="ts">
|
|
37
|
-
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
37
|
+
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
|
38
38
|
import { RM_GEOGRAPHIES, type RmGeoShape } from '../internal/geo'
|
|
39
39
|
import { useChartTheme } from '../composables/useChartTheme'
|
|
40
40
|
|
|
@@ -64,6 +64,12 @@ const props = withDefaults(
|
|
|
64
64
|
reverseColors?: boolean
|
|
65
65
|
/** Resserre le cadrage sur la partie continentale. */
|
|
66
66
|
compact?: boolean
|
|
67
|
+
/**
|
|
68
|
+
* Zones a cadrer, nommees comme la geographie les nomme (les departements
|
|
69
|
+
* d'une region, par exemple). La carte se resserre sur leur emprise ; les
|
|
70
|
+
* autres zones restent dessinees autour. Vide ou absent : tout le pays.
|
|
71
|
+
*/
|
|
72
|
+
focus?: string[] | null
|
|
67
73
|
/** Hauteur du dessin, en pixels. */
|
|
68
74
|
height?: number
|
|
69
75
|
lang?: 'fr' | 'en'
|
|
@@ -79,6 +85,7 @@ const props = withDefaults(
|
|
|
79
85
|
source: null,
|
|
80
86
|
reverseColors: false,
|
|
81
87
|
compact: false,
|
|
88
|
+
focus: null,
|
|
82
89
|
height: 500,
|
|
83
90
|
lang: 'fr',
|
|
84
91
|
valueFormatter: undefined,
|
|
@@ -115,10 +122,51 @@ watch(
|
|
|
115
122
|
{ immediate: true },
|
|
116
123
|
)
|
|
117
124
|
|
|
118
|
-
const
|
|
125
|
+
const baseViewBox = computed(() =>
|
|
119
126
|
(props.compact ? geography.value?.compactViewBox : null) ?? geography.value?.viewBox ?? '0 0 100 100',
|
|
120
127
|
)
|
|
121
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Cadrage sur `focus` : l'emprise des zones nommees, lue sur les traces une
|
|
131
|
+
* fois dessines (getBBox), avec une marge. Le trait garde son epaisseur a
|
|
132
|
+
* l'ecran : il est reduit dans le rapport du zoom.
|
|
133
|
+
*/
|
|
134
|
+
const svgRef = ref<SVGSVGElement | null>(null)
|
|
135
|
+
const focusBox = ref<{ x: number; y: number; w: number; h: number } | null>(null)
|
|
136
|
+
|
|
137
|
+
async function frameFocus() {
|
|
138
|
+
focusBox.value = null
|
|
139
|
+
const names = new Set((props.focus ?? []).map(n => n.normalize('NFC')))
|
|
140
|
+
if (!names.size || loading.value) return
|
|
141
|
+
await nextTick()
|
|
142
|
+
const svg = svgRef.value
|
|
143
|
+
if (!svg) return
|
|
144
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity
|
|
145
|
+
for (const el of svg.querySelectorAll<SVGPathElement>('path[data-name]')) {
|
|
146
|
+
if (!names.has(String(el.dataset.name).normalize('NFC'))) continue
|
|
147
|
+
const b = el.getBBox()
|
|
148
|
+
x0 = Math.min(x0, b.x); y0 = Math.min(y0, b.y)
|
|
149
|
+
x1 = Math.max(x1, b.x + b.width); y1 = Math.max(y1, b.y + b.height)
|
|
150
|
+
}
|
|
151
|
+
if (x0 === Infinity) return
|
|
152
|
+
const pad = Math.max(x1 - x0, y1 - y0) * 0.06
|
|
153
|
+
focusBox.value = { x: x0 - pad, y: y0 - pad, w: x1 - x0 + 2 * pad, h: y1 - y0 + 2 * pad }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
watch([() => (props.focus ?? []).join('|'), loading, () => props.geography], frameFocus, { immediate: true })
|
|
157
|
+
|
|
158
|
+
const viewBox = computed(() => {
|
|
159
|
+
const f = focusBox.value
|
|
160
|
+
return f ? `${f.x} ${f.y} ${f.w} ${f.h}` : baseViewBox.value
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const strokeWidth = computed(() => {
|
|
164
|
+
const f = focusBox.value
|
|
165
|
+
if (!f) return 1
|
|
166
|
+
const baseWidth = Number(baseViewBox.value.split(/\s+/)[2]) || f.w
|
|
167
|
+
return Math.max(f.w, f.h) / baseWidth
|
|
168
|
+
})
|
|
169
|
+
|
|
122
170
|
const values = computed(() =>
|
|
123
171
|
props.data.filter(d => d.value !== null && d.value !== undefined).map(d => Number(d.value)),
|
|
124
172
|
)
|
|
@@ -243,14 +291,15 @@ const fmt = computed(() =>
|
|
|
243
291
|
|
|
244
292
|
<div class="rm-choro__plot" :style="{ height: `${height}px` }">
|
|
245
293
|
<RmSkeleton v-if="loading" height="100%" />
|
|
246
|
-
<svg v-else class="rm-choro__svg" :viewBox="viewBox" preserveAspectRatio="xMidYMid meet">
|
|
294
|
+
<svg v-else ref="svgRef" class="rm-choro__svg" :viewBox="viewBox" preserveAspectRatio="xMidYMid meet">
|
|
247
295
|
<path
|
|
248
296
|
v-for="(shape, name) in shapes"
|
|
249
297
|
:key="name"
|
|
298
|
+
:data-name="name"
|
|
250
299
|
:d="shape.path"
|
|
251
300
|
:fill="colorOf(String(name))"
|
|
252
301
|
:stroke="colorOf(String(name)) === NO_DATA ? 'var(--border-default)' : colorOf(String(name))"
|
|
253
|
-
stroke-width="
|
|
302
|
+
:stroke-width="strokeWidth"
|
|
254
303
|
class="rm-choro__shape"
|
|
255
304
|
:class="{ 'rm-choro__shape--dimmed': hovered !== null && hovered !== name }"
|
|
256
305
|
@mouseenter="onEnter(String(name), $event)"
|