@icij/murmur-next 4.1.2 → 4.1.3

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.
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { ComponentPublicInstance, computed, defineComponent, PropType, ref, watch } from 'vue'
2
+ import { ComponentPublicInstance, computed, defineComponent, getCurrentInstance, PropType, ref, watch } from 'vue'
3
3
  import { identity, iteratee, sortBy } from 'lodash'
4
4
  import * as d3 from 'd3'
5
5
  import { chartProps, getChartProps, useChart } from '@/composables/chart'
@@ -306,6 +306,9 @@ export default defineComponent({
306
306
  .ticks(props.yAxisTicks)
307
307
  })
308
308
 
309
+ const activeBar = computed((): ColumnBar => bars.value[shownTooltip.value] ?? null)
310
+ const activeBarId = computed((): string => columnUniqueId(shownTooltip.value))
311
+
309
312
  function formatXDatum(d: any) {
310
313
  return d3Formatter(d, props.xAxisTickFormat)
311
314
  }
@@ -351,11 +354,10 @@ export default defineComponent({
351
354
  .attr('x2', padded.value.width)
352
355
  }
353
356
 
354
- function barTooltipStyle(bar: { x: number; y: number; width: number }) {
355
- const { x, y } = el?.value?.getBoundingClientRect() ?? new DOMRect()
356
- const top = `${y + bar.y + margin.value.top}px`
357
- const left = `${x + bar.x + bar.width / 2 + margin.value.left}px`
358
- return { top, left }
357
+ function columnUniqueId(i: number) {
358
+ // @ts-ignore
359
+ const { uid } = getCurrentInstance()
360
+ return `column-${uid}-${i}`
359
361
  }
360
362
 
361
363
  function highlighted(datum: any): boolean {
@@ -369,6 +371,9 @@ export default defineComponent({
369
371
 
370
372
  return {
371
373
  el,
374
+ activeBar,
375
+ activeBarId,
376
+ columnUniqueId,
372
377
  dataHasHighlights,
373
378
  width,
374
379
  height,
@@ -379,7 +384,6 @@ export default defineComponent({
379
384
  bars,
380
385
  select,
381
386
  highlighted,
382
- barTooltipStyle,
383
387
  formatYDatum,
384
388
  formatXDatum
385
389
  }
@@ -437,34 +441,24 @@ export default defineComponent({
437
441
  :height="bar.height"
438
442
  :width="bar.width"
439
443
  :y="bar.y"
444
+ :id="columnUniqueId(index)"
440
445
  class="column-chart__columns__item__bar"
441
446
  />
442
447
  </g>
443
448
  </g>
444
449
  </svg>
445
- <teleport to="body">
446
- <div v-if="!noTooltips" class="column-chart__tooltips">
447
- <div v-for="(bar, index) in bars" :key="index">
448
- <div :style="barTooltipStyle(bar)" class="column-chart__tooltips__item">
449
- <transition name="fade">
450
- <div
451
- v-if="shownTooltip === index"
452
- class="column-chart__tooltips__item__wrapper"
453
- >
454
- <slot name="tooltip" v-bind="bar">
455
- <h6 class="column-chart__tooltips__item__wrapper__heading mb-0">
456
- {{ formatXDatum(bar.datum[timeseriesKey]) }}
457
- </h6>
458
- <div class="column-chart__tooltips__item__wrapper__value">
459
- {{ formatYDatum(bar.datum[seriesName]) }}
460
- </div>
461
- </slot>
462
- </div>
463
- </transition>
450
+ <template v-if="!noTooltips && activeBar">
451
+ <b-tooltip :target="activeBarId" teleport-to="body" manual :model-value="true" class="column-chart__tooltip">
452
+ <slot name="tooltip" v-bind="activeBar">
453
+ <h6 class="column-chart__tooltip__heading mb-0">
454
+ {{ formatXDatum(activeBar.datum[timeseriesKey]) }}
455
+ </h6>
456
+ <div class="column-chart__tooltip__value">
457
+ {{ formatYDatum(activeBar.datum[seriesName]) }}
464
458
  </div>
465
- </div>
466
- </div>
467
- </teleport>
459
+ </slot>
460
+ </b-tooltip>
461
+ </template>
468
462
  </div>
469
463
  </template>
470
464
 
@@ -519,54 +513,5 @@ export default defineComponent({
519
513
  display: none;
520
514
  }
521
515
  }
522
-
523
- &__tooltips {
524
- pointer-events: none;
525
- position: absolute;
526
- top: 0;
527
- left: 0;
528
-
529
- &__item {
530
- $tooltip-bg: $body-emphasis-color;
531
-
532
- display: inline-flex;
533
- text-align: center;
534
- flex-direction: row;
535
- align-items: flex-end;
536
- justify-content: flex-start;
537
- position: absolute;
538
- transform: translate(-50%, -100%);
539
- margin-top: -0.5 * $tooltip-arrow-width;
540
-
541
- &__wrapper {
542
- max-width: $tooltip-max-width;
543
- background: rgba($tooltip-bg, $tooltip-opacity);
544
- border-radius: $tooltip-border-radius;
545
- color: $tooltip-color;
546
- margin: 0;
547
- padding: $tooltip-padding-y $tooltip-padding-x;
548
-
549
- &.fade-enter-active,
550
- &.fade-leave-active {
551
- transition: $transition-fade;
552
- }
553
-
554
- &.fade-enter-from,
555
- &.fade-leave-to {
556
- opacity: 0;
557
- }
558
-
559
- &:after {
560
- content: '';
561
- border: ($tooltip-arrow-width * 0.5) solid transparent;
562
- border-top-color: rgba($tooltip-bg, $tooltip-opacity);
563
- transform: translateX(-50%);
564
- position: absolute;
565
- left: 50%;
566
- top: 100%;
567
- }
568
- }
569
- }
570
- }
571
516
  }
572
517
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icij/murmur-next",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
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",