@icij/murmur-next 4.7.5 → 4.8.1

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 (32) hide show
  1. package/dist/lib/lib/datavisualisations/ColumnChart/ColumnChart.vue.d.ts +17 -0
  2. package/dist/lib/lib/datavisualisations/LineChart/LineChart.vue.d.ts +19 -0
  3. package/dist/lib/murmur.css +1 -1
  4. package/dist/lib/murmur.js +10419 -10307
  5. package/dist/lib/murmur.js.map +1 -1
  6. package/dist/lib/murmur.umd.cjs +23 -23
  7. package/dist/lib/murmur.umd.cjs.map +1 -1
  8. package/lib/assets/images/icij-full-white.svg +0 -0
  9. package/lib/assets/images/icij-full.svg +0 -0
  10. package/lib/assets/images/icij.png +0 -0
  11. package/lib/assets/images/icij.svg +0 -0
  12. package/lib/assets/images/icij@2x.png +0 -0
  13. package/lib/assets/images/murmur-dark.png +0 -0
  14. package/lib/assets/images/murmur-dark.svg +0 -0
  15. package/lib/assets/images/murmur-textured.png +0 -0
  16. package/lib/assets/images/murmur-white.png +0 -0
  17. package/lib/assets/images/murmur-white.svg +0 -0
  18. package/lib/config.default.ts +0 -0
  19. package/lib/datavisualisations/ColumnChart/ColumnChart.vue +97 -14
  20. package/lib/datavisualisations/LineChart/LineChart.vue +158 -13
  21. package/lib/datavisualisations/StackedBarChart/StackedBarChart.vue +56 -29
  22. package/lib/datavisualisations/StackedColumnChart/StackedColumnChart.vue +59 -30
  23. package/lib/keys.ts +0 -0
  24. package/lib/locales/fr.json +0 -0
  25. package/lib/styles/lib.scss +0 -0
  26. package/lib/styles/utilities.scss +0 -0
  27. package/lib/styles/variables_dark.scss +0 -0
  28. package/lib/types/d3-geo-projection.d.ts +0 -0
  29. package/lib/types/querystring-es3.d.ts +0 -0
  30. package/lib/types/shims-bootstrap-vue.d.ts +0 -0
  31. package/lib/utils/clipboard.ts +0 -0
  32. package/package.json +1 -1
@@ -1,7 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import * as d3 from 'd3'
3
3
  import keysFn from 'lodash/keys'
4
- import find from 'lodash/find'
5
4
  import get from 'lodash/get'
6
5
  import identity from 'lodash/identity'
7
6
  import sortByFn from 'lodash/sortBy'
@@ -15,7 +14,6 @@ import {
15
14
  watch
16
15
  } from 'vue'
17
16
  import { getChartProps, useChart } from '@/composables/useChart'
18
- import { useQueryObserver } from '@/composables/useQueryObserver'
19
17
 
20
18
  defineOptions({
21
19
  name: 'StackedColumnChart'
@@ -157,7 +155,6 @@ const highlightedKeys = ref(props.highlights)
157
155
  const highlightTimeout = ref<ReturnType<typeof setTimeout> | undefined>(undefined)
158
156
  const isLoaded = ref(false)
159
157
  const el = ref<ComponentPublicInstance<HTMLElement> | null>(null)
160
- const { querySelector, querySelectorAll } = useQueryObserver(el.value)
161
158
 
162
159
  const {
163
160
  elementsMaxBBox,
@@ -383,11 +380,12 @@ function stackBarAndValue(i: string | number): StackItem[] {
383
380
  }
384
381
 
385
382
  function queryBarAndValue(i: number, key: string) {
386
- if (!mounted.value) {
383
+ const root = el.value as unknown as HTMLElement
384
+ if (!mounted.value || !root) {
387
385
  return {}
388
386
  }
389
387
  const rowSelector = '.stacked-column-chart__groups__item'
390
- const row = querySelectorAll(rowSelector)[i] as HTMLElement
388
+ const row = root.querySelectorAll(rowSelector)[i] as HTMLElement
391
389
  const barSelector = `.stacked-column-chart__groups__item__bars__item--${key}`
392
390
  const bar = row.querySelector(barSelector) as HTMLElement
393
391
  const valueSelector = '.stacked-column-chart__groups__item__bars__item__value'
@@ -399,37 +397,64 @@ function isHidden(i: string | number, key: string) {
399
397
  return props.hideEmptyValues && !sortedData.value[i as number][key]
400
398
  }
401
399
 
402
- function hasValueOverflow(i: string | number, key: string) {
403
- try {
404
- const stack = stackBarAndValue(i)
405
- return find(stack, { key })?.overflow
406
- }
407
- catch {
408
- return false
400
+ interface LabelState {
401
+ overflow: boolean
402
+ pushed: boolean
403
+ hidden: boolean
404
+ }
405
+
406
+ const labelStates = ref<Record<string, LabelState>>({})
407
+
408
+ function labelStateKey(i: number | string, key: string) {
409
+ return `${i}-${key}`
410
+ }
411
+
412
+ function computeLabelStates() {
413
+ const root = el.value as unknown as HTMLElement
414
+ if (!root || !mounted.value || !sortedData.value?.length) return
415
+
416
+ const states: Record<string, LabelState> = {}
417
+
418
+ for (let i = 0; i < sortedData.value.length; i++) {
419
+ try {
420
+ const stack = stackBarAndValue(i)
421
+ for (const item of stack) {
422
+ states[labelStateKey(i, item.key)] = {
423
+ overflow: item.overflow,
424
+ pushed: item.pushed,
425
+ hidden: false
426
+ }
427
+ }
428
+ // A value is hidden when both it and the next key overflow
429
+ for (let j = 0; j < stack.length; j++) {
430
+ const nextItem = stack[j + 1]
431
+ if (nextItem && stack[j].overflow && nextItem.overflow) {
432
+ states[labelStateKey(i, stack[j].key)].hidden = true
433
+ }
434
+ }
435
+ }
436
+ catch {
437
+ // If measurement fails for a row, skip it
438
+ }
409
439
  }
440
+
441
+ labelStates.value = states
442
+ }
443
+
444
+ function hasValueOverflow(i: string | number, key: string) {
445
+ return labelStates.value[labelStateKey(i, key)]?.overflow ?? false
410
446
  }
411
447
 
412
448
  function hasValuePushed(i: string | number, key: string) {
413
- try {
414
- const stack = stackBarAndValue(i)
415
- return find(stack, { key })?.pushed
416
- }
417
- catch {
418
- return false
419
- }
449
+ return labelStates.value[labelStateKey(i, key)]?.pushed ?? false
420
450
  }
421
451
 
422
452
  function hasValueHidden(i: string | number, key: string) {
423
- const keyIndex = discoveredKeys.value.indexOf(key)
424
- const nextKey = discoveredKeys.value[keyIndex + 1]
425
- if (!nextKey) {
426
- return false
427
- }
428
- return hasValueOverflow(i, key) && hasValueOverflow(i, nextKey)
453
+ return labelStates.value[labelStateKey(i, key)]?.hidden ?? false
429
454
  }
430
455
 
431
456
  function formatXDatum(d: string) {
432
- return d3Formatter(d, props.yAxisTickFormat)
457
+ return d3Formatter(d, props.xAxisTickFormat)
433
458
  }
434
459
 
435
460
  function formatYDatum(d: string) {
@@ -445,13 +470,17 @@ watch(
445
470
 
446
471
  watch(sortedData, async () => {
447
472
  await nextTick()
473
+ const root = el.value as unknown as HTMLElement
474
+ if (!root) return
448
475
  // This must be set after the column have been rendered
449
- const element = querySelector('.stacked-column-chart__groups__item__bars')
476
+ const element = root.querySelector('.stacked-column-chart__groups__item__bars') as HTMLElement
450
477
  // Update the left axis only if the bars exists
451
478
  if (element) {
452
- leftAxisHeight.value = (element as HTMLElement).offsetHeight
479
+ leftAxisHeight.value = element.offsetHeight
453
480
  leftAxisCanvas.value.call(leftAxis.value as any)
454
481
  }
482
+ // Compute label overflow/pushed/hidden states after DOM layout
483
+ computeLabelStates()
455
484
  })
456
485
  </script>
457
486
 
@@ -484,8 +513,8 @@ watch(sortedData, async () => {
484
513
  <span
485
514
  class="stacked-column-chart__legend__item__box"
486
515
  :style="{ 'background-color': colorScale(key) }"
487
- >
488
- {{ groupName(key) }}</span>
516
+ />
517
+ <span class="stacked-column-chart__legend__item__label">{{ groupName(key) }}</span>
489
518
  </li>
490
519
  </ul>
491
520
  <div class="d-flex flex-grow-1 position-relative overflow-hidden">
package/lib/keys.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icij/murmur-next",
3
- "version": "4.7.5",
3
+ "version": "4.8.1",
4
4
  "private": false,
5
5
  "description": "Murmur is ICIJ's Design System for Bootstrap 5 and Vue.js",
6
6
  "author": "promera@icij.org",