Skip to content

Commit 9a6786c

Browse files
author
Bot
committed
fix input intervals chart time axis
1 parent 300e8cb commit 9a6786c

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/components/CodeEditor.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ export default {
486486
},
487487
onFocus() {
488488
console.log('cmFocus');
489+
this.$emit('pause', false);
489490
if (this.pauseStart) {
490-
this.$emit('pause', false);
491491
this.pauseTime += Date.now() - this.pauseStart;
492492
this.pauseStart = null;
493493
}
@@ -502,7 +502,9 @@ export default {
502502
if (DEV) ev.preventDefault();
503503
clearInterval(this.liveWpmInterval);
504504
this.liveWpmInterval = null;
505-
this.pauseStart = Date.now();
505+
if (this.stats.firstCharTime) {
506+
this.pauseStart = Date.now();
507+
}
506508
if (!this.isCompleted && this.popUpText !== 'Try again' && ev) {
507509
if (DEV) this.cm.focus();
508510
if (ev.relatedTarget !== null) {

src/components/charts/MixedChart.vue

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import { Bar } from 'vue-chartjs';
3+
import { mapGetters } from 'vuex';
34
45
export default {
56
name: 'MixedChart',
@@ -11,15 +12,16 @@ export default {
1112
},
1213
},
1314
computed: {
15+
...mapGetters(['options']),
1416
history() {
1517
return this.stats.history.filter((event) => event.text);
1618
},
1719
inputIntervalsPoints() {
1820
const points = [];
19-
for (let i = 1; i < this.history.length; i += 1) {
21+
for (let i = 0; i < this.history.length; i += 1) {
2022
points.push({
2123
x: this.history[i].time,
22-
y: this.history[i].time - this.history[i - 1].time,
24+
y: i === 0 ? this.stats.firstCharTime - this.stats.startTime : this.history[i].time - this.history[i - 1].time,
2325
type: this.history[i].type,
2426
});
2527
}
@@ -31,7 +33,7 @@ export default {
3133
},
3234
wpmPoints() {
3335
const points = this.stats.wpmOverTime.map((wpmEvent) => ({
34-
x: wpmEvent[0],
36+
x: wpmEvent[0] - (this.options.liveWpmRefreshRate / 3),
3537
y: wpmEvent[1],
3638
}));
3739
points.unshift({
@@ -43,9 +45,9 @@ export default {
4345
y: points[points.length - 1].y,
4446
});
4547
46-
return points;
48+
return points.filter(({ x }) => x >= 0);
4749
},
48-
options() {
50+
chartOptions() {
4951
return {
5052
responsive: true,
5153
maintainAspectRatio: false,
@@ -73,7 +75,7 @@ export default {
7375
callbacks: {
7476
title: ([item]) => {
7577
if (item.datasetIndex !== 0) {
76-
const event = this.history[item.index + 1];
78+
const event = this.history[item.index];
7779
7880
7981
const buffer = [`${event.type === 'mistake' ? 'Wrong' : 'Correct'}: ${event.text.replace(' ', 'Space')}`];
@@ -182,49 +184,49 @@ export default {
182184
label: 'Input intervals',
183185
data: this.inputIntervalsPoints,
184186
pointStyle(ctx) {
185-
const event = ctx.dataset.data[ctx.dataIndex - 1];
187+
const event = ctx.dataset.data[ctx.dataIndex];
186188
if (event && event.type === 'mistake') {
187189
return 'crossRot';
188190
}
189191
return 'circle';
190192
},
191193
pointBackgroundColor(ctx) {
192-
const event = ctx.dataset.data[ctx.dataIndex - 1];
194+
const event = ctx.dataset.data[ctx.dataIndex];
193195
if (event && event.type === 'mistake') {
194196
return '#eee';
195197
}
196198
return '#266eb7';
197199
},
198200
pointBorderColor(ctx) {
199-
const event = ctx.dataset.data[ctx.dataIndex - 1];
201+
const event = ctx.dataset.data[ctx.dataIndex];
200202
if (event && event.type === 'mistake') {
201203
return '#eee';
202204
}
203205
return 'transparent';
204206
},
205207
pointBorderWidth(ctx) {
206-
const event = ctx.dataset.data[ctx.dataIndex - 1];
208+
const event = ctx.dataset.data[ctx.dataIndex];
207209
if (event && event.type === 'mistake') {
208210
return 2;
209211
}
210212
return 0;
211213
},
212214
pointRadius(ctx) {
213-
const event = ctx.dataset.data[ctx.dataIndex - 1];
215+
const event = ctx.dataset.data[ctx.dataIndex];
214216
if (event && event.type === 'mistake') {
215217
return 5;
216218
}
217219
return 2;
218220
},
219221
pointHoverRadius(ctx) {
220-
const event = ctx.dataset.data[ctx.dataIndex - 1];
222+
const event = ctx.dataset.data[ctx.dataIndex];
221223
if (event && event.type === 'mistake') {
222224
return 5;
223225
}
224226
return 2;
225227
},
226228
pointHoverBorderWidth(ctx) {
227-
const event = ctx.dataset.data[ctx.dataIndex - 1];
229+
const event = ctx.dataset.data[ctx.dataIndex];
228230
if (event && event.type === 'mistake') {
229231
return 2;
230232
}
@@ -252,7 +254,7 @@ export default {
252254
},
253255
},
254256
mounted() {
255-
this.renderChart(this.chartDatasets, this.options);
257+
this.renderChart(this.chartDatasets, this.chartOptions);
256258
},
257259
methods: {
258260
format(number, precision = 2, scaler = 0.001) {

0 commit comments

Comments
 (0)