Skip to content

Commit 8420250

Browse files
committed
chore: fixes
1 parent 36ab66d commit 8420250

17 files changed

+637
-560
lines changed

app/components/chart/ElevationChart.svelte

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,39 @@
1515
import { ApplicationSettings, Color, Utils } from '@nativescript/core';
1616
import { createEventDispatcher } from '@shared/utils/svelte/ui';
1717
import { NativeViewElementNode } from 'svelte-native/dom';
18-
import { convertDurationSeconds, formatDistance, convertElevation } from '~/helpers/formatter';
18+
import { convertDurationSeconds, convertElevation, formatDistance } from '~/helpers/formatter';
1919
import { getBounds } from '~/helpers/geolib';
2020
import { onThemeChanged } from '~/helpers/theme';
2121
import { getMapContext } from '~/mapModules/MapModule';
2222
import type { AscentSegment, IItem as Item } from '~/models/Item';
2323
import { showError } from '@shared/utils/showError';
2424
import { colors, fonts } from '~/variables';
2525
import { SDK_VERSION } from '@akylas/nativescript/utils';
26-
let { colorOnSurface, colorOutline, colorOutlineVariant, colorOnPrimary, colorPrimary } = $colors;
27-
$: ({ colorOnSurface, colorOutline, colorOutlineVariant, colorPrimary } = $colors);
28-
26+
let { colorOnPrimary, colorOnSurface, colorOutline, colorOutlineVariant, colorPrimary } = $colors;
27+
$: ({ colorOnPrimary, colorOnSurface, colorOutline, colorOutlineVariant, colorPrimary } = $colors);
28+
2929
const xintervals = [1, 2, 5, 10, 20, 50, 100];
3030
function closestUpper(arr: number[], target: number): number | undefined {
31-
return arr.filter(x => x >= target).sort((a, b) => a - b)[0];
31+
return arr.filter((x) => x >= target).sort((a, b) => a - b)[0];
3232
}
3333
34-
3534
const dispatch = createEventDispatcher();
3635
const mapContext = getMapContext();
37-
36+
3837
const highlightPaint = new Paint();
3938
highlightPaint.setColor('#aaa');
4039
highlightPaint.setStrokeWidth(1);
4140
highlightPaint.setTextSize(10);
42-
41+
4342
const waypointsBackPaint = new Paint();
4443
waypointsBackPaint.setColor(colorPrimary);
45-
44+
4645
const waypointsPaint = new Paint();
4746
waypointsPaint.fontFamily = 'osm';
4847
waypointsPaint.setColor(colorOnPrimary);
4948
waypointsPaint.setTextSize(8);
5049
waypointsPaint.setTextAlign(Align.CENTER);
51-
50+
5251
const nstringPaint = new Paint();
5352
nstringPaint.setColor('#aaa');
5453
nstringPaint.setStrokeWidth(1);
@@ -70,7 +69,7 @@
7069
showError(err);
7170
}
7271
}
73-
$: if (chart?.nativeView?.data && (showProfileGrades !== undefined || showAscents !== undefined)){
72+
$: if (chart?.nativeView?.data && (showProfileGrades !== undefined || showAscents !== undefined)) {
7473
updateChartData(item);
7574
}
7675
let onChartDataUpdateCallbacks = [];
@@ -114,8 +113,8 @@
114113
if (!item) {
115114
return;
116115
}
117-
const shouldSelectItem = event.highlight.hasOwnProperty('xPx');
118-
// const shouldSelectItem = true;
116+
const shouldSelectItem = event.highlight.hasOwnProperty('xPx');
117+
// const shouldSelectItem = true;
119118
const entryIndex = event.highlight.entryIndex;
120119
const positions = item.geometry?.['coordinates'];
121120
const actualIndex = Math.max(0, Math.min(entryIndex, positions.length - 1));
@@ -181,7 +180,11 @@
181180
dataSet.valueTextColor = colorOnSurface;
182181
}
183182
});
184-
export function hilghlightPathIndex(params:{onPathIndex: number, remainingDistance: number, remainingDistanceToStep: number, remainingTime: number, dplus?: number, dmin?: number}, highlight?: Highlight<Entry>, sendEvent = true) {
183+
export function hilghlightPathIndex(
184+
params: { onPathIndex: number; remainingDistance: number; remainingDistanceToStep: number; remainingTime: number; dplus?: number; dmin?: number },
185+
highlight?: Highlight<Entry>,
186+
sendEvent = true
187+
) {
185188
if (!chart) {
186189
return;
187190
}
@@ -192,7 +195,7 @@
192195
return;
193196
}
194197
const nChart = chart?.nativeView;
195-
DEV_LOG && console.log('hilghlightPathIndex', !!item, JSON.stringify(params), JSON.stringify(highlight), nChart);
198+
DEV_LOG && console.log('hilghlightPathIndex', !!item, JSON.stringify(params), JSON.stringify(highlight), nChart);
196199
const onPathIndex = params.onPathIndex;
197200
if (onPathIndex === -1) {
198201
if (nChart) {
@@ -231,25 +234,29 @@
231234
text: '~' + (itemData.g || 0).toFixed() + '% '
232235
}
233236
];
234-
if (!isNaN(itemData.dp) && (params.dplus - itemData.dp > 0)) {
235-
spans.push({
236-
fontFamily: $fonts.mdi,
237-
color: colorPrimary,
238-
text: 'mdi-arrow-top-right'
239-
},
240-
{
241-
text: convertElevation(params.dplus - itemData.dp) + ' '
242-
});
237+
if (!isNaN(itemData.dp) && params.dplus - itemData.dp > 0) {
238+
spans.push(
239+
{
240+
fontFamily: $fonts.mdi,
241+
color: colorPrimary,
242+
text: 'mdi-arrow-top-right'
243+
},
244+
{
245+
text: convertElevation(params.dplus - itemData.dp) + ' '
246+
}
247+
);
243248
}
244249
if (!isNaN(itemData.dm) && Math.abs(params.dmin - itemData.dm) > 0) {
245-
spans.push({
246-
fontFamily: $fonts.mdi,
247-
color: colorPrimary,
248-
text: 'mdi-arrow-bottom-right'
249-
},
250-
{
251-
text: convertElevation(-(params.dmin - itemData.dm)) + ' '
252-
});
250+
spans.push(
251+
{
252+
fontFamily: $fonts.mdi,
253+
color: colorPrimary,
254+
text: 'mdi-arrow-bottom-right'
255+
},
256+
{
257+
text: convertElevation(-(params.dmin - itemData.dm)) + ' '
258+
}
259+
);
253260
}
254261
if (!isNaN(params.remainingTime)) {
255262
spans.unshift(
@@ -292,7 +299,7 @@
292299
dataSet.ignoreFiltered = true;
293300
const entry = profileData[onPathIndex];
294301
dataSet.ignoreFiltered = false;
295-
DEV_LOG && console.log('highlight', onPathIndex, sendEvent, entry.d, JSON.stringify(entry));
302+
DEV_LOG && console.log('highlight', onPathIndex, sendEvent, entry.d, JSON.stringify(entry));
296303
const highlight = {
297304
dataSetIndex: 0,
298305
entryIndex: onPathIndex,
@@ -377,25 +384,25 @@
377384
chartView.resetZoom();
378385
}
379386
const deltaA = profile.max[1] - profile.min[1];
380-
let spaceMin = 50;
387+
const spaceMin = 50;
381388
let spaceMax = 0;
382389
const chartElevationMinRange = ApplicationSettings.getNumber('chart_elevation_min_range', 250);
383390
if (deltaA < chartElevationMinRange) {
384-
// const space = (chartElevationMinRange - deltaA) / 2;
385-
// spaceMin += space;
391+
// const space = (chartElevationMinRange - deltaA) / 2;
392+
// spaceMin += space;
386393
spaceMax += chartElevationMinRange - deltaA;
387394
}
388-
const labelCount = 5;
395+
const labelCount = 5;
389396
const interval = Math.max(chartElevationMinRange, deltaA) / labelCount < 100 ? 50 : Math.round(Math.max(chartElevationMinRange, deltaA) / labelCount / 100) * 100;
390397
leftAxis.forcedInterval = interval;
391398
leftAxis.labelCount = labelCount;
392399
leftAxis.spaceMin = spaceMin;
393400
leftAxis.spaceMax = spaceMax;
394401
leftAxis.textSize = 9;
395-
402+
396403
const totalDistance = it.route.totalDistance;
397-
const xLabelCount = 6;
398-
xinterval = closestUpper( xintervals, totalDistance / xLabelCount / 1000)* 1000;
404+
const xLabelCount = 6;
405+
xinterval = closestUpper(xintervals, totalDistance / xLabelCount / 1000) * 1000;
399406
xAxis.forcedInterval = xinterval;
400407
xAxis.labelCount = xLabelCount;
401408
xAxis.textSize = 9;
@@ -413,7 +420,7 @@
413420
}
414421
}
415422
if (!chartData) {
416-
set = new LineDataSet(profileData, 'a', 'd', 'a');
423+
set = new LineDataSet(profileData, 'a', 'd', 'a');
417424
set.maxFilterNumber = ApplicationSettings.getNumber('chart_max_filter', 50);
418425
set.useColorsForFill = true;
419426
set.fillFormatter = {
@@ -439,85 +446,81 @@
439446
chartView.data = lineData;
440447
} else {
441448
chartView.highlightValues(null);
442-
set = chartData.getDataSetByIndex(0) as LineDataSet;
449+
set = chartData.getDataSetByIndex(0);
443450
updateSetColors();
444451
set.values = profileData;
445452
set.notifyDataSetChanged();
446453
chartData.notifyDataChanged();
447454
chartView.notifyDataSetChanged();
448455
}
449-
456+
450457
leftAxis.removeAllLimitLines();
451458
let limitLine = new LimitLine(profile.min[1], convertElevation(profile.min[1]));
452459
limitLine.lineColor = colorOutline;
453460
limitLine.enableDashedLine(4, 3, 0);
454461
limitLine.lineWidth = 0.5;
455462
limitLine.yOffset = -1;
456463
limitLine.textSize = 9;
457-
limitLine.textColor= colorOnSurface;
458-
// limitLine.ensureVisible = true;
464+
limitLine.textColor = colorOnSurface;
465+
// limitLine.ensureVisible = true;
459466
limitLine.labelPosition = LimitLabelPosition.RIGHT_BOTTOM;
460467
leftAxis.addLimitLine(limitLine);
461-
468+
462469
limitLine = new LimitLine(profile.max[1], convertElevation(profile.max[1]));
463470
limitLine.lineColor = colorOutline;
464471
limitLine.enableDashedLine(4, 3, 0);
465472
limitLine.lineWidth = 0.5;
466473
limitLine.yOffset = 1;
467474
limitLine.textSize = 9;
468-
limitLine.textColor= colorOnSurface;
475+
limitLine.textColor = colorOnSurface;
469476
limitLine.ensureVisible = true;
470477
leftAxis.addLimitLine(limitLine);
471-
478+
472479
xAxis.removeAllLimitLines();
473480
if (showAscents) {
474481
profile.ascents.forEach((ascent: AscentSegment) => {
475482
const text = convertElevation(ascent.highestElevation) + '\n+' + convertElevation(ascent.gain);
476-
483+
477484
limitLine = new LimitLine(profileData[ascent.highestPointIndex].d, text);
478485
limitLine.lineColor = colorOutline;
479486
limitLine.enableDashedLine(6, 3, 0);
480487
limitLine.lineWidth = 0.5;
481488
limitLine.textSize = 7;
482489
limitLine.xOffset = 0;
483-
limitLine.textColor= colorOnSurface;
490+
limitLine.textColor = colorOnSurface;
484491
limitLine.ensureVisible = true;
485492
limitLine.drawLabel = (c: Canvas, label: string, x: number, y: number, paint: Paint) => {
486493
c.drawCircle(x + 5, y - 6, 6, waypointsBackPaint);
487494
waypointsPaint.textSize = 7;
488-
c.drawText('', x + 5, y - 5 +1, waypointsPaint);
489-
// paint.setTextAlign(Align.CENTER);
495+
c.drawText('', x + 5, y - 5 + 1, waypointsPaint);
496+
// paint.setTextAlign(Align.CENTER);
490497
const staticLayout = new StaticLayout(label, paint, c.getWidth(), LayoutAlignment.ALIGN_NORMAL, 1, 0, true);
491498
c.save();
492499
c.translate(x, y - 3);
493500
staticLayout.draw(c);
494501
c.restore();
495-
}
502+
};
496503
xAxis.addLimitLine(limitLine);
497-
});
504+
});
498505
}
499506
if (showWaypoints) {
500507
const positions = packageService.getRouteItemPoses(it);
501-
it.route.waypoints.forEach(p=> {
508+
it.route.waypoints.forEach((p) => {
502509
if (p.properties.showOnMap && p.properties.index > 0) {
503510
limitLine = new LimitLine(profileData[p.properties.index].d, ' ');
504511
limitLine.lineColor = colorOutline;
505512
limitLine.enableDashedLine(6, 3, 0);
506513
limitLine.lineWidth = 0.5;
507514
limitLine.ensureVisible = true;
508515
limitLine.drawLabel = (c: Canvas, label: string, x: number, y: number, paint: Paint) => {
509-
510-
c.drawCircle(x - 5, y +0, 6, waypointsBackPaint);
516+
c.drawCircle(x - 5, y + 0, 6, waypointsBackPaint);
511517
waypointsPaint.textSize = 8;
512-
c.drawText('', x - 5, y +4 - 1, waypointsPaint);
513-
514-
}
518+
c.drawText('', x - 5, y + 4 - 1, waypointsPaint);
519+
};
515520
xAxis.addLimitLine(limitLine);
516521
}
517-
518522
});
519523
}
520-
521524
522525
onChartDataUpdateCallbacks.forEach((c) => c());
523526
onChartDataUpdateCallbacks = [];

0 commit comments

Comments
 (0)