@datagouv/components-next 1.0.2-dev.67 → 1.0.2-dev.69
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/{Datafair.client-mCVEbSye.js → Datafair.client-B57v03ac.js} +1 -1
- package/dist/{JsonPreview.client-D2-QXKW9.js → JsonPreview.client-C7uJkiI6.js} +2 -2
- package/dist/{MapContainer.client-fG7SH8SY.js → MapContainer.client-D9AVgKoU.js} +2 -2
- package/dist/{PdfPreview.client-BD2LoeWd.js → PdfPreview.client-3_AtEyvC.js} +2 -2
- package/dist/{Pmtiles.client-BoISUK3N.js → Pmtiles.client-D00kMVdH.js} +1 -1
- package/dist/{PreviewWrapper.vue_vue_type_script_setup_true_lang-BRkoVZX6.js → PreviewWrapper.vue_vue_type_script_setup_true_lang-NHqgUJAK.js} +1 -1
- package/dist/{XmlPreview.client-D4beM-9H.js → XmlPreview.client-Bn2kpzCg.js} +3 -3
- package/dist/components-next.css +1 -1
- package/dist/components-next.js +166 -157
- package/dist/components.css +1 -1
- package/dist/{index-CHqTMS42.js → index-BPZOlCaf.js} +1 -1
- package/dist/{main-vXPsdhWv.js → main-By-J5lfU.js} +79299 -31033
- package/dist/{vue3-xml-viewer.common-S2fcy_RO.js → vue3-xml-viewer.common-D-uUQRA7.js} +1 -1
- package/package.json +2 -1
- package/src/components/Chart/ChartViewer.vue +226 -0
- package/src/components/Chart/ChartViewerWrapper.vue +170 -0
- package/src/components/Form/Listbox.vue +101 -0
- package/src/components/ResourceAccordion/Preview.vue +1 -1
- package/src/composables/useHasTabularData.ts +6 -0
- package/src/config.ts +1 -0
- package/src/functions/charts.ts +68 -0
- package/src/functions/tabularApi.ts +136 -7
- package/src/main.ts +27 -0
- package/src/types/visualizations.ts +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagouv/components-next",
|
|
3
|
-
"version": "1.0.2-dev.
|
|
3
|
+
"version": "1.0.2-dev.69",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@vueuse/router": "^14.2.1",
|
|
26
26
|
"chart.js": "^4.4.8",
|
|
27
27
|
"dompurify": "^3.2.5",
|
|
28
|
+
"echarts": "^6.0.0",
|
|
28
29
|
"geopf-extensions-openlayers": "^1.0.0-beta.5",
|
|
29
30
|
"leaflet": "^1.9.4",
|
|
30
31
|
"maplibre-gl": "^5.6.2",
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="chartContainer"
|
|
4
|
+
class="w-full min-h-96"
|
|
5
|
+
/>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { format, use, type ComposeOption } from 'echarts/core'
|
|
10
|
+
import { CanvasRenderer } from 'echarts/renderers'
|
|
11
|
+
import { LineChart, BarChart, type BarSeriesOption, type LineSeriesOption } from 'echarts/charts'
|
|
12
|
+
import { TitleComponent, TooltipComponent, LegendComponent, GridComponent, DatasetComponent } from 'echarts/components'
|
|
13
|
+
import { init, type ECharts as EChartsType } from 'echarts'
|
|
14
|
+
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
15
|
+
import { summarize } from '../../functions/helpers'
|
|
16
|
+
import type { Chart, XAxis, YAxis, XAxisForm, ChartForApi } from '../../types/visualizations'
|
|
17
|
+
import { useTranslation } from '../../composables/useTranslation'
|
|
18
|
+
|
|
19
|
+
use([CanvasRenderer, LineChart, BarChart, TitleComponent, TooltipComponent, LegendComponent, GridComponent, DatasetComponent])
|
|
20
|
+
|
|
21
|
+
const props = defineProps<{
|
|
22
|
+
chart: Chart | ChartForApi
|
|
23
|
+
series: {
|
|
24
|
+
data: Record<string, Array<Record<string, unknown>>>
|
|
25
|
+
columns: Record<string, Array<string>>
|
|
26
|
+
}
|
|
27
|
+
}>()
|
|
28
|
+
|
|
29
|
+
const { locale } = useTranslation()
|
|
30
|
+
const chartContainer = ref<HTMLElement | null>(null)
|
|
31
|
+
let echartsInstance: EChartsType | null = null
|
|
32
|
+
|
|
33
|
+
function mapXAxisType(xAxis: XAxis | XAxisForm): 'category' | 'value' {
|
|
34
|
+
if (!xAxis) return 'category'
|
|
35
|
+
return (xAxis.type ?? 'discrete') === 'continuous' ? 'value' : 'category'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildYAxisFormatter(yAxis: YAxis): ((value: number) => string) | undefined {
|
|
39
|
+
return (value: number) => {
|
|
40
|
+
const v = summarize(value)
|
|
41
|
+
if (!yAxis.unit) return v
|
|
42
|
+
if (yAxis.unit_position === 'prefix') return `${yAxis.unit} ${v}`
|
|
43
|
+
return `${v} ${yAxis.unit}`
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const echartsOption = computed(() => {
|
|
48
|
+
const seriesCount = props.chart.series.length
|
|
49
|
+
if (!props.chart.series || seriesCount === 0) return
|
|
50
|
+
|
|
51
|
+
const seriesArray = props.chart.series.map((s) => {
|
|
52
|
+
const xColumn = s.column_x_name_override ?? props.chart.x_axis.column_x
|
|
53
|
+
const yColumn = s.aggregate_y ? `${s.column_y}__${s.aggregate_y}` : s.column_y
|
|
54
|
+
const resourceId = s.resource_id
|
|
55
|
+
|
|
56
|
+
if (!xColumn || !yColumn || !resourceId || !s.type || !props.series.data[resourceId] || !props.series.columns[resourceId]) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const sortedData = [...props.series.data[resourceId]]
|
|
61
|
+
const sortBy = props.chart.x_axis.sort_x_by
|
|
62
|
+
const sortDirection = props.chart.x_axis.sort_x_direction ?? 'asc'
|
|
63
|
+
|
|
64
|
+
if (sortBy && sortDirection && props.chart.x_axis.column_x) {
|
|
65
|
+
const sortKey = sortBy === 'axis_x' ? xColumn : yColumn
|
|
66
|
+
sortedData.sort((a, b) => {
|
|
67
|
+
const valA = a[sortKey]
|
|
68
|
+
const valB = b[sortKey]
|
|
69
|
+
|
|
70
|
+
const aNullish = valA === null || valA === undefined
|
|
71
|
+
const bNullish = valB === null || valB === undefined
|
|
72
|
+
if (aNullish && bNullish) return 0
|
|
73
|
+
if (aNullish) return sortDirection === 'asc' ? -1 : 1
|
|
74
|
+
if (bNullish) return sortDirection === 'asc' ? 1 : -1
|
|
75
|
+
|
|
76
|
+
if (valA instanceof Date && valB instanceof Date) {
|
|
77
|
+
const timeA = valA.getTime()
|
|
78
|
+
const timeB = valB.getTime()
|
|
79
|
+
if (timeA < timeB) return sortDirection === 'asc' ? -1 : 1
|
|
80
|
+
if (timeA > timeB) return sortDirection === 'asc' ? 1 : -1
|
|
81
|
+
return 0
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof valA === 'boolean' && typeof valB === 'boolean') {
|
|
85
|
+
if (valA === valB) return 0
|
|
86
|
+
// false comes before true in ascending order
|
|
87
|
+
if (valB) return sortDirection === 'asc' ? -1 : 1
|
|
88
|
+
return sortDirection === 'asc' ? 1 : -1
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const numA = Number(valA)
|
|
92
|
+
const numB = Number(valB)
|
|
93
|
+
const bothNumeric = !isNaN(numA) && !isNaN(numB)
|
|
94
|
+
|
|
95
|
+
if (bothNumeric) {
|
|
96
|
+
if (numA < numB) return sortDirection === 'asc' ? -1 : 1
|
|
97
|
+
if (numA > numB) return sortDirection === 'asc' ? 1 : -1
|
|
98
|
+
return 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const strA = String(valA)
|
|
102
|
+
const strB = String(valB)
|
|
103
|
+
return strA.localeCompare(strB, locale, {
|
|
104
|
+
sensitivity: 'base',
|
|
105
|
+
numeric: true,
|
|
106
|
+
}) * (sortDirection === 'asc' ? 1 : -1)
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
series: {
|
|
112
|
+
type: s.type === 'histogram' ? 'bar' : 'line',
|
|
113
|
+
dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
|
|
114
|
+
name: yColumn,
|
|
115
|
+
encode: {
|
|
116
|
+
x: xColumn,
|
|
117
|
+
y: yColumn,
|
|
118
|
+
},
|
|
119
|
+
} as LineSeriesOption | BarSeriesOption,
|
|
120
|
+
data: {
|
|
121
|
+
source: sortedData,
|
|
122
|
+
dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const seriesData = {
|
|
128
|
+
series: [] as Array<LineSeriesOption | BarSeriesOption>,
|
|
129
|
+
data: [] as Array<Record<string, unknown>>,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (const curr of seriesArray) {
|
|
133
|
+
if (!curr) continue
|
|
134
|
+
seriesData.series.push(curr.series)
|
|
135
|
+
seriesData.data.push(curr.data)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
dataset: [...seriesData.data],
|
|
140
|
+
title: {
|
|
141
|
+
text: props.chart.title,
|
|
142
|
+
left: 'center',
|
|
143
|
+
},
|
|
144
|
+
tooltip: {
|
|
145
|
+
trigger: 'axis' as const,
|
|
146
|
+
formatter: (params: Array<{ value: Record<string, unknown>, axisValueLabel: string, seriesName: string }>) => {
|
|
147
|
+
let tooltip = ''
|
|
148
|
+
const formatter = new Intl.NumberFormat('fr-FR')
|
|
149
|
+
for (const param of params) {
|
|
150
|
+
const seriesName = param.seriesName
|
|
151
|
+
tooltip += `${format.encodeHTML(param.axisValueLabel)}: <strong>${formatter.format(Number(param.value[seriesName]))}</strong><br>`
|
|
152
|
+
}
|
|
153
|
+
return tooltip
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
legend: {
|
|
157
|
+
show: seriesData.series.length > 1,
|
|
158
|
+
bottom: 0,
|
|
159
|
+
},
|
|
160
|
+
grid: {
|
|
161
|
+
top: 60,
|
|
162
|
+
bottom: 40,
|
|
163
|
+
left: 20,
|
|
164
|
+
right: 20,
|
|
165
|
+
containLabel: true,
|
|
166
|
+
},
|
|
167
|
+
xAxis: {
|
|
168
|
+
type: mapXAxisType(props.chart.x_axis),
|
|
169
|
+
name: (props.chart.x_axis as XAxis).column_x,
|
|
170
|
+
},
|
|
171
|
+
yAxis: {
|
|
172
|
+
type: 'value' as const,
|
|
173
|
+
name: props.chart.y_axis.label ?? undefined,
|
|
174
|
+
min: props.chart.y_axis.min ?? undefined,
|
|
175
|
+
max: props.chart.y_axis.max ?? undefined,
|
|
176
|
+
axisLabel: {
|
|
177
|
+
formatter: buildYAxisFormatter(props.chart.y_axis),
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
series: seriesData.series,
|
|
181
|
+
} satisfies ComposeOption<
|
|
182
|
+
| BarSeriesOption
|
|
183
|
+
| LineSeriesOption
|
|
184
|
+
>
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
onMounted(() => {
|
|
188
|
+
if (chartContainer.value) {
|
|
189
|
+
echartsInstance = init(chartContainer.value)
|
|
190
|
+
updateChart()
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
onUnmounted(() => {
|
|
195
|
+
if (echartsInstance) {
|
|
196
|
+
echartsInstance.dispose()
|
|
197
|
+
echartsInstance = null
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
watch(() => props.chart, updateChart, { deep: true })
|
|
202
|
+
|
|
203
|
+
watch(() => props.series, updateChart, { deep: true })
|
|
204
|
+
|
|
205
|
+
function updateChart() {
|
|
206
|
+
if (!echartsInstance) return
|
|
207
|
+
const option = echartsOption.value
|
|
208
|
+
if (option) {
|
|
209
|
+
echartsInstance.setOption(option, { notMerge: true })
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const handleResize = () => {
|
|
214
|
+
if (echartsInstance) {
|
|
215
|
+
echartsInstance.resize()
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
onMounted(() => {
|
|
220
|
+
window.addEventListener('resize', handleResize)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
onUnmounted(() => {
|
|
224
|
+
window.removeEventListener('resize', handleResize)
|
|
225
|
+
})
|
|
226
|
+
</script>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<LoadingBlock
|
|
3
|
+
:status="status"
|
|
4
|
+
:data="series"
|
|
5
|
+
>
|
|
6
|
+
<template #default="{ data }">
|
|
7
|
+
<ChartViewer
|
|
8
|
+
:chart="chart"
|
|
9
|
+
:series="data"
|
|
10
|
+
/>
|
|
11
|
+
</template>
|
|
12
|
+
<template #error>
|
|
13
|
+
<div class="text-center py-8 text-gray-500">
|
|
14
|
+
{{ t('Une erreur est survenue lors du chargement des données du graphique.') }}
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
</LoadingBlock>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import { reactive, ref, watch } from 'vue'
|
|
22
|
+
import ChartViewer from './ChartViewer.vue'
|
|
23
|
+
import LoadingBlock from '../../components/LoadingBlock.vue'
|
|
24
|
+
import { useComponentsConfig } from '../../config'
|
|
25
|
+
import { fetchTabularData, useGetProfile } from '../../functions/tabularApi'
|
|
26
|
+
import type { Chart, ChartForApi } from '../../types/visualizations'
|
|
27
|
+
import { useTranslation } from '../../composables/useTranslation'
|
|
28
|
+
|
|
29
|
+
const props = defineProps<{
|
|
30
|
+
chart: Chart | ChartForApi
|
|
31
|
+
}>()
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
columns: [columns: Record<string, Array<string>>]
|
|
35
|
+
}>()
|
|
36
|
+
|
|
37
|
+
const { t } = useTranslation()
|
|
38
|
+
const config = useComponentsConfig()
|
|
39
|
+
const getProfile = useGetProfile()
|
|
40
|
+
|
|
41
|
+
const status = ref<'idle' | 'pending' | 'success' | 'error'>('idle')
|
|
42
|
+
const error = ref<Error | null>(null)
|
|
43
|
+
|
|
44
|
+
const pendingOperations = ref(0)
|
|
45
|
+
|
|
46
|
+
const series = reactive<{
|
|
47
|
+
data: Record<string, Array<Record<string, unknown>>>
|
|
48
|
+
columns: Record<string, Array<string>>
|
|
49
|
+
}>({
|
|
50
|
+
data: {},
|
|
51
|
+
columns: {},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
async function fetchSeriesProfile() {
|
|
55
|
+
pendingOperations.value++
|
|
56
|
+
status.value = 'pending'
|
|
57
|
+
error.value = null
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
if (props.chart.series.length === 0) {
|
|
61
|
+
status.value = 'success'
|
|
62
|
+
series.data = {}
|
|
63
|
+
series.columns = {}
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const fetchPromises = props.chart.series
|
|
68
|
+
.filter(serie => serie.resource_id)
|
|
69
|
+
.map(async (serie) => {
|
|
70
|
+
return {
|
|
71
|
+
id: serie.resource_id,
|
|
72
|
+
profile: await getProfile(serie.resource_id),
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const results = (await Promise.allSettled(fetchPromises))
|
|
77
|
+
.filter(r => r.status === 'fulfilled')
|
|
78
|
+
.map(r => r.value)
|
|
79
|
+
series.columns = Object.fromEntries(results.map(result => [
|
|
80
|
+
result.id,
|
|
81
|
+
result.profile.profile.header,
|
|
82
|
+
]))
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
error.value = err instanceof Error ? err : new Error('Failed to fetch series profile')
|
|
86
|
+
status.value = 'error'
|
|
87
|
+
console.error(err)
|
|
88
|
+
series.columns = {}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
pendingOperations.value--
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function fetchSeriesData() {
|
|
96
|
+
pendingOperations.value++
|
|
97
|
+
status.value = 'pending'
|
|
98
|
+
error.value = null
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
if (props.chart.series.length === 0 || !props.chart.x_axis.column_x) {
|
|
102
|
+
status.value = 'success'
|
|
103
|
+
series.data = {}
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const fetchPromises = props.chart.series
|
|
108
|
+
.filter((serie) => {
|
|
109
|
+
const xColumn = serie.column_x_name_override ?? props.chart.x_axis.column_x
|
|
110
|
+
return xColumn && serie.resource_id && serie.column_y
|
|
111
|
+
})
|
|
112
|
+
.map(async (serie) => {
|
|
113
|
+
const xColumn = serie.column_x_name_override ?? props.chart.x_axis.column_x
|
|
114
|
+
return {
|
|
115
|
+
id: serie.resource_id,
|
|
116
|
+
data: await fetchTabularData(config, {
|
|
117
|
+
columns: serie.aggregate_y ? undefined : [xColumn, serie.column_y],
|
|
118
|
+
resourceId: serie.resource_id,
|
|
119
|
+
page: 1,
|
|
120
|
+
pageSize: 100,
|
|
121
|
+
groupBy: xColumn,
|
|
122
|
+
aggregation: serie.column_y && serie.aggregate_y
|
|
123
|
+
? {
|
|
124
|
+
column: serie.column_y,
|
|
125
|
+
type: serie.aggregate_y,
|
|
126
|
+
}
|
|
127
|
+
: undefined,
|
|
128
|
+
filters: serie.filters ?? undefined,
|
|
129
|
+
}),
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const results = (await Promise.allSettled(fetchPromises))
|
|
134
|
+
.filter(r => r.status === 'fulfilled')
|
|
135
|
+
.map(r => r.value)
|
|
136
|
+
series.data = Object.fromEntries(results.map(result => [
|
|
137
|
+
result.id,
|
|
138
|
+
result.data.data,
|
|
139
|
+
]))
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
error.value = err instanceof Error ? err : new Error('Failed to fetch series data')
|
|
143
|
+
status.value = 'error'
|
|
144
|
+
series.data = {}
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
pendingOperations.value--
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
watch(() => props.chart.series, async () => {
|
|
152
|
+
await fetchSeriesProfile()
|
|
153
|
+
}, { immediate: true, deep: true })
|
|
154
|
+
|
|
155
|
+
watch([() => props.chart.series, () => props.chart.x_axis.column_x], async () => {
|
|
156
|
+
await fetchSeriesData()
|
|
157
|
+
}, { immediate: true, deep: true })
|
|
158
|
+
|
|
159
|
+
watch(() => series.columns, () => {
|
|
160
|
+
emit('columns', series.columns)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
watch(pendingOperations, (count) => {
|
|
164
|
+
if (count === 0) {
|
|
165
|
+
if (error.value === null && status.value === 'pending') {
|
|
166
|
+
status.value = 'success'
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
</script>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Listbox v-model="model">
|
|
3
|
+
<div class="relative min-w-0">
|
|
4
|
+
<div
|
|
5
|
+
ref="floatingReference"
|
|
6
|
+
class="relative w-full cursor-default overflow-hidden bg-white text-left shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-teal-300 sm:text-sm"
|
|
7
|
+
>
|
|
8
|
+
<ListboxButton class="input shadow-input text-sm flex items-center gap-2">
|
|
9
|
+
<slot name="button">
|
|
10
|
+
<div class="w-full flex items-center justify-between gap-2">
|
|
11
|
+
<div
|
|
12
|
+
class="truncate"
|
|
13
|
+
:class="{ 'text-new-disabled-text': isDisabled(model) }"
|
|
14
|
+
>
|
|
15
|
+
{{ displayValue(model) }}
|
|
16
|
+
</div>
|
|
17
|
+
<RiArrowDownSLine class="flex-none size-4 justify-self-end" />
|
|
18
|
+
</div>
|
|
19
|
+
</slot>
|
|
20
|
+
</ListboxButton>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<ListboxOptions
|
|
24
|
+
ref="popover"
|
|
25
|
+
:style="floatingStyles"
|
|
26
|
+
class="z-10 mt-1 absolute max-h-60 min-w-80 w-full overflow-auto rounded-md bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-none sm:text-sm pl-0"
|
|
27
|
+
>
|
|
28
|
+
<ListboxOption
|
|
29
|
+
v-for="option in options"
|
|
30
|
+
:key="getOptionId(toValue(option))"
|
|
31
|
+
v-slot="{ active, selected }"
|
|
32
|
+
as="template"
|
|
33
|
+
:value="option"
|
|
34
|
+
>
|
|
35
|
+
<li
|
|
36
|
+
class="relative cursor-default select-none py-2 pr-4 list-none flex items-center gap-2 text-gray-900"
|
|
37
|
+
:class="{
|
|
38
|
+
'bg-gray-lower': active && !isDisabled(toValue(option)),
|
|
39
|
+
'text-new-disabled-text': isDisabled(toValue(option)),
|
|
40
|
+
'pl-2': selected,
|
|
41
|
+
'pl-6': !selected,
|
|
42
|
+
}"
|
|
43
|
+
>
|
|
44
|
+
<div class="flex items-center justify-center aspect-square">
|
|
45
|
+
<RiCheckLine
|
|
46
|
+
v-if="selected"
|
|
47
|
+
class="size-4"
|
|
48
|
+
:class="isDisabled(toValue(option)) ?' text-new-disabled-text' : 'text-new-primary'"
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
<slot
|
|
52
|
+
name="option"
|
|
53
|
+
v-bind="{ option, active }"
|
|
54
|
+
>
|
|
55
|
+
{{ displayValue(option) }}
|
|
56
|
+
</slot>
|
|
57
|
+
</li>
|
|
58
|
+
</ListboxOption>
|
|
59
|
+
</ListboxOptions>
|
|
60
|
+
</div>
|
|
61
|
+
</Listbox>
|
|
62
|
+
</template>
|
|
63
|
+
|
|
64
|
+
<script setup lang="ts" generic="T extends string | number | object">
|
|
65
|
+
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/vue'
|
|
66
|
+
import { useFloating, autoUpdate, autoPlacement } from '@floating-ui/vue'
|
|
67
|
+
import { toValue, useTemplateRef } from 'vue'
|
|
68
|
+
import { RiArrowDownSLine, RiCheckLine } from '@remixicon/vue'
|
|
69
|
+
|
|
70
|
+
withDefaults(defineProps<{
|
|
71
|
+
options?: Array<T>
|
|
72
|
+
getOptionId?: (option: T) => string | number
|
|
73
|
+
displayValue: (option: T | null) => string
|
|
74
|
+
isDisabled?: (option: T | null) => boolean
|
|
75
|
+
}>(), {
|
|
76
|
+
getOptionId: (option: T): string | number => {
|
|
77
|
+
if (typeof option === 'string') return option
|
|
78
|
+
if (typeof option === 'number') return option
|
|
79
|
+
if (typeof option === 'object' && 'id' in option) return option.id as string
|
|
80
|
+
|
|
81
|
+
throw new Error('Please set getOptionId()')
|
|
82
|
+
},
|
|
83
|
+
isDisabled: (option: T | null): boolean => {
|
|
84
|
+
if (option && typeof option === 'object' && 'disabled' in option) return option.disabled as boolean
|
|
85
|
+
|
|
86
|
+
return false
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const model = defineModel<T | null>({ required: true })
|
|
91
|
+
|
|
92
|
+
const referenceRef = useTemplateRef('floatingReference')
|
|
93
|
+
const floatingRef = useTemplateRef<InstanceType<typeof ListboxOptions>>('popover')
|
|
94
|
+
const { floatingStyles } = useFloating(referenceRef, floatingRef, {
|
|
95
|
+
middleware: [autoPlacement({
|
|
96
|
+
allowedPlacements: ['bottom-start', 'bottom', 'bottom-end'],
|
|
97
|
+
crossAxis: true,
|
|
98
|
+
})],
|
|
99
|
+
whileElementsMounted: autoUpdate,
|
|
100
|
+
})
|
|
101
|
+
</script>
|
|
@@ -142,7 +142,7 @@ async function getTableInfos(page: number, sortConfig?: SortConfig | null) {
|
|
|
142
142
|
try {
|
|
143
143
|
// Check that this function return wanted data
|
|
144
144
|
const response = await getData(config, props.resource.id, page, sortConfig)
|
|
145
|
-
if ('data' in response && response.data && response.data
|
|
145
|
+
if ('data' in response && response.data && 0 in response.data) {
|
|
146
146
|
// Update existing rows
|
|
147
147
|
rows.value = response.data
|
|
148
148
|
columns.value = Object.keys(response.data[0]).filter(item => item !== '__id')
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { useComponentsConfig } from '../config'
|
|
2
2
|
import type { Resource } from '../types/resources'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Composable to determine if a resource has tabular data.
|
|
6
|
+
* This is used to show the "Données" tab for tabular files AND the "Structure des données" tab (for tabular data structure).
|
|
7
|
+
*
|
|
8
|
+
* @returns A function to check if a resource has tabular data.
|
|
9
|
+
*/
|
|
4
10
|
export const useHasTabularData = () => {
|
|
5
11
|
const config = useComponentsConfig()
|
|
6
12
|
|
package/src/config.ts
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Chart, ChartForm, ChartForApi, Filter } from '../types/visualizations'
|
|
2
|
+
|
|
3
|
+
export function toChartForm(chart: Chart) {
|
|
4
|
+
const seriesFilter = chart.series[0]?.filters as Filter | null
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
title: chart.title,
|
|
8
|
+
description: chart.description,
|
|
9
|
+
private: chart.private,
|
|
10
|
+
owned: chart.organization ? { organization: chart.organization.id, owner: null } : { owner: chart.owner.id, organization: null },
|
|
11
|
+
x_axis: {
|
|
12
|
+
column_x: chart.x_axis.column_x,
|
|
13
|
+
type: chart.x_axis.type,
|
|
14
|
+
sort_combined: chart.x_axis.sort_x_by && chart.x_axis.sort_x_direction
|
|
15
|
+
? `${chart.x_axis.sort_x_by}-${chart.x_axis.sort_x_direction}`
|
|
16
|
+
: '',
|
|
17
|
+
},
|
|
18
|
+
y_axis: {
|
|
19
|
+
label: chart.y_axis.label || '',
|
|
20
|
+
min: chart.y_axis.min,
|
|
21
|
+
max: chart.y_axis.max,
|
|
22
|
+
unit: chart.y_axis.unit || '',
|
|
23
|
+
unit_position: chart.y_axis.unit_position || 'suffix',
|
|
24
|
+
},
|
|
25
|
+
series: chart.series.map(serie => ({
|
|
26
|
+
...serie,
|
|
27
|
+
aggregate_y: serie.aggregate_y || '',
|
|
28
|
+
})),
|
|
29
|
+
extras: chart.extras,
|
|
30
|
+
chart_type: chart.series[0] ? chart.series[0].type : null,
|
|
31
|
+
filter: seriesFilter ?? null,
|
|
32
|
+
} satisfies ChartForm
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function toChartApi(chartForm: ChartForm): ChartForApi {
|
|
36
|
+
const xAxis = {
|
|
37
|
+
column_x: chartForm.x_axis.column_x,
|
|
38
|
+
type: chartForm.x_axis.type,
|
|
39
|
+
sort_x_by: chartForm.x_axis.sort_combined
|
|
40
|
+
? (chartForm.x_axis.sort_combined.split('-')[0] as 'axis_x' | 'axis_y')
|
|
41
|
+
: null,
|
|
42
|
+
sort_x_direction: chartForm.x_axis.sort_combined
|
|
43
|
+
? (chartForm.x_axis.sort_combined.split('-')[1] as 'asc' | 'desc')
|
|
44
|
+
: null,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...chartForm.owned,
|
|
49
|
+
title: chartForm.title,
|
|
50
|
+
description: chartForm.description,
|
|
51
|
+
private: chartForm.private,
|
|
52
|
+
x_axis: xAxis,
|
|
53
|
+
y_axis: {
|
|
54
|
+
label: chartForm.y_axis.label ?? null,
|
|
55
|
+
min: chartForm.y_axis.min ?? null,
|
|
56
|
+
max: chartForm.y_axis.max ?? null,
|
|
57
|
+
unit: chartForm.y_axis.unit ?? null,
|
|
58
|
+
unit_position: chartForm.y_axis.unit_position ?? null,
|
|
59
|
+
},
|
|
60
|
+
series: chartForm.series.map((serie, index) => ({
|
|
61
|
+
...serie,
|
|
62
|
+
type: index === 0 && chartForm.chart_type ? chartForm.chart_type : serie.type,
|
|
63
|
+
aggregate_y: serie.aggregate_y || null,
|
|
64
|
+
filters: serie.filters || (index === 0 && chartForm.filter ? chartForm.filter : null),
|
|
65
|
+
})),
|
|
66
|
+
extras: chartForm.extras,
|
|
67
|
+
}
|
|
68
|
+
}
|