|
15 | 15 | import { ApplicationSettings, Color, Utils } from '@nativescript/core';
|
16 | 16 | import { createEventDispatcher } from '@shared/utils/svelte/ui';
|
17 | 17 | import { NativeViewElementNode } from 'svelte-native/dom';
|
18 |
| - import { convertDurationSeconds, formatDistance, convertElevation } from '~/helpers/formatter'; |
| 18 | + import { convertDurationSeconds, convertElevation, formatDistance } from '~/helpers/formatter'; |
19 | 19 | import { getBounds } from '~/helpers/geolib';
|
20 | 20 | import { onThemeChanged } from '~/helpers/theme';
|
21 | 21 | import { getMapContext } from '~/mapModules/MapModule';
|
22 | 22 | import type { AscentSegment, IItem as Item } from '~/models/Item';
|
23 | 23 | import { showError } from '@shared/utils/showError';
|
24 | 24 | import { colors, fonts } from '~/variables';
|
25 | 25 | 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 | +
|
29 | 29 | const xintervals = [1, 2, 5, 10, 20, 50, 100];
|
30 | 30 | 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]; |
32 | 32 | }
|
33 | 33 |
|
34 |
| -
|
35 | 34 | const dispatch = createEventDispatcher();
|
36 | 35 | const mapContext = getMapContext();
|
37 |
| - |
| 36 | +
|
38 | 37 | const highlightPaint = new Paint();
|
39 | 38 | highlightPaint.setColor('#aaa');
|
40 | 39 | highlightPaint.setStrokeWidth(1);
|
41 | 40 | highlightPaint.setTextSize(10);
|
42 |
| - |
| 41 | +
|
43 | 42 | const waypointsBackPaint = new Paint();
|
44 | 43 | waypointsBackPaint.setColor(colorPrimary);
|
45 |
| - |
| 44 | +
|
46 | 45 | const waypointsPaint = new Paint();
|
47 | 46 | waypointsPaint.fontFamily = 'osm';
|
48 | 47 | waypointsPaint.setColor(colorOnPrimary);
|
49 | 48 | waypointsPaint.setTextSize(8);
|
50 | 49 | waypointsPaint.setTextAlign(Align.CENTER);
|
51 |
| - |
| 50 | +
|
52 | 51 | const nstringPaint = new Paint();
|
53 | 52 | nstringPaint.setColor('#aaa');
|
54 | 53 | nstringPaint.setStrokeWidth(1);
|
|
70 | 69 | showError(err);
|
71 | 70 | }
|
72 | 71 | }
|
73 |
| - $: if (chart?.nativeView?.data && (showProfileGrades !== undefined || showAscents !== undefined)){ |
| 72 | + $: if (chart?.nativeView?.data && (showProfileGrades !== undefined || showAscents !== undefined)) { |
74 | 73 | updateChartData(item);
|
75 | 74 | }
|
76 | 75 | let onChartDataUpdateCallbacks = [];
|
|
114 | 113 | if (!item) {
|
115 | 114 | return;
|
116 | 115 | }
|
117 |
| - const shouldSelectItem = event.highlight.hasOwnProperty('xPx'); |
118 |
| - // const shouldSelectItem = true; |
| 116 | + const shouldSelectItem = event.highlight.hasOwnProperty('xPx'); |
| 117 | + // const shouldSelectItem = true; |
119 | 118 | const entryIndex = event.highlight.entryIndex;
|
120 | 119 | const positions = item.geometry?.['coordinates'];
|
121 | 120 | const actualIndex = Math.max(0, Math.min(entryIndex, positions.length - 1));
|
|
181 | 180 | dataSet.valueTextColor = colorOnSurface;
|
182 | 181 | }
|
183 | 182 | });
|
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 | + ) { |
185 | 188 | if (!chart) {
|
186 | 189 | return;
|
187 | 190 | }
|
|
192 | 195 | return;
|
193 | 196 | }
|
194 | 197 | 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); |
196 | 199 | const onPathIndex = params.onPathIndex;
|
197 | 200 | if (onPathIndex === -1) {
|
198 | 201 | if (nChart) {
|
|
231 | 234 | text: '~' + (itemData.g || 0).toFixed() + '% '
|
232 | 235 | }
|
233 | 236 | ];
|
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 | + ); |
243 | 248 | }
|
244 | 249 | 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 | + ); |
253 | 260 | }
|
254 | 261 | if (!isNaN(params.remainingTime)) {
|
255 | 262 | spans.unshift(
|
|
292 | 299 | dataSet.ignoreFiltered = true;
|
293 | 300 | const entry = profileData[onPathIndex];
|
294 | 301 | 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)); |
296 | 303 | const highlight = {
|
297 | 304 | dataSetIndex: 0,
|
298 | 305 | entryIndex: onPathIndex,
|
|
377 | 384 | chartView.resetZoom();
|
378 | 385 | }
|
379 | 386 | const deltaA = profile.max[1] - profile.min[1];
|
380 |
| - let spaceMin = 50; |
| 387 | + const spaceMin = 50; |
381 | 388 | let spaceMax = 0;
|
382 | 389 | const chartElevationMinRange = ApplicationSettings.getNumber('chart_elevation_min_range', 250);
|
383 | 390 | if (deltaA < chartElevationMinRange) {
|
384 |
| - // const space = (chartElevationMinRange - deltaA) / 2; |
385 |
| - // spaceMin += space; |
| 391 | + // const space = (chartElevationMinRange - deltaA) / 2; |
| 392 | + // spaceMin += space; |
386 | 393 | spaceMax += chartElevationMinRange - deltaA;
|
387 | 394 | }
|
388 |
| - const labelCount = 5; |
| 395 | + const labelCount = 5; |
389 | 396 | const interval = Math.max(chartElevationMinRange, deltaA) / labelCount < 100 ? 50 : Math.round(Math.max(chartElevationMinRange, deltaA) / labelCount / 100) * 100;
|
390 | 397 | leftAxis.forcedInterval = interval;
|
391 | 398 | leftAxis.labelCount = labelCount;
|
392 | 399 | leftAxis.spaceMin = spaceMin;
|
393 | 400 | leftAxis.spaceMax = spaceMax;
|
394 | 401 | leftAxis.textSize = 9;
|
395 |
| - |
| 402 | +
|
396 | 403 | 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; |
399 | 406 | xAxis.forcedInterval = xinterval;
|
400 | 407 | xAxis.labelCount = xLabelCount;
|
401 | 408 | xAxis.textSize = 9;
|
|
413 | 420 | }
|
414 | 421 | }
|
415 | 422 | if (!chartData) {
|
416 |
| - set = new LineDataSet(profileData, 'a', 'd', 'a'); |
| 423 | + set = new LineDataSet(profileData, 'a', 'd', 'a'); |
417 | 424 | set.maxFilterNumber = ApplicationSettings.getNumber('chart_max_filter', 50);
|
418 | 425 | set.useColorsForFill = true;
|
419 | 426 | set.fillFormatter = {
|
|
439 | 446 | chartView.data = lineData;
|
440 | 447 | } else {
|
441 | 448 | chartView.highlightValues(null);
|
442 |
| - set = chartData.getDataSetByIndex(0) as LineDataSet; |
| 449 | + set = chartData.getDataSetByIndex(0); |
443 | 450 | updateSetColors();
|
444 | 451 | set.values = profileData;
|
445 | 452 | set.notifyDataSetChanged();
|
446 | 453 | chartData.notifyDataChanged();
|
447 | 454 | chartView.notifyDataSetChanged();
|
448 | 455 | }
|
449 |
| - |
| 456 | +
|
450 | 457 | leftAxis.removeAllLimitLines();
|
451 | 458 | let limitLine = new LimitLine(profile.min[1], convertElevation(profile.min[1]));
|
452 | 459 | limitLine.lineColor = colorOutline;
|
453 | 460 | limitLine.enableDashedLine(4, 3, 0);
|
454 | 461 | limitLine.lineWidth = 0.5;
|
455 | 462 | limitLine.yOffset = -1;
|
456 | 463 | limitLine.textSize = 9;
|
457 |
| - limitLine.textColor= colorOnSurface; |
458 |
| - // limitLine.ensureVisible = true; |
| 464 | + limitLine.textColor = colorOnSurface; |
| 465 | + // limitLine.ensureVisible = true; |
459 | 466 | limitLine.labelPosition = LimitLabelPosition.RIGHT_BOTTOM;
|
460 | 467 | leftAxis.addLimitLine(limitLine);
|
461 |
| - |
| 468 | +
|
462 | 469 | limitLine = new LimitLine(profile.max[1], convertElevation(profile.max[1]));
|
463 | 470 | limitLine.lineColor = colorOutline;
|
464 | 471 | limitLine.enableDashedLine(4, 3, 0);
|
465 | 472 | limitLine.lineWidth = 0.5;
|
466 | 473 | limitLine.yOffset = 1;
|
467 | 474 | limitLine.textSize = 9;
|
468 |
| - limitLine.textColor= colorOnSurface; |
| 475 | + limitLine.textColor = colorOnSurface; |
469 | 476 | limitLine.ensureVisible = true;
|
470 | 477 | leftAxis.addLimitLine(limitLine);
|
471 |
| - |
| 478 | +
|
472 | 479 | xAxis.removeAllLimitLines();
|
473 | 480 | if (showAscents) {
|
474 | 481 | profile.ascents.forEach((ascent: AscentSegment) => {
|
475 | 482 | const text = convertElevation(ascent.highestElevation) + '\n+' + convertElevation(ascent.gain);
|
476 |
| - |
| 483 | +
|
477 | 484 | limitLine = new LimitLine(profileData[ascent.highestPointIndex].d, text);
|
478 | 485 | limitLine.lineColor = colorOutline;
|
479 | 486 | limitLine.enableDashedLine(6, 3, 0);
|
480 | 487 | limitLine.lineWidth = 0.5;
|
481 | 488 | limitLine.textSize = 7;
|
482 | 489 | limitLine.xOffset = 0;
|
483 |
| - limitLine.textColor= colorOnSurface; |
| 490 | + limitLine.textColor = colorOnSurface; |
484 | 491 | limitLine.ensureVisible = true;
|
485 | 492 | limitLine.drawLabel = (c: Canvas, label: string, x: number, y: number, paint: Paint) => {
|
486 | 493 | c.drawCircle(x + 5, y - 6, 6, waypointsBackPaint);
|
487 | 494 | 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); |
490 | 497 | const staticLayout = new StaticLayout(label, paint, c.getWidth(), LayoutAlignment.ALIGN_NORMAL, 1, 0, true);
|
491 | 498 | c.save();
|
492 | 499 | c.translate(x, y - 3);
|
493 | 500 | staticLayout.draw(c);
|
494 | 501 | c.restore();
|
495 |
| - } |
| 502 | + }; |
496 | 503 | xAxis.addLimitLine(limitLine);
|
497 |
| - }); |
| 504 | + }); |
498 | 505 | }
|
499 | 506 | if (showWaypoints) {
|
500 | 507 | const positions = packageService.getRouteItemPoses(it);
|
501 |
| - it.route.waypoints.forEach(p=> { |
| 508 | + it.route.waypoints.forEach((p) => { |
502 | 509 | if (p.properties.showOnMap && p.properties.index > 0) {
|
503 | 510 | limitLine = new LimitLine(profileData[p.properties.index].d, ' ');
|
504 | 511 | limitLine.lineColor = colorOutline;
|
505 | 512 | limitLine.enableDashedLine(6, 3, 0);
|
506 | 513 | limitLine.lineWidth = 0.5;
|
507 | 514 | limitLine.ensureVisible = true;
|
508 | 515 | 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); |
511 | 517 | waypointsPaint.textSize = 8;
|
512 |
| - c.drawText('', x - 5, y +4 - 1, waypointsPaint); |
513 |
| - |
514 |
| - } |
| 518 | + c.drawText('', x - 5, y + 4 - 1, waypointsPaint); |
| 519 | + }; |
515 | 520 | xAxis.addLimitLine(limitLine);
|
516 | 521 | }
|
517 |
| - |
518 | 522 | });
|
519 | 523 | }
|
520 |
| - |
521 | 524 |
|
522 | 525 | onChartDataUpdateCallbacks.forEach((c) => c());
|
523 | 526 | onChartDataUpdateCallbacks = [];
|
|
0 commit comments