@datagouv/components-next 1.3.0 → 1.4.0

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.
Files changed (131) hide show
  1. package/dist/{Control-b-43UT2B.js → Control-B9WQxlpJ.js} +10 -10
  2. package/dist/{Datafair.client-BrjISlaZ.js → Datafair.client-D_6yzJUG.js} +9 -9
  3. package/dist/{Event-py_AAwJY.js → Event-iXDrp-fy.js} +15 -15
  4. package/dist/{Image-BHQYZWzH.js → Image-mNMBOofs.js} +22 -22
  5. package/dist/ImagePreview.client-B0iPhFm3.js +36 -0
  6. package/dist/{JsonPreview.client-DivFAnbN.js → JsonPreview.client-DSl1kiwC.js} +2 -2
  7. package/dist/{Map-CtP7leHl.js → Map-BfqKMw0S.js} +165 -165
  8. package/dist/{MapContainer.client-Cq8tNLZZ.js → MapContainer.client-BSfpk_rT.js} +17 -17
  9. package/dist/{OSM-gdDSIsDA.js → OSM-CcrUhItr.js} +1 -1
  10. package/dist/{PdfPreview.client-BNBgLsK2.js → PdfPreview.client-BANFeM6K.js} +438 -427
  11. package/dist/{Pmtiles.client-CQi5Rw8W.js → Pmtiles.client-DH9ZrsZR.js} +6177 -5967
  12. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-I8EZCgzp.js +60 -0
  13. package/dist/{ScaleLine-hG-FhNqy.js → ScaleLine-VGQ7nkMS.js} +2 -2
  14. package/dist/{Tile-D6rFonpT.js → Tile-CSpn0Ca8.js} +47 -47
  15. package/dist/{TileImage-cfrEgz5y.js → TileImage-CpbaEFwd.js} +44 -44
  16. package/dist/{View-vp7vDb9q.js → View-BYBpt-AU.js} +58 -58
  17. package/dist/{XmlPreview.client-XCsNvnsZ.js → XmlPreview.client-KCB5mwVf.js} +3 -3
  18. package/dist/{common-C8efyyuc.js → common-BoeTUnDZ.js} +58 -58
  19. package/dist/components-next.css +1 -1
  20. package/dist/components-next.js +199 -172
  21. package/dist/components.css +1 -1
  22. package/dist/{index-CXUamc8Z.js → index-DHWzX5vK.js} +4668 -4466
  23. package/dist/{leaflet-src-BRKv9Ksv.js → leaflet-src-pVQfonBI.js} +1 -1
  24. package/dist/{main-DKu5SOAl.js → main-BDcYkhOc.js} +41684 -33432
  25. package/dist/{proj-CsjVeojN.js → proj-DxGbobp7.js} +110 -110
  26. package/dist/{tilecoord-CPcQJnrF.js → tilecoord-DvX7WWiA.js} +94 -94
  27. package/dist/{vue3-xml-viewer.common-BIaEIFYG.js → vue3-xml-viewer.common-Bdcn54ST.js} +1 -1
  28. package/package.json +28 -27
  29. package/src/components/ActivityList/ActivityList.vue +21 -12
  30. package/src/components/AppLink.vue +3 -0
  31. package/src/components/BannerAction.vue +6 -2
  32. package/src/components/Chart/ChartViewer.vue +111 -17
  33. package/src/components/Chart/ChartViewerWrapper.vue +28 -16
  34. package/src/components/ChartCard.vue +112 -0
  35. package/src/components/CopyButton.vue +6 -2
  36. package/src/components/DataserviceCard.vue +23 -6
  37. package/src/components/DataserviceQuality.vue +82 -0
  38. package/src/components/DataserviceQualityInline.vue +31 -0
  39. package/src/components/DataserviceQualityTooltipContent.vue +79 -0
  40. package/src/components/DatasetCard.vue +17 -6
  41. package/src/components/DatasetInformation/DatasetTemporalitySection.vue +7 -4
  42. package/src/components/DatasetQuality.vue +11 -11
  43. package/src/components/DatasetQualityInline.vue +2 -2
  44. package/src/components/DatasetQualityTooltipContent.vue +1 -1
  45. package/src/components/DiscussionMessageCard.vue +14 -15
  46. package/src/components/Form/SchemaSelect.vue +2 -0
  47. package/src/components/FormattedDate.vue +69 -0
  48. package/src/components/LoadingBlock.vue +4 -1
  49. package/src/components/ObjectCard.vue +4 -1
  50. package/src/components/ObjectCardOwner.vue +13 -1
  51. package/src/components/Pagination.vue +18 -58
  52. package/src/components/Placeholder.vue +3 -2
  53. package/src/components/PostCard.vue +13 -15
  54. package/src/components/ResourceAccordion/Datafair.client.vue +1 -1
  55. package/src/components/ResourceAccordion/Downloads.vue +19 -7
  56. package/src/components/ResourceAccordion/ImagePreview.client.vue +48 -0
  57. package/src/components/ResourceAccordion/MapContainer.client.vue +1 -8
  58. package/src/components/ResourceAccordion/Metadata.vue +21 -5
  59. package/src/components/ResourceAccordion/PdfPreview.client.vue +36 -12
  60. package/src/components/ResourceAccordion/PdfSkeleton.vue +44 -0
  61. package/src/components/ResourceAccordion/Pmtiles.client.vue +27 -18
  62. package/src/components/ResourceAccordion/Preview.vue +8 -4
  63. package/src/components/ResourceAccordion/PreviewWrapper.vue +17 -10
  64. package/src/components/ResourceAccordion/ResourceAccordion.vue +29 -9
  65. package/src/components/ResourceExplorer/ResourceExplorer.vue +105 -209
  66. package/src/components/ResourceExplorer/ResourceExplorerHeader.vue +79 -0
  67. package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +104 -71
  68. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +136 -183
  69. package/src/components/ResourceExplorer/ResourceMainAction.vue +240 -0
  70. package/src/components/ResourceExplorer/ResourceSelector.vue +24 -86
  71. package/src/components/ResourceExplorer/ResourceViewerHeader.vue +124 -0
  72. package/src/components/ResourceExplorer/ResourceViewerSkeleton.vue +96 -0
  73. package/src/components/ResourceListItem.vue +168 -0
  74. package/src/components/ReuseCard.vue +18 -6
  75. package/src/components/ReuseDetails.vue +2 -2
  76. package/src/components/ReuseHorizontalCard.vue +4 -3
  77. package/src/components/SchemaCard.vue +10 -1
  78. package/src/components/Search/Filter/AccessTypeFilter.vue +2 -2
  79. package/src/components/Search/GlobalSearch.vue +12 -8
  80. package/src/components/Search/SearchInput.vue +1 -1
  81. package/src/components/Search/Sidemenu.vue +4 -3
  82. package/src/components/SmallChart.vue +11 -10
  83. package/src/components/StatBox.vue +13 -5
  84. package/src/components/TabularExplorer/TabularActiveFilters.vue +79 -0
  85. package/src/components/TabularExplorer/TabularCell.vue +7 -8
  86. package/src/components/TabularExplorer/TabularCellPopover.vue +19 -3
  87. package/src/components/TabularExplorer/TabularColumnsMenu.vue +112 -0
  88. package/src/components/TabularExplorer/TabularDateField.vue +41 -0
  89. package/src/components/TabularExplorer/TabularDateFilter.vue +403 -0
  90. package/src/components/TabularExplorer/TabularExplorer.vue +122 -913
  91. package/src/components/TabularExplorer/TabularFilterContent.vue +33 -25
  92. package/src/components/TabularExplorer/TabularFilterPopover.vue +7 -7
  93. package/src/components/TabularExplorer/TabularMobileFilterButton.vue +21 -0
  94. package/src/components/TabularExplorer/TabularMobileFilters.vue +150 -0
  95. package/src/components/TabularExplorer/TabularRowsInfo.vue +31 -0
  96. package/src/components/TabularExplorer/TabularSkeleton.vue +92 -0
  97. package/src/components/TabularExplorer/TabularTable.vue +484 -0
  98. package/src/components/TabularExplorer/TabularToolbar.vue +25 -0
  99. package/src/components/TabularExplorer/types.ts +32 -20
  100. package/src/components/TabularExplorer/useColumnMetadata.ts +98 -0
  101. package/src/components/TabularExplorer/useTabularContext.ts +82 -0
  102. package/src/components/TopicCard.vue +15 -14
  103. package/src/composables/useActiveDescendant.ts +5 -0
  104. package/src/composables/useDatasetResources.ts +164 -0
  105. package/src/composables/useHasTabularData.ts +2 -1
  106. package/src/composables/useResizable.ts +46 -0
  107. package/src/composables/useResourceCapabilities.ts +47 -39
  108. package/src/composables/useTranslation.ts +24 -9
  109. package/src/config.ts +1 -0
  110. package/src/functions/charts.ts +32 -1
  111. package/src/functions/dates.ts +26 -7
  112. package/src/functions/helpers.ts +15 -0
  113. package/src/functions/metrics.ts +57 -56
  114. package/src/functions/owned.ts +21 -0
  115. package/src/functions/paginate.ts +46 -0
  116. package/src/functions/resourceCapabilities.ts +34 -0
  117. package/src/functions/resources.ts +83 -0
  118. package/src/functions/schemas.ts +27 -0
  119. package/src/functions/scroll.ts +20 -0
  120. package/src/functions/tabular.ts +119 -4
  121. package/src/functions/tabularApi.ts +1 -43
  122. package/src/main.ts +32 -6
  123. package/src/types/dataservices.ts +15 -0
  124. package/src/types/organizations.ts +10 -0
  125. package/src/types/reuses.ts +12 -1
  126. package/src/types/search.ts +2 -2
  127. package/src/types/visualizations.ts +5 -0
  128. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-C3dDzrIr.js +0 -61
  129. /package/src/components/{DatasetQualityItem.vue → QualityItem.vue} +0 -0
  130. /package/src/components/{DatasetQualityItemWarning.vue → QualityItemWarning.vue} +0 -0
  131. /package/src/components/{DatasetQualityScore.vue → QualityScore.vue} +0 -0
@@ -1,4 +1,4 @@
1
- import { b7 as Ke } from "./main-DKu5SOAl.js";
1
+ import { g as Ke } from "./main-BDcYkhOc.js";
2
2
  import We from "vue";
3
3
  function Fe(I, K) {
4
4
  for (var V = 0; V < K.length; V++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagouv/components-next",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -23,29 +23,31 @@
23
23
  "src"
24
24
  ],
25
25
  "dependencies": {
26
- "@floating-ui/vue": "^1.1.11",
26
+ "@floating-ui/vue": "^2.0.1",
27
27
  "@headlessui/vue": "^1.7.23",
28
+ "@internationalized/date": "^3.12.4",
28
29
  "@remixicon/vue": "^4.9.0",
29
- "@types/hast": "^3.0.4",
30
- "@types/leaflet": "^1.9.21",
31
- "@vueuse/core": "^14.3.0",
32
- "@vueuse/router": "^14.3.0",
30
+ "@types/hast": "^3.0.5",
31
+ "@types/leaflet": "^1.9.22",
32
+ "@vueuse/core": "^14.4.0",
33
+ "@vueuse/router": "^14.4.0",
33
34
  "chart.js": "^4.5.1",
34
- "dompurify": "^3.4.7",
35
+ "dompurify": "^3.4.15",
35
36
  "echarts": "^6.1.0",
36
37
  "geopf-extensions-openlayers": "1.0.0-beta.11",
37
38
  "leaflet": "^1.9.4",
38
39
  "maplibre-gl": "^5.24.0",
39
40
  "ofetch": "^1.5.1",
40
- "ol": "^10.9.0",
41
+ "ol": "^10.10.0",
41
42
  "pdfjs-dist": "^4.10.38",
42
- "pmtiles": "^4.4.1",
43
+ "pmtiles": "^4.5.0",
43
44
  "popmotion": "^11.0.5",
44
45
  "rehype-highlight": "^7.0.2",
45
46
  "rehype-raw": "^7.0.0",
46
47
  "rehype-sanitize": "^6.0.0",
47
48
  "rehype-slug": "^6.0.0",
48
49
  "rehype-stringify": "^10.0.1",
50
+ "reka-ui": "^2.10.4",
49
51
  "remark-behead": "^3.1.0",
50
52
  "remark-breaks": "^4.0.0",
51
53
  "remark-gfm": "^4.0.1",
@@ -63,34 +65,33 @@
63
65
  "yaml": "^2.9.0"
64
66
  },
65
67
  "devDependencies": {
66
- "@intlify/cli": "^0.13.1",
67
- "@tailwindcss/cli": "^4.3.0",
68
- "@tailwindcss/typography": "^0.5.19",
69
- "@tsconfig/node22": "^22.0.5",
68
+ "@tailwindcss/cli": "^4.3.3",
69
+ "@tailwindcss/typography": "^0.5.20",
70
+ "@tsconfig/node22": "^22.0.6",
70
71
  "@types/geojson": "^7946.0.16",
71
- "@types/node": "^22.19.19",
72
- "@vitejs/plugin-vue": "^6.0.7",
72
+ "@types/node": "^22.20.2",
73
+ "@vitejs/plugin-vue": "^6.0.8",
73
74
  "@vue/eslint-config-prettier": "^10.2.0",
74
- "@vue/eslint-config-typescript": "^14.7.0",
75
+ "@vue/eslint-config-typescript": "^14.9.0",
75
76
  "@vue/tsconfig": "^0.8.1",
76
- "eslint": "^9.39.4",
77
- "eslint-plugin-vue": "^10.9.1",
77
+ "eslint": "^9.39.5",
78
+ "eslint-plugin-vue": "^10.11.0",
78
79
  "jiti": "^2.7.0",
79
80
  "npm-run-all2": "^8.0.4",
80
81
  "openapi-types": "^12.1.3",
81
- "prettier": "^3.8.3",
82
- "tailwindcss": "^4.3.0",
82
+ "prettier": "^3.9.6",
83
+ "tailwindcss": "^4.3.3",
83
84
  "typescript": "^5.9.3",
84
- "vite": "^7.3.3",
85
- "vite-plugin-vue-devtools": "^8.1.2",
86
- "vue": "^3.5.35",
87
- "vue-router": "^5.0.7",
88
- "vue-tsc": "^3.3.2"
85
+ "vite": "^7.3.6",
86
+ "vite-plugin-vue-devtools": "^8.2.1",
87
+ "vue": "^3.5.42",
88
+ "vue-router": "^5.3.1",
89
+ "vue-tsc": "^3.3.11"
89
90
  },
90
91
  "peerDependencies": {
92
+ "echarts": "^6.0.0",
91
93
  "vue": "^3.5.13",
92
- "vue-router": "^4.5.0 || ^5.0.0",
93
- "echarts": "^6.0.0"
94
+ "vue-router": "^4.5.0 || ^5.0.0"
94
95
  },
95
96
  "scarfSettings": {
96
97
  "enabled": false
@@ -12,7 +12,10 @@
12
12
  class="my-1"
13
13
  >
14
14
  <p class="pl-3 mb-1 text-xs text-gray-medium">
15
- {{ month }}
15
+ <FormattedDate
16
+ :date="month"
17
+ :options="{ dateStyle: undefined, year: 'numeric', month: 'long', day: undefined }"
18
+ />
16
19
  </p>
17
20
  <ul
18
21
  class="space-y-2 p-0 m-0"
@@ -82,9 +85,15 @@
82
85
  </template>
83
86
  </slot>
84
87
  </p>
85
- <p class="m-0 flex-none text-xs text-gray-medium">
86
- {{ t('le {date}', { date: formatDate(activity.created_at) }) }}
87
- </p>
88
+ <TranslationT
89
+ tag="p"
90
+ class="m-0 flex-none text-xs text-gray-medium"
91
+ keypath="le {date}"
92
+ >
93
+ <template #date>
94
+ <FormattedDate :date="activity.created_at" />
95
+ </template>
96
+ </TranslationT>
88
97
  </div>
89
98
  </li>
90
99
  </ul>
@@ -118,13 +127,14 @@ import { useRoute } from 'vue-router'
118
127
  import { useTranslation } from '../../composables/useTranslation'
119
128
  import { getActivityTranslation } from '../../functions/activities'
120
129
  import { useFetch } from '../../functions/api'
121
- import { useFormatDate } from '../../functions/dates'
122
130
  import type { PaginatedArray } from '../../types/api'
123
131
  import type { Activity } from '../../types/activity'
124
132
  import Avatar from '../Avatar.vue'
125
133
  import LoadingBlock from '../LoadingBlock.vue'
126
134
  import Pagination from '../Pagination.vue'
127
135
  import PaddedContainer from '../PaddedContainer.vue'
136
+ import FormattedDate from '../FormattedDate.vue'
137
+ import TranslationT from '../TranslationT.vue'
128
138
  import listSrc from '../../../assets/illustrations/list.svg?url'
129
139
 
130
140
  const props = defineProps<{
@@ -133,7 +143,6 @@ const props = defineProps<{
133
143
  }>()
134
144
 
135
145
  const route = useRoute()
136
- const { formatDate } = useFormatDate()
137
146
  const { t } = useTranslation()
138
147
 
139
148
  const page = ref(parseInt(route.query.page as string | undefined ?? '1', 10))
@@ -146,13 +155,13 @@ const { data: activities, status } = await useFetch<PaginatedArray<Activity>>('/
146
155
  },
147
156
  })
148
157
 
158
+ // Grouping on a month read in the reader's timezone would change both the number of
159
+ // groups and their keys between the server render and the browser's — a mismatch on
160
+ // the children themselves, which no `data-allow-mismatch` covers. The `YYYY-MM` the
161
+ // timestamp starts with is the same string for everyone; the month is worded from it
162
+ // at render time.
149
163
  const groupedActivities = computed(() => activities.value?.data.reduce((grouped, activity) => {
150
- const activityMonth = formatDate(activity.created_at, {
151
- dateStyle: undefined,
152
- day: undefined,
153
- month: 'long',
154
- year: 'numeric',
155
- })
164
+ const activityMonth = activity.created_at.slice(0, 7)
156
165
  if (!grouped[activityMonth]) {
157
166
  grouped[activityMonth] = []
158
167
  }
@@ -3,6 +3,7 @@
3
3
  :is="config?.appLink"
4
4
  v-if="config.appLink"
5
5
  :to
6
+ :replace
6
7
  >
7
8
  <slot />
8
9
  </component>
@@ -18,6 +19,7 @@
18
19
  <RouterLink
19
20
  v-else
20
21
  :to
22
+ :replace
21
23
  ><slot /></RouterLink>
22
24
  </template>
23
25
 
@@ -33,6 +35,7 @@ const { locale } = useTranslation()
33
35
 
34
36
  const props = defineProps<{
35
37
  to: string | RouteLocationRaw | null | undefined
38
+ replace?: boolean
36
39
  }>()
37
40
 
38
41
  const isExternal = computed(() => {
@@ -10,7 +10,9 @@
10
10
  >
11
11
  <div>
12
12
  <div class="text-gray-900">
13
- {{ title }}
13
+ <slot name="title">
14
+ {{ title }}
15
+ </slot>
14
16
  </div>
15
17
  <div
16
18
  v-if="$slots.default"
@@ -34,7 +36,9 @@ export const bannerActionTypeKey = Symbol() as InjectionKey<'primary' | 'danger'
34
36
  <script setup lang="ts">
35
37
  const props = defineProps<{
36
38
  type: 'primary' | 'danger' | 'warning'
37
- title: string
39
+ // Optional so the title can be a slot, for instance to make it the toggle of a
40
+ // disclosure whose panel lives in the banner
41
+ title?: string
38
42
  }>()
39
43
 
40
44
  provide(bannerActionTypeKey, props.type)
@@ -13,7 +13,8 @@ import { TitleComponent, TooltipComponent, LegendComponent, GridComponent, Datas
13
13
  import { init, type ECharts as EChartsType } from 'echarts'
14
14
  import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
15
15
  import { summarize } from '../../functions/helpers'
16
- import type { Chart, XAxis, YAxis, XAxisForm, ChartForApi } from '../../types/visualizations'
16
+ import { useFormatDate } from '../../functions/dates'
17
+ import type { Chart, ColumnDefinition, ColumnsDefinition, XAxis, YAxis, XAxisForm, ChartForApi } from '../../types/visualizations'
17
18
  import { useTranslation } from '../../composables/useTranslation'
18
19
 
19
20
  use([CanvasRenderer, LineChart, BarChart, TitleComponent, TooltipComponent, LegendComponent, GridComponent, DatasetComponent])
@@ -22,17 +23,26 @@ const props = defineProps<{
22
23
  chart: Chart | ChartForApi
23
24
  series: {
24
25
  data: Record<string, Array<Record<string, unknown>>>
25
- columns: Record<string, Array<string>>
26
+ columns: ColumnsDefinition
26
27
  }
27
28
  }>()
28
29
 
29
30
  const { locale } = useTranslation()
31
+ const { formatDate } = useFormatDate()
30
32
  const chartContainer = ref<HTMLElement | null>(null)
31
33
  let echartsInstance: EChartsType | null = null
32
34
 
33
- function mapXAxisType(xAxis: XAxis | XAxisForm): 'category' | 'value' {
35
+ function capture(): string | null {
36
+ return echartsInstance?.getDataURL() ?? null
37
+ }
38
+
39
+ defineExpose({ capture })
40
+
41
+ // ECharts has a dedicated 'time' axis type for continuous date values.
42
+ function mapXAxisType(xAxis: XAxis | XAxisForm): 'category' | 'value' | 'time' {
34
43
  if (!xAxis) return 'category'
35
- return (xAxis.type ?? 'discrete') === 'continuous' ? 'value' : 'category'
44
+ if (xAxis.type !== 'continuous') return 'category'
45
+ return isDateAxis.value ? 'time' : 'value'
36
46
  }
37
47
 
38
48
  function buildYAxisFormatter(yAxis: YAxis): ((value: number) => string) | undefined {
@@ -44,6 +54,77 @@ function buildYAxisFormatter(yAxis: YAxis): ((value: number) => string) | undefi
44
54
  }
45
55
  }
46
56
 
57
+ function buildXAxisFormatter(column: ColumnDefinition | null, options?: Intl.DateTimeFormatOptions): ((value: string | number | Date) => string) | undefined {
58
+ if (column?.type !== 'date') return undefined
59
+ return (value: string | number | Date) => {
60
+ if (value === null || value === undefined) return ''
61
+ const date = value instanceof Date ? value : new Date(value)
62
+ if (Number.isNaN(date.getTime())) return String(value)
63
+ return formatDate(date, options ?? { dateStyle: 'short' })
64
+ }
65
+ }
66
+
67
+ function parseXValueAsDate(row: Record<string, unknown>, xColumn: string): Record<string, unknown> {
68
+ const value = row[xColumn]
69
+ if (value === null || value === undefined || value instanceof Date) return row
70
+ if (typeof value === 'string') {
71
+ const date = new Date(value)
72
+ if (!Number.isNaN(date.getTime())) {
73
+ return { ...row, [xColumn]: date }
74
+ }
75
+ }
76
+ return row
77
+ }
78
+
79
+ const xAxisColumn = computed(() => {
80
+ const columnName = props.chart.x_axis.column_x
81
+ if (!columnName) return null
82
+ for (const columns of Object.values(props.series.columns)) {
83
+ const column = columns.find(c => c.name === columnName)
84
+ if (column) return column
85
+ }
86
+ return null
87
+ })
88
+
89
+ const isDateAxis = computed(() => xAxisColumn.value?.type === 'date')
90
+
91
+ const xAxisBounds = computed(() => {
92
+ const columnName = props.chart.x_axis.column_x
93
+ if (!columnName) return { min: undefined, max: undefined }
94
+
95
+ let min: number | undefined
96
+ let max: number | undefined
97
+
98
+ for (const s of props.chart.series) {
99
+ const xColumn = s.column_x_name_override ?? columnName
100
+ const data = props.series.data[s.resource_id]
101
+ if (!data) continue
102
+
103
+ for (const row of data) {
104
+ const value = row[xColumn]
105
+ if (value === null || value === undefined) continue
106
+
107
+ let numericValue: number | undefined
108
+ if (value instanceof Date) {
109
+ numericValue = value.getTime()
110
+ }
111
+ else if (isDateAxis.value && typeof value === 'string') {
112
+ numericValue = new Date(value).getTime()
113
+ }
114
+ else {
115
+ numericValue = Number(value)
116
+ }
117
+
118
+ if (numericValue === undefined || Number.isNaN(numericValue)) continue
119
+
120
+ if (min === undefined || numericValue < min) min = numericValue
121
+ if (max === undefined || numericValue > max) max = numericValue
122
+ }
123
+ }
124
+
125
+ return { min, max }
126
+ })
127
+
47
128
  const echartsOption = computed(() => {
48
129
  const seriesCount = props.chart.series.length
49
130
  if (!props.chart.series || seriesCount === 0) return
@@ -53,16 +134,20 @@ const echartsOption = computed(() => {
53
134
  const yColumn = s.aggregate_y ? `${s.column_y}__${s.aggregate_y}` : s.column_y
54
135
  const resourceId = s.resource_id
55
136
 
56
- if (!xColumn || !yColumn || !resourceId || !s.type || !props.series.data[resourceId] || !props.series.columns[resourceId]) {
137
+ const resourceColumns = props.series.columns[resourceId]
138
+ if (!xColumn || !yColumn || !resourceId || !s.type || !props.series.data[resourceId] || !resourceColumns) {
57
139
  return null
58
140
  }
59
141
 
60
- const sortedData = [...props.series.data[resourceId]]
61
- const sortBy = props.chart.x_axis.sort_x_by
142
+ const rawData = props.series.data[resourceId]
143
+ const sortedData = isDateAxis.value
144
+ ? rawData.map(row => parseXValueAsDate(row, xColumn))
145
+ : [...rawData]
146
+ const sortBy = props.chart.x_axis.sort_x_by ?? (isDateAxis.value ? 'axis_x' : null)
62
147
  const sortDirection = props.chart.x_axis.sort_x_direction ?? 'asc'
63
148
 
64
149
  if (sortBy && sortDirection && props.chart.x_axis.column_x) {
65
- const sortKey = sortBy === 'axis_x' ? xColumn : yColumn
150
+ const sortKey = sortBy === 'axis_y' ? yColumn : xColumn
66
151
  sortedData.sort((a, b) => {
67
152
  const valA = a[sortKey]
68
153
  const valB = b[sortKey]
@@ -110,7 +195,7 @@ const echartsOption = computed(() => {
110
195
  return {
111
196
  series: {
112
197
  type: s.type === 'histogram' ? 'bar' : 'line',
113
- dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
198
+ dimensions: s.aggregate_y ? [xColumn, yColumn] : resourceColumns.map(c => c.name),
114
199
  name: yColumn,
115
200
  encode: {
116
201
  x: xColumn,
@@ -119,7 +204,7 @@ const echartsOption = computed(() => {
119
204
  } as LineSeriesOption | BarSeriesOption,
120
205
  data: {
121
206
  source: sortedData,
122
- dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
207
+ dimensions: s.aggregate_y ? [xColumn, yColumn] : resourceColumns.map(c => c.name),
123
208
  },
124
209
  }
125
210
  })
@@ -135,26 +220,30 @@ const echartsOption = computed(() => {
135
220
  seriesData.data.push(curr.data)
136
221
  }
137
222
 
223
+ const xAxisType = mapXAxisType(props.chart.x_axis)
224
+
138
225
  return {
139
226
  dataset: [...seriesData.data],
140
- title: {
141
- text: props.chart.title,
142
- left: 'center',
227
+ textStyle: {
228
+ fontFamily: 'Marianne, arial, sans-serif',
143
229
  },
230
+ color: '#000091',
144
231
  tooltip: {
145
232
  trigger: 'axis' as const,
146
233
  formatter: (params: Array<{ value: Record<string, unknown>, axisValueLabel: string, seriesName: string }>) => {
147
234
  let tooltip = ''
148
- const formatter = new Intl.NumberFormat('fr-FR')
235
+ const valueFormatter = new Intl.NumberFormat(locale)
236
+ const xAxisFormatter = buildXAxisFormatter(xAxisColumn.value, { dateStyle: 'medium' })
149
237
  for (const param of params) {
150
238
  const seriesName = param.seriesName
151
- tooltip += `${format.encodeHTML(param.axisValueLabel)}: <strong>${formatter.format(Number(param.value[seriesName]))}</strong><br>`
239
+ const axisLabel = xAxisFormatter ? xAxisFormatter(param.axisValueLabel) : param.axisValueLabel
240
+ tooltip += `${format.encodeHTML(String(axisLabel))}: <strong>${valueFormatter.format(Number(param.value[seriesName]))}</strong><br>`
152
241
  }
153
242
  return tooltip
154
243
  },
155
244
  },
156
245
  legend: {
157
- show: seriesData.series.length > 1,
246
+ show: false,
158
247
  bottom: 0,
159
248
  },
160
249
  grid: {
@@ -165,8 +254,13 @@ const echartsOption = computed(() => {
165
254
  containLabel: true,
166
255
  },
167
256
  xAxis: {
168
- type: mapXAxisType(props.chart.x_axis),
257
+ type: xAxisType,
169
258
  name: (props.chart.x_axis as XAxis).column_x,
259
+ min: xAxisType !== 'category' ? xAxisColumn.value?.min ?? xAxisBounds.value.min ?? undefined : undefined,
260
+ max: xAxisType !== 'category' ? xAxisColumn.value?.max ?? xAxisBounds.value.max ?? undefined : undefined,
261
+ axisLabel: xAxisType === 'time'
262
+ ? { formatter: buildXAxisFormatter(xAxisColumn.value) }
263
+ : undefined,
170
264
  },
171
265
  yAxis: {
172
266
  type: 'value' as const,
@@ -5,6 +5,7 @@
5
5
  >
6
6
  <template #default="{ data }">
7
7
  <ChartViewer
8
+ ref="chartViewerRef"
8
9
  :chart="chart"
9
10
  :series="data"
10
11
  />
@@ -18,23 +19,28 @@
18
19
  </template>
19
20
 
20
21
  <script setup lang="ts">
21
- import { reactive, ref, watch } from 'vue'
22
+ import { computed, reactive, ref, watch } from 'vue'
22
23
  import ChartViewer from './ChartViewer.vue'
23
24
  import LoadingBlock from '../../components/LoadingBlock.vue'
24
25
  import { useComponentsConfig } from '../../config'
25
26
  import { fetchTabularData, useGetProfile } from '../../functions/tabularApi'
26
- import type { Chart, ChartForApi } from '../../types/visualizations'
27
+ import type { Chart, ChartForApi, ColumnsDefinition } from '../../types/visualizations'
27
28
  import { useTranslation } from '../../composables/useTranslation'
29
+ import { watchDebounced } from '@vueuse/shared'
30
+ import { buildColumnsFromProfile } from '../../functions/charts'
28
31
 
29
32
  const props = defineProps<{
30
33
  chart: Chart | ChartForApi
31
34
  }>()
32
35
 
33
- const emit = defineEmits<{
34
- columns: [columns: Record<string, Array<string>>]
35
- }>()
36
-
37
36
  const { t } = useTranslation()
37
+ const chartViewerRef = ref<InstanceType<typeof ChartViewer> | null>(null)
38
+
39
+ function capture(): string | null {
40
+ return chartViewerRef.value?.capture() ?? null
41
+ }
42
+
43
+ defineExpose({ capture })
38
44
  const config = useComponentsConfig()
39
45
  const getProfile = useGetProfile()
40
46
 
@@ -45,12 +51,18 @@ const pendingOperations = ref(0)
45
51
 
46
52
  const series = reactive<{
47
53
  data: Record<string, Array<Record<string, unknown>>>
48
- columns: Record<string, Array<string>>
54
+ columns: ColumnsDefinition
49
55
  }>({
50
56
  data: {},
51
57
  columns: {},
52
58
  })
53
59
 
60
+ const resourceIds = computed(() => {
61
+ return props.chart.series
62
+ .filter(s => s.resource_id)
63
+ .map(s => s.resource_id)
64
+ })
65
+
54
66
  async function fetchSeriesProfile() {
55
67
  pendingOperations.value++
56
68
  status.value = 'pending'
@@ -78,7 +90,7 @@ async function fetchSeriesProfile() {
78
90
  .map(r => r.value)
79
91
  series.columns = Object.fromEntries(results.map(result => [
80
92
  result.id,
81
- result.profile.profile.header,
93
+ buildColumnsFromProfile(result.profile),
82
94
  ]))
83
95
  }
84
96
  catch (err) {
@@ -86,6 +98,7 @@ async function fetchSeriesProfile() {
86
98
  status.value = 'error'
87
99
  console.error(err)
88
100
  series.columns = {}
101
+ series.data = {}
89
102
  }
90
103
  finally {
91
104
  pendingOperations.value--
@@ -148,17 +161,16 @@ async function fetchSeriesData() {
148
161
  }
149
162
  }
150
163
 
151
- watch(() => props.chart.series, async () => {
164
+ watch(resourceIds, async () => {
152
165
  await fetchSeriesProfile()
153
- }, { immediate: true, deep: true })
166
+ }, { immediate: true })
154
167
 
155
- watch([() => props.chart.series, () => props.chart.x_axis.column_x], async () => {
168
+ watchDebounced([
169
+ () => props.chart.series,
170
+ () => props.chart.x_axis.column_x,
171
+ ], async () => {
156
172
  await fetchSeriesData()
157
- }, { immediate: true, deep: true })
158
-
159
- watch(() => series.columns, () => {
160
- emit('columns', series.columns)
161
- })
173
+ }, { debounce: config.searchDebounce ?? 300, immediate: true, deep: true })
162
174
 
163
175
  watch(pendingOperations, (count) => {
164
176
  if (count === 0) {
@@ -0,0 +1,112 @@
1
+ <template>
2
+ <ObjectCard media-size="xl">
3
+ <template #badge>
4
+ <ObjectCardBadge
5
+ v-if="chart.deleted_at"
6
+ :icon="RiDeleteBinLine"
7
+ >
8
+ {{ t('Supprimé') }}
9
+ </ObjectCardBadge>
10
+ <ObjectCardBadge
11
+ v-else-if="chart.private"
12
+ :icon="RiLockLine"
13
+ >
14
+ {{ t('Brouillon') }}
15
+ </ObjectCardBadge>
16
+ </template>
17
+
18
+ <template #media>
19
+ <img
20
+ v-if="chart.image"
21
+ :src="chart.image"
22
+ class="w-full h-full object-cover"
23
+ :alt="chart.title"
24
+ >
25
+ <Placeholder
26
+ v-else
27
+ type="Chart"
28
+ class="w-full h-full"
29
+ />
30
+ </template>
31
+
32
+ <ObjectCardHeader
33
+ :icon="chartIcon"
34
+ :url="chartUrl || chart.page"
35
+ >
36
+ {{ chart.title }}
37
+ </ObjectCardHeader>
38
+
39
+ <div
40
+ v-if="chart.organization || chart.owner"
41
+ class="text-sm flex flex-wrap gap-y-1 items-center truncate"
42
+ >
43
+ <ObjectCardOwner
44
+ :organization="chart.organization"
45
+ :owner="chart.owner"
46
+ :organization-url="organizationUrl"
47
+ />
48
+ <RiSubtractLine
49
+ aria-hidden="true"
50
+ class="size-4 flex-none fill-gray-medium"
51
+ />
52
+ <TranslationT
53
+ tag="p"
54
+ class="text-sm whitespace-nowrap mb-0 text-gray-medium"
55
+ keypath="Mis à jour {date}"
56
+ >
57
+ <template #date>
58
+ <FormattedDate
59
+ :date="chart.last_modified"
60
+ format="relative"
61
+ :options="{ dateStyle: 'medium' }"
62
+ />
63
+ </template>
64
+ </TranslationT>
65
+ </div>
66
+
67
+ <div class="mx-0 -mb-1 flex flex-wrap items-center text-sm text-gray-medium mt-1">
68
+ <p
69
+ class="text-sm mb-0 flex items-center gap-0.5"
70
+ :aria-label="t('{n} vues | {n} vue | {n} vues', chart.metrics.views)"
71
+ >
72
+ <RiEyeLine
73
+ aria-hidden="true"
74
+ class="size-3.5"
75
+ />{{ summarize(chart.metrics.views) }}
76
+ </p>
77
+ </div>
78
+
79
+ <ObjectCardShortDescription :text="chart.description" />
80
+
81
+ <slot />
82
+ </ObjectCard>
83
+ </template>
84
+
85
+ <script setup lang="ts">
86
+ import { computed } from 'vue'
87
+ import { RiBarChartBoxLine, RiDeleteBinLine, RiEyeLine, RiLineChartLine, RiLockLine, RiSubtractLine } from '@remixicon/vue'
88
+ import type { RouteLocationRaw } from 'vue-router'
89
+ import type { Chart } from '../types/visualizations'
90
+ import { summarize } from '../functions/helpers'
91
+ import { useTranslation } from '../composables/useTranslation'
92
+ import Placeholder from './Placeholder.vue'
93
+ import FormattedDate from './FormattedDate.vue'
94
+ import ObjectCard from './ObjectCard.vue'
95
+ import ObjectCardBadge from './ObjectCardBadge.vue'
96
+ import ObjectCardHeader from './ObjectCardHeader.vue'
97
+ import ObjectCardOwner from './ObjectCardOwner.vue'
98
+ import ObjectCardShortDescription from './ObjectCardShortDescription.vue'
99
+ import TranslationT from './TranslationT.vue'
100
+
101
+ const props = defineProps<{
102
+ chart: Chart
103
+ chartUrl?: RouteLocationRaw
104
+ organizationUrl?: RouteLocationRaw
105
+ }>()
106
+
107
+ const { t } = useTranslation()
108
+
109
+ const chartIcon = computed(() => {
110
+ return props.chart.series[0]?.type === 'line' ? RiLineChartLine : RiBarChartBoxLine
111
+ })
112
+ </script>