Skip to content

Commit fe54dcc

Browse files
committed
fix: better y-ticks for barplot
1 parent 0b4edeb commit fe54dcc

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/visualizations/TimelineBarChart.vue

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ import { Bar } from 'vue-chartjs';
55
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
66
import { get_hour_offset } from '~/util/time';
77
8+
function hourToTick(hours: number): string {
9+
if (hours > 1) {
10+
return `${hours}h`;
11+
} else {
12+
if (hours == 1) {
13+
return '1h';
14+
} else if (hours == 0) {
15+
return '0';
16+
} else {
17+
return Math.round(hours * 60) + 'm';
18+
}
19+
}
20+
}
21+
822
@Component({
923
extends: Bar, // this is important to add the functionality to your component
1024
})
@@ -60,13 +74,7 @@ export default class ChartTimelineBars extends Vue<Bar> {
6074
stepSize: 0.25,
6175
min: 0,
6276
max: 1,
63-
callback: function (value: number) {
64-
if (value == 1) {
65-
return '1h';
66-
} else {
67-
return Math.round(value * 60) + 'min';
68-
}
69-
},
77+
callback: hourToTick,
7078
},
7179
},
7280
];
@@ -77,13 +85,7 @@ export default class ChartTimelineBars extends Vue<Bar> {
7785
ticks: {
7886
stepSize: 1,
7987
min: 0,
80-
callback: function (value: number) {
81-
if (value == 1) {
82-
return '1h';
83-
} else {
84-
return Math.round(value) + 'h';
85-
}
86-
},
88+
callback: hourToTick,
8789
},
8890
},
8991
];

0 commit comments

Comments
 (0)