@icij/murmur-next 4.1.1 → 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,10 +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 top = `${bar.y + margin.value.top}px`
356
- const left = `${bar.x + bar.width / 2 + margin.value.left}px`
357
- return { top, left }
357
+ function columnUniqueId(i: number) {
358
+ // @ts-ignore
359
+ const { uid } = getCurrentInstance()
360
+ return `column-${uid}-${i}`
358
361
  }
359
362
 
360
363
  function highlighted(datum: any): boolean {
@@ -368,6 +371,9 @@ export default defineComponent({
368
371
 
369
372
  return {
370
373
  el,
374
+ activeBar,
375
+ activeBarId,
376
+ columnUniqueId,
371
377
  dataHasHighlights,
372
378
  width,
373
379
  height,
@@ -378,7 +384,6 @@ export default defineComponent({
378
384
  bars,
379
385
  select,
380
386
  highlighted,
381
- barTooltipStyle,
382
387
  formatYDatum,
383
388
  formatXDatum
384
389
  }
@@ -436,32 +441,24 @@ export default defineComponent({
436
441
  :height="bar.height"
437
442
  :width="bar.width"
438
443
  :y="bar.y"
444
+ :id="columnUniqueId(index)"
439
445
  class="column-chart__columns__item__bar"
440
446
  />
441
447
  </g>
442
448
  </g>
443
449
  </svg>
444
- <div v-if="!noTooltips" class="column-chart__tooltips">
445
- <div v-for="(bar, index) in bars" :key="index">
446
- <div :style="barTooltipStyle(bar)" class="column-chart__tooltips__item">
447
- <transition name="fade">
448
- <div
449
- v-if="shownTooltip === index"
450
- class="column-chart__tooltips__item__wrapper"
451
- >
452
- <slot name="tooltip" v-bind="bar">
453
- <h6 class="column-chart__tooltips__item__wrapper__heading mb-0">
454
- {{ formatXDatum(bar.datum[timeseriesKey]) }}
455
- </h6>
456
- <div class="column-chart__tooltips__item__wrapper__value">
457
- {{ formatYDatum(bar.datum[seriesName]) }}
458
- </div>
459
- </slot>
460
- </div>
461
- </transition>
462
- </div>
463
- </div>
464
- </div>
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]) }}
458
+ </div>
459
+ </slot>
460
+ </b-tooltip>
461
+ </template>
465
462
  </div>
466
463
  </template>
467
464
 
@@ -516,54 +513,5 @@ export default defineComponent({
516
513
  display: none;
517
514
  }
518
515
  }
519
-
520
- &__tooltips {
521
- pointer-events: none;
522
- position: absolute;
523
- top: 0;
524
- left: 0;
525
-
526
- &__item {
527
- $tooltip-bg: $body-emphasis-color;
528
-
529
- display: inline-flex;
530
- text-align: center;
531
- flex-direction: row;
532
- align-items: flex-end;
533
- justify-content: flex-start;
534
- position: absolute;
535
- transform: translate(-50%, -100%);
536
- margin-top: -0.5 * $tooltip-arrow-width;
537
-
538
- &__wrapper {
539
- max-width: $tooltip-max-width;
540
- background: rgba($tooltip-bg, $tooltip-opacity);
541
- border-radius: $tooltip-border-radius;
542
- color: $tooltip-color;
543
- margin: 0;
544
- padding: $tooltip-padding-y $tooltip-padding-x;
545
-
546
- &.fade-enter-active,
547
- &.fade-leave-active {
548
- transition: $transition-fade;
549
- }
550
-
551
- &.fade-enter-from,
552
- &.fade-leave-to {
553
- opacity: 0;
554
- }
555
-
556
- &:after {
557
- content: '';
558
- border: ($tooltip-arrow-width * 0.5) solid transparent;
559
- border-top-color: rgba($tooltip-bg, $tooltip-opacity);
560
- transform: translateX(-50%);
561
- position: absolute;
562
- left: 50%;
563
- top: 100%;
564
- }
565
- }
566
- }
567
- }
568
516
  }
569
517
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icij/murmur-next",
3
- "version": "4.1.1",
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",