From 279271af42a342f9fc064a2c277d605b068d207c Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 26 Sep 2021 11:21:09 +0200 Subject: [PATCH] Client - display a marker on map when mouse is over the chart --- .../components/Workout/WorkoutChart/index.vue | 28 +++++++++++++++++-- .../Workout/WorkoutDetail/WorkoutMap.vue | 13 +++++++-- .../Workout/WorkoutDetail/index.vue | 8 ++++-- fittrackee_client/src/types/workouts.ts | 7 +++++ fittrackee_client/src/utils/workouts.ts | 5 +++- fittrackee_client/src/views/Workout.vue | 21 ++++++++++++-- .../tests/unit/utils/workouts.spec.ts | 6 ++++ 7 files changed, 77 insertions(+), 11 deletions(-) diff --git a/fittrackee_client/src/components/Workout/WorkoutChart/index.vue b/fittrackee_client/src/components/Workout/WorkoutChart/index.vue index 6f36bb37..b1a4bef7 100644 --- a/fittrackee_client/src/components/Workout/WorkoutChart/index.vue +++ b/fittrackee_client/src/components/Workout/WorkoutChart/index.vue @@ -23,7 +23,11 @@ {{ t('workouts.DURATION') }} - +
{{ t('workouts.NO_DATA_CLEANING') }}
@@ -40,7 +44,11 @@ import Card from '@/components/Common/Card.vue' import { IAuthUserProfile } from '@/types/user' - import { IWorkoutChartData, IWorkoutState } from '@/types/workouts' + import { + IWorkoutChartData, + IWorkoutState, + TCoordinates, + } from '@/types/workouts' import { getDatasets } from '@/utils/workouts' export default defineComponent({ @@ -59,7 +67,8 @@ required: true, }, }, - setup(props) { + emits: ['getCoordinates'], + setup(props, { emit }) { const { t } = useI18n() let displayDistance = ref(true) const datasets: ComputedRef = computed(() => @@ -76,6 +85,9 @@ ]) ), })) + const coordinates: ComputedRef = computed( + () => datasets.value.coordinates + ) const options = computed>(() => ({ responsive: true, animation: false, @@ -151,6 +163,9 @@ : label + ' km/h' }, title: function (tooltipItems) { + if (tooltipItems.length > 0) { + emitCoordinates(coordinates.value[tooltipItems[0].dataIndex]) + } return tooltipItems.length === 0 ? '' : displayDistance.value @@ -168,6 +183,12 @@ function formatDuration(duration: string | number): string { return new Date(+duration * 1000).toISOString().substr(11, 8) } + function emitCoordinates(coordinates: TCoordinates) { + emit('getCoordinates', coordinates) + } + function emitEmptyCoordinates() { + emitCoordinates({ latitude: null, longitude: null }) + } const { lineChartProps } = useLineChart({ chartData, @@ -177,6 +198,7 @@ displayDistance, lineChartProps, t, + emitEmptyCoordinates, updateDisplayDistance, } }, diff --git a/fittrackee_client/src/components/Workout/WorkoutDetail/WorkoutMap.vue b/fittrackee_client/src/components/Workout/WorkoutDetail/WorkoutMap.vue index 05614d8b..9d4eeea3 100644 --- a/fittrackee_client/src/components/Workout/WorkoutDetail/WorkoutMap.vue +++ b/fittrackee_client/src/components/Workout/WorkoutDetail/WorkoutMap.vue @@ -17,6 +17,10 @@ :bounds="bounds" /> +
{{ t('workouts.NO_MAP') }}
@@ -25,13 +29,13 @@ diff --git a/fittrackee_client/tests/unit/utils/workouts.spec.ts b/fittrackee_client/tests/unit/utils/workouts.spec.ts index 5edd00d7..fc7f0408 100644 --- a/fittrackee_client/tests/unit/utils/workouts.spec.ts +++ b/fittrackee_client/tests/unit/utils/workouts.spec.ts @@ -36,6 +36,7 @@ describe('getDatasets', () => { yAxisID: 'yElevation', }, }, + coordinates: [], }, }, { @@ -94,6 +95,11 @@ describe('getDatasets', () => { yAxisID: 'yElevation', }, }, + coordinates: [ + { latitude: 48.845574, longitude: 2.373723 }, + { latitude: 48.845578, longitude: 2.373732 }, + { latitude: 48.845591, longitude: 2.373811 }, + ], }, }, ]