Skip to content

Commit c3f096b

Browse files
committed
better reactivity
1 parent 62144cb commit c3f096b

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

dev/serve.vue

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<template>
22
<div>
3+
<h4>Unit Select</h4>
4+
<div>
5+
<input type="radio" id="one" value="Dings" v-model="picked"/>
6+
<label for="one">Dings</label>
7+
<br/>
8+
<input type="radio" id="two" value="Da" v-model="picked"/>
9+
<label for="two">Da</label>
10+
<br/>
11+
<span>Current Unit: {{ picked }}</span>
12+
</div>
13+
<br>
314
<h4>None</h4>
415
<calendar-heatmap :values="[]" :end-date="endDate" style="max-width: 675px"/>
516
<br>
@@ -15,14 +26,17 @@
1526
more : 'Mehr'
1627
}"/>
1728
<br>
29+
<h4>Tooltip Unit</h4>
30+
<calendar-heatmap :values="values" :end-date="endDate" style="max-width: 675px" :tooltip-unit="picked"/>
31+
<br>
1832
<h4>TooltipFormatter</h4>
1933
<calendar-heatmap
2034
:values="values"
2135
:end-date="endDate"
2236
style="max-width: 675px"
23-
:tooltip-formatter="(c) => c.count ? c.count / 3600 / 1000 : 'NÖX'"
37+
:tooltip-formatter="(c, u) => c.count ? (c.count / 3600 / 1000) + ' ' + u: 'NÖX'"
2438
no-data-text="NIX"
25-
tooltip-unit="Dings"
39+
:tooltip-unit="picked"
2640
/>
2741
</div>
2842
</template>
@@ -42,7 +56,8 @@
4256
data() {
4357
return {
4458
values : data,
45-
endDate: new Date('2021-08-01')
59+
endDate: new Date('2021-08-01'),
60+
picked : 'Dings'
4661
};
4762
}
4863
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-calendar-heatmap",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "A lightweight calendar heatmap Vue 3 component built on SVG, inspired by julienr114's vue-calendar-heatmap ans github's contribution calendar graph",
55
"keywords": [
66
"vue",

src/CalendarHeatmap.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
</template>
7676

7777
<script lang="ts">
78-
import { defineComponent, onBeforeUnmount, onMounted, PropType, ref, toRefs, watch } from 'vue';
79-
import { CalendarItem, Heatmap, Locale, Month, Position, Value } from '@/Heatmap';
78+
import { defineComponent, nextTick, onBeforeUnmount, onMounted, PropType, ref, toRefs, watch } from 'vue';
79+
import { CalendarItem, Heatmap, Locale, Month, Position, TooltipFormatter, Value } from '@/Heatmap';
8080
import tippy, { createSingleton, CreateSingletonInstance, Instance } from 'tippy.js';
8181
import 'tippy.js/dist/tippy.css';
8282
import 'tippy.js/dist/svg-arrow.css';
@@ -112,7 +112,7 @@
112112
default: Heatmap.DEFAULT_TOOLTIP_UNIT
113113
},
114114
tooltipFormatter: {
115-
type: Function as PropType<(day: CalendarItem) => string>
115+
type: Function as PropType<TooltipFormatter>
116116
},
117117
vertical : {
118118
type : Boolean,
@@ -201,7 +201,7 @@
201201
if (this.tooltip) {
202202
if (day.count !== undefined) {
203203
if (this.tooltipFormatter) {
204-
return this.tooltipFormatter(day);
204+
return this.tooltipFormatter(day, this.tooltipUnit);
205205
}
206206
return `<b>${day.count} ${this.tooltipUnit}</b> ${this.lo.on} ${this.lo.months[ day.date.getMonth() ]} ${day.date.getDate()}, ${day.date.getFullYear()}`;
207207
} else if (this.noDataText) {
@@ -256,7 +256,7 @@
256256
() => {
257257
heatmap.value = new Heatmap(props.endDate as Date, props.values, props.max);
258258
tippyInstances?.map(i => i.destroy());
259-
initTippy();
259+
nextTick(initTippy);
260260
}
261261
);
262262

src/Heatmap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export enum Position {
3636
VERTICAL = 'vertical'
3737
}
3838

39+
export type TooltipFormatter = (item: CalendarItem, unit: string) => string;
40+
3941
export class Heatmap {
4042

4143
static readonly DEFAULT_RANGE_COLOR = [ '#ebedf0', '#dae2ef', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e' ];

0 commit comments

Comments
 (0)