From ea01eac5e24607ac3e7bf17d25b9a3721c020bc0 Mon Sep 17 00:00:00 2001 From: AlitaBernachot Date: Fri, 15 Nov 2024 16:53:58 +0100 Subject: [PATCH] test: add ut for profile --- .../d3-graph-elevation.fixtures.ts | 1012 ++++++++++++++++ .../graph/d3-graph-elevation.fixtures.ts | 1022 ----------------- .../common/graph/d3-graph-elevation.spec.ts | 4 + .../common/graph/d3-graph-elevation.vue | 2 +- .../common/graph/elevation-profile.spec.ts | 42 + src/components/draw/feature-menu-popup.vue | 4 +- .../feature-elevation-profil.spec.ts | 144 +++ src/directives/format-measure.directive.ts | 22 + src/services/common/formatting.utils.spec.ts | 125 +- src/services/common/formatting.utils.ts | 28 +- src/services/draw/drawn-feature.spec.ts | 97 +- .../export-feature-profile-csv.spec.ts | 63 + .../export-feature/export-feature.service.ts | 4 +- .../export-feature/export-feature.spec.ts | 115 ++ .../ol-layer-feature-position.helper.spec.ts | 47 + .../ol-layer-feature-position.helper.ts | 6 +- src/services/ol-layer/styles.helper.spec.ts | 26 + .../state-persistor-map.service.spec.ts | 2 +- src/services/utils.spec.ts | 39 +- src/services/utils.ts | 5 + 20 files changed, 1772 insertions(+), 1037 deletions(-) create mode 100644 src/__fixtures__/d3-graph-elevation.fixtures.ts delete mode 100644 src/components/common/graph/d3-graph-elevation.fixtures.ts create mode 100644 src/components/common/graph/elevation-profile.spec.ts create mode 100644 src/components/feature-elevation-profile/feature-elevation-profil.spec.ts create mode 100644 src/services/export-feature/export-feature-profile-csv.spec.ts create mode 100644 src/services/export-feature/export-feature.spec.ts create mode 100644 src/services/ol-layer/ol-layer-feature-position.helper.spec.ts create mode 100644 src/services/ol-layer/styles.helper.spec.ts diff --git a/src/__fixtures__/d3-graph-elevation.fixtures.ts b/src/__fixtures__/d3-graph-elevation.fixtures.ts new file mode 100644 index 00000000..cca766b9 --- /dev/null +++ b/src/__fixtures__/d3-graph-elevation.fixtures.ts @@ -0,0 +1,1012 @@ +export const dataset = [ + { + dist: 0, + values: { dhm: 417.04 }, + x: 73679.482601148, + y: 110624.051484868, + id: '', + cumulativeElevation: 0, + elevationGain: 0, + elevationLoss: 0, + }, + { + dist: 95.8, + values: { dhm: 447.74 }, + x: 73771.64510032868, + y: 110597.7924035457, + id: '', + cumulativeElevation: 30.69999999999999, + elevationGain: 30.69999999999999, + elevationLoss: 0, + }, + { + dist: 191.7, + values: { dhm: 464.15 }, + x: 73863.80759950935, + y: 110571.53332222339, + id: '', + cumulativeElevation: 47.10999999999996, + elevationGain: 47.10999999999996, + elevationLoss: 0, + }, + { + dist: 287.5, + values: { dhm: 471.31 }, + x: 73955.97009869003, + y: 110545.2742409011, + id: '', + cumulativeElevation: 54.26999999999998, + elevationGain: 54.26999999999998, + elevationLoss: 0, + }, + { + dist: 383.3, + values: { dhm: 475.44 }, + x: 74048.1325978707, + y: 110519.01515957879, + id: '', + cumulativeElevation: 58.39999999999998, + elevationGain: 58.39999999999998, + elevationLoss: 0, + }, + { + dist: 479.2, + values: { dhm: 476.98 }, + x: 74140.29509705138, + y: 110492.75607825648, + id: '', + cumulativeElevation: 59.94, + elevationGain: 59.94, + elevationLoss: 0, + }, + { + dist: 575, + values: { dhm: 475.23 }, + x: 74232.45759623205, + y: 110466.49699693418, + id: '', + cumulativeElevation: 58.19, + elevationGain: 59.94, + elevationLoss: -1.75, + }, + { + dist: 670.8, + values: { dhm: 455.88 }, + x: 74324.62009541273, + y: 110440.23791561187, + id: '', + cumulativeElevation: 38.839999999999975, + elevationGain: 59.94, + elevationLoss: -21.100000000000023, + }, + { + dist: 766.6, + values: { dhm: 466.35 }, + x: 74416.78259459339, + y: 110413.97883428956, + id: '', + cumulativeElevation: 49.31, + elevationGain: 70.41000000000003, + elevationLoss: -21.100000000000023, + }, + { + dist: 862.5, + values: { dhm: 458.52 }, + x: 74508.94509377406, + y: 110387.71975296727, + id: '', + cumulativeElevation: 41.47999999999996, + elevationGain: 70.41000000000003, + elevationLoss: -28.930000000000064, + }, + { + dist: 958.3, + values: { dhm: 440.88 }, + x: 74601.10759295474, + y: 110361.46067164496, + id: '', + cumulativeElevation: 23.839999999999975, + elevationGain: 70.41000000000003, + elevationLoss: -46.57000000000005, + }, + { + dist: 1054.1, + values: { dhm: 405.59 }, + x: 74693.27009213541, + y: 110335.20159032266, + id: '', + cumulativeElevation: -11.450000000000045, + elevationGain: 70.41000000000003, + elevationLoss: -81.86000000000007, + }, + { + dist: 1150, + values: { dhm: 344.16 }, + x: 74785.43259131609, + y: 110308.94250900035, + id: '', + cumulativeElevation: -72.88, + elevationGain: 70.41000000000003, + elevationLoss: -143.29000000000002, + }, + { + dist: 1245.8, + values: { dhm: 389.09 }, + x: 74877.59509049676, + y: 110282.68342767804, + id: '', + cumulativeElevation: -27.950000000000045, + elevationGain: 115.33999999999997, + elevationLoss: -143.29000000000002, + }, + { + dist: 1341.6, + values: { dhm: 434.09 }, + x: 74969.75758967744, + y: 110256.42434635574, + id: '', + cumulativeElevation: 17.049999999999955, + elevationGain: 160.33999999999997, + elevationLoss: -143.29000000000002, + }, + { + dist: 1437.5, + values: { dhm: 426.46 }, + x: 75061.92008885811, + y: 110230.16526503344, + id: '', + cumulativeElevation: 9.419999999999959, + elevationGain: 160.33999999999997, + elevationLoss: -150.92000000000002, + }, + { + dist: 1533.3, + values: { dhm: 397.69 }, + x: 75154.08258803879, + y: 110203.90618371114, + id: '', + cumulativeElevation: -19.350000000000023, + elevationGain: 160.33999999999997, + elevationLoss: -179.69, + }, + { + dist: 1629.1, + values: { dhm: 411.77 }, + x: 75246.24508721946, + y: 110177.64710238883, + id: '', + cumulativeElevation: -5.270000000000039, + elevationGain: 174.41999999999996, + elevationLoss: -179.69, + }, + { + dist: 1724.9, + values: { dhm: 444.31 }, + x: 75338.40758640014, + y: 110151.38802106652, + id: '', + cumulativeElevation: 27.269999999999982, + elevationGain: 206.95999999999998, + elevationLoss: -179.69, + }, + { + dist: 1820.8, + values: { dhm: 443.65 }, + x: 75430.57008558081, + y: 110125.12893974422, + id: '', + cumulativeElevation: 26.609999999999957, + elevationGain: 206.95999999999998, + elevationLoss: -180.35000000000002, + }, + { + dist: 1916.6, + values: { dhm: 439.29 }, + x: 75522.73258476148, + y: 110098.86985842191, + id: '', + cumulativeElevation: 22.25, + elevationGain: 206.95999999999998, + elevationLoss: -184.70999999999998, + }, + { + dist: 2012.4, + values: { dhm: 441.37 }, + x: 75614.89508394216, + y: 110072.61077709962, + id: '', + cumulativeElevation: 24.329999999999984, + elevationGain: 209.03999999999996, + elevationLoss: -184.70999999999998, + }, + { + dist: 2108.3, + values: { dhm: 442.05 }, + x: 75707.05758312283, + y: 110046.35169577731, + id: '', + cumulativeElevation: 25.00999999999999, + elevationGain: 209.71999999999997, + elevationLoss: -184.70999999999998, + }, + { + dist: 2204.1, + values: { dhm: 435.89 }, + x: 75799.22008230351, + y: 110020.092614455, + id: '', + cumulativeElevation: 18.849999999999966, + elevationGain: 209.71999999999997, + elevationLoss: -190.87, + }, + { + dist: 2299.9, + values: { dhm: 426.96 }, + x: 75891.38258148417, + y: 109993.8335331327, + id: '', + cumulativeElevation: 9.919999999999959, + elevationGain: 209.71999999999997, + elevationLoss: -199.8, + }, + { + dist: 2395.8, + values: { dhm: 414.79 }, + x: 75983.54508066484, + y: 109967.57445181039, + id: '', + cumulativeElevation: -2.25, + elevationGain: 209.71999999999997, + elevationLoss: -211.96999999999997, + }, + { + dist: 2491.6, + values: { dhm: 372.16 }, + x: 76075.70757984552, + y: 109941.3153704881, + id: '', + cumulativeElevation: -44.879999999999995, + elevationGain: 209.71999999999997, + elevationLoss: -254.59999999999997, + }, + { + dist: 2587.4, + values: { dhm: 314.67 }, + x: 76167.8700790262, + y: 109915.05628916579, + id: '', + cumulativeElevation: -102.37, + elevationGain: 209.71999999999997, + elevationLoss: -312.09, + }, + { + dist: 2683.3, + values: { dhm: 346.33 }, + x: 76260.03257820687, + y: 109888.79720784348, + id: '', + cumulativeElevation: -70.71000000000004, + elevationGain: 241.37999999999994, + elevationLoss: -312.09, + }, + { + dist: 2779.1, + values: { dhm: 392.62 }, + x: 76352.19507738754, + y: 109862.53812652118, + id: '', + cumulativeElevation: -24.420000000000016, + elevationGain: 287.66999999999996, + elevationLoss: -312.09, + }, + { + dist: 2874.9, + values: { dhm: 424 }, + x: 76444.35757656822, + y: 109836.27904519887, + id: '', + cumulativeElevation: 6.9599999999999795, + elevationGain: 319.04999999999995, + elevationLoss: -312.09, + }, + { + dist: 2970.7, + values: { dhm: 444.19 }, + x: 76536.5200757489, + y: 109810.01996387656, + id: '', + cumulativeElevation: 27.149999999999977, + elevationGain: 339.23999999999995, + elevationLoss: -312.09, + }, + { + dist: 3066.6, + values: { dhm: 448.06 }, + x: 76628.68257492957, + y: 109783.76088255427, + id: '', + cumulativeElevation: 31.019999999999982, + elevationGain: 343.10999999999996, + elevationLoss: -312.09, + }, + { + dist: 3162.4, + values: { dhm: 445.95 }, + x: 76720.84507411024, + y: 109757.50180123196, + id: '', + cumulativeElevation: 28.909999999999968, + elevationGain: 343.10999999999996, + elevationLoss: -314.2, + }, + { + dist: 3258.2, + values: { dhm: 442 }, + x: 76813.00757329092, + y: 109731.24271990966, + id: '', + cumulativeElevation: 24.95999999999998, + elevationGain: 343.10999999999996, + elevationLoss: -318.15, + }, + { + dist: 3354.1, + values: { dhm: 419.38 }, + x: 76905.17007247159, + y: 109704.98363858735, + id: '', + cumulativeElevation: 2.339999999999975, + elevationGain: 343.10999999999996, + elevationLoss: -340.77, + }, + { + dist: 3449.9, + values: { dhm: 419.2 }, + x: 76997.33257165227, + y: 109678.72455726504, + id: '', + cumulativeElevation: 2.159999999999968, + elevationGain: 343.10999999999996, + elevationLoss: -340.95, + }, + { + dist: 3545.7, + values: { dhm: 433.89 }, + x: 77089.49507083294, + y: 109652.46547594274, + id: '', + cumulativeElevation: 16.849999999999966, + elevationGain: 357.79999999999995, + elevationLoss: -340.95, + }, + { + dist: 3641.6, + values: { dhm: 434.13 }, + x: 77181.6575700136, + y: 109626.20639462044, + id: '', + cumulativeElevation: 17.089999999999975, + elevationGain: 358.03999999999996, + elevationLoss: -340.95, + }, + { + dist: 3737.4, + values: { dhm: 432.54 }, + x: 77273.82006919428, + y: 109599.94731329814, + id: '', + cumulativeElevation: 15.5, + elevationGain: 358.03999999999996, + elevationLoss: -342.53999999999996, + }, + { + dist: 3833.2, + values: { dhm: 426.04 }, + x: 77365.98256837495, + y: 109573.68823197583, + id: '', + cumulativeElevation: 9, + elevationGain: 358.03999999999996, + elevationLoss: -349.03999999999996, + }, + { + dist: 3929, + values: { dhm: 423.16 }, + x: 77458.14506755563, + y: 109547.42915065352, + id: '', + cumulativeElevation: 6.1200000000000045, + elevationGain: 358.03999999999996, + elevationLoss: -351.91999999999996, + }, + { + dist: 4024.9, + values: { dhm: 418.4 }, + x: 77550.3075667363, + y: 109521.17006933122, + id: '', + cumulativeElevation: 1.3599999999999568, + elevationGain: 358.03999999999996, + elevationLoss: -356.68, + }, + { + dist: 4120.7, + values: { dhm: 410.22 }, + x: 77642.47006591698, + y: 109494.91098800891, + id: '', + cumulativeElevation: -6.819999999999993, + elevationGain: 358.03999999999996, + elevationLoss: -364.85999999999996, + }, + { + dist: 4216.5, + values: { dhm: 357.69 }, + x: 77734.63256509765, + y: 109468.65190668662, + id: '', + cumulativeElevation: -59.35000000000002, + elevationGain: 358.03999999999996, + elevationLoss: -417.39, + }, + { + dist: 4312.4, + values: { dhm: 298.91 }, + x: 77826.79506427833, + y: 109442.39282536431, + id: '', + cumulativeElevation: -118.13, + elevationGain: 358.03999999999996, + elevationLoss: -476.16999999999996, + }, + { + dist: 4408.2, + values: { dhm: 345.53 }, + x: 77918.957563459, + y: 109416.133744042, + id: '', + cumulativeElevation: -71.51000000000005, + elevationGain: 404.6599999999999, + elevationLoss: -476.16999999999996, + }, + { + dist: 4504.8, + values: { dhm: 398.74 }, + x: 78015.29530200161, + y: 109423.42917632837, + id: '', + cumulativeElevation: -18.30000000000001, + elevationGain: 457.86999999999995, + elevationLoss: -476.16999999999996, + }, + { + dist: 4601.4, + values: { dhm: 420.13 }, + x: 78111.63304054423, + y: 109430.72460861475, + id: '', + cumulativeElevation: 3.089999999999975, + elevationGain: 479.25999999999993, + elevationLoss: -476.16999999999996, + }, + { + dist: 4698, + values: { dhm: 431.13 }, + x: 78207.97077908683, + y: 109438.02004090112, + id: '', + cumulativeElevation: 14.089999999999975, + elevationGain: 490.25999999999993, + elevationLoss: -476.16999999999996, + }, + { + dist: 4794.7, + values: { dhm: 436.56 }, + x: 78304.30851762944, + y: 109445.31547318748, + id: '', + cumulativeElevation: 19.519999999999982, + elevationGain: 495.68999999999994, + elevationLoss: -476.16999999999996, + }, + { + dist: 4891.3, + values: { dhm: 438.56 }, + x: 78400.64625617205, + y: 109452.61090547385, + id: '', + cumulativeElevation: 21.519999999999982, + elevationGain: 497.68999999999994, + elevationLoss: -476.16999999999996, + }, + { + dist: 4987.9, + values: { dhm: 440.02 }, + x: 78496.98399471467, + y: 109459.90633776023, + id: '', + cumulativeElevation: 22.97999999999996, + elevationGain: 499.1499999999999, + elevationLoss: -476.16999999999996, + }, + { + dist: 5084.5, + values: { dhm: 440.66 }, + x: 78593.32173325728, + y: 109467.2017700466, + id: '', + cumulativeElevation: 23.620000000000005, + elevationGain: 499.78999999999996, + elevationLoss: -476.16999999999996, + }, + { + dist: 5181.1, + values: { dhm: 440.66 }, + x: 78689.6594717999, + y: 109474.49720233296, + id: '', + cumulativeElevation: 23.620000000000005, + elevationGain: 499.78999999999996, + elevationLoss: -476.16999999999996, + }, + { + dist: 5277.7, + values: { dhm: 440.17 }, + x: 78785.9972103425, + y: 109481.79263461934, + id: '', + cumulativeElevation: 23.129999999999995, + elevationGain: 499.78999999999996, + elevationLoss: -476.65999999999997, + }, + { + dist: 5374.3, + values: { dhm: 439.32 }, + x: 78882.33494888511, + y: 109489.08806690571, + id: '', + cumulativeElevation: 22.279999999999973, + elevationGain: 499.78999999999996, + elevationLoss: -477.51, + }, + { + dist: 5470.9, + values: { dhm: 437.78 }, + x: 78978.67268742772, + y: 109496.38349919207, + id: '', + cumulativeElevation: 20.739999999999952, + elevationGain: 499.78999999999996, + elevationLoss: -479.05, + }, + { + dist: 5567.6, + values: { dhm: 435.12 }, + x: 79075.01042597034, + y: 109503.67893147845, + id: '', + cumulativeElevation: 18.079999999999984, + elevationGain: 499.78999999999996, + elevationLoss: -481.71, + }, + { + dist: 5664.2, + values: { dhm: 430.87 }, + x: 79171.34816451295, + y: 109510.97436376482, + id: '', + cumulativeElevation: 13.829999999999984, + elevationGain: 499.78999999999996, + elevationLoss: -485.96, + }, + { + dist: 5760.8, + values: { dhm: 425.06 }, + x: 79267.68590305555, + y: 109518.26979605119, + id: '', + cumulativeElevation: 8.019999999999982, + elevationGain: 499.78999999999996, + elevationLoss: -491.77, + }, + { + dist: 5857.4, + values: { dhm: 415.91 }, + x: 79364.02364159816, + y: 109525.56522833755, + id: '', + cumulativeElevation: -1.1299999999999955, + elevationGain: 499.78999999999996, + elevationLoss: -500.91999999999996, + }, + { + dist: 5954, + values: { dhm: 403.05 }, + x: 79460.36138014078, + y: 109532.86066062393, + id: '', + cumulativeElevation: -13.990000000000009, + elevationGain: 499.78999999999996, + elevationLoss: -513.78, + }, + { + dist: 6050.6, + values: { dhm: 371.07 }, + x: 79556.69911868339, + y: 109540.1560929103, + id: '', + cumulativeElevation: -45.97000000000003, + elevationGain: 499.78999999999996, + elevationLoss: -545.76, + }, + { + dist: 6147.2, + values: { dhm: 332.52 }, + x: 79653.036857226, + y: 109547.45152519667, + id: '', + cumulativeElevation: -84.52000000000004, + elevationGain: 499.78999999999996, + elevationLoss: -584.31, + }, + { + dist: 6243.9, + values: { dhm: 327.7 }, + x: 79749.3745957686, + y: 109554.74695748305, + id: '', + cumulativeElevation: -89.34000000000003, + elevationGain: 499.78999999999996, + elevationLoss: -589.1299999999999, + }, + { + dist: 6340.5, + values: { dhm: 307.16 }, + x: 79845.71233431122, + y: 109562.04238976941, + id: '', + cumulativeElevation: -109.88, + elevationGain: 499.78999999999996, + elevationLoss: -609.6699999999998, + }, + { + dist: 6437.1, + values: { dhm: 295.12 }, + x: 79942.05007285383, + y: 109569.33782205578, + id: '', + cumulativeElevation: -121.92000000000002, + elevationGain: 499.78999999999996, + elevationLoss: -621.7099999999998, + }, + { + dist: 6533.7, + values: { dhm: 301.26 }, + x: 80038.38781139645, + y: 109576.63325434216, + id: '', + cumulativeElevation: -115.78000000000003, + elevationGain: 505.92999999999995, + elevationLoss: -621.7099999999998, + }, + { + dist: 6630.3, + values: { dhm: 322.12 }, + x: 80134.72554993906, + y: 109583.92868662853, + id: '', + cumulativeElevation: -94.92000000000002, + elevationGain: 526.79, + elevationLoss: -621.7099999999998, + }, + { + dist: 6726.9, + values: { dhm: 355.86 }, + x: 80231.06328848167, + y: 109591.22411891489, + id: '', + cumulativeElevation: -61.18000000000001, + elevationGain: 560.53, + elevationLoss: -621.7099999999998, + }, + { + dist: 6823.5, + values: { dhm: 355.04 }, + x: 80327.40102702427, + y: 109598.51955120126, + id: '', + cumulativeElevation: -62, + elevationGain: 560.53, + elevationLoss: -622.5299999999997, + }, + { + dist: 6920.2, + values: { dhm: 333.44 }, + x: 80423.73876556689, + y: 109605.81498348764, + id: '', + cumulativeElevation: -83.60000000000002, + elevationGain: 560.53, + elevationLoss: -644.1299999999998, + }, + { + dist: 7016.8, + values: { dhm: 317.78 }, + x: 80520.0765041095, + y: 109613.110415774, + id: '', + cumulativeElevation: -99.26000000000005, + elevationGain: 560.53, + elevationLoss: -659.7899999999997, + }, + { + dist: 7113.4, + values: { dhm: 304.48 }, + x: 80616.41424265211, + y: 109620.40584806037, + id: '', + cumulativeElevation: -112.56, + elevationGain: 560.53, + elevationLoss: -673.0899999999997, + }, + { + dist: 7210, + values: { dhm: 326.67 }, + x: 80712.75198119473, + y: 109627.70128034675, + id: '', + cumulativeElevation: -90.37, + elevationGain: 582.72, + elevationLoss: -673.0899999999997, + }, + { + dist: 7306.6, + values: { dhm: 354.73 }, + x: 80809.08971973733, + y: 109634.99671263312, + id: '', + cumulativeElevation: -62.31, + elevationGain: 610.78, + elevationLoss: -673.0899999999997, + }, + { + dist: 7403.2, + values: { dhm: 364.41 }, + x: 80905.42745827994, + y: 109642.29214491948, + id: '', + cumulativeElevation: -52.629999999999995, + elevationGain: 620.46, + elevationLoss: -673.0899999999997, + }, + { + dist: 7499.8, + values: { dhm: 354.23 }, + x: 81001.76519682255, + y: 109649.58757720585, + id: '', + cumulativeElevation: -62.81, + elevationGain: 620.46, + elevationLoss: -683.2699999999998, + }, + { + dist: 7596.4, + values: { dhm: 330.1 }, + x: 81098.10293536517, + y: 109656.88300949223, + id: '', + cumulativeElevation: -86.94, + elevationGain: 620.46, + elevationLoss: -707.3999999999997, + }, + { + dist: 7693.1, + values: { dhm: 316.28 }, + x: 81194.44067390778, + y: 109664.1784417786, + id: '', + cumulativeElevation: -100.76000000000005, + elevationGain: 620.46, + elevationLoss: -721.2199999999998, + }, + { + dist: 7789.7, + values: { dhm: 349.55 }, + x: 81290.7784124504, + y: 109671.47387406496, + id: '', + cumulativeElevation: -67.49000000000001, + elevationGain: 653.73, + elevationLoss: -721.2199999999998, + }, + { + dist: 7886.3, + values: { dhm: 363.53 }, + x: 81387.116150993, + y: 109678.76930635134, + id: '', + cumulativeElevation: -53.51000000000005, + elevationGain: 667.71, + elevationLoss: -721.2199999999998, + }, + { + dist: 7982.9, + values: { dhm: 368.73 }, + x: 81483.45388953561, + y: 109686.06473863771, + id: '', + cumulativeElevation: -48.31, + elevationGain: 672.9100000000001, + elevationLoss: -721.2199999999998, + }, + { + dist: 8079.5, + values: { dhm: 368.32 }, + x: 81579.79162807822, + y: 109693.36017092408, + id: '', + cumulativeElevation: -48.72000000000003, + elevationGain: 672.9100000000001, + elevationLoss: -721.6299999999999, + }, + { + dist: 8176.1, + values: { dhm: 361.09 }, + x: 81676.12936662084, + y: 109700.65560321046, + id: '', + cumulativeElevation: -55.950000000000045, + elevationGain: 672.9100000000001, + elevationLoss: -728.8599999999999, + }, + { + dist: 8272.7, + values: { dhm: 357.96 }, + x: 81772.46710516345, + y: 109707.95103549682, + id: '', + cumulativeElevation: -59.08000000000004, + elevationGain: 672.9100000000001, + elevationLoss: -731.9899999999999, + }, + { + dist: 8369.4, + values: { dhm: 361.51 }, + x: 81868.80484370605, + y: 109715.24646778319, + id: '', + cumulativeElevation: -55.53000000000003, + elevationGain: 676.46, + elevationLoss: -731.9899999999999, + }, + { + dist: 8466, + values: { dhm: 356.17 }, + x: 81965.14258224866, + y: 109722.54190006955, + id: '', + cumulativeElevation: -60.870000000000005, + elevationGain: 676.46, + elevationLoss: -737.3299999999999, + }, + { + dist: 8562.6, + values: { dhm: 352.78 }, + x: 82061.48032079128, + y: 109729.83733235594, + id: '', + cumulativeElevation: -64.26000000000005, + elevationGain: 676.46, + elevationLoss: -740.72, + }, + { + dist: 8659.2, + values: { dhm: 348.02 }, + x: 82157.81805933389, + y: 109737.1327646423, + id: '', + cumulativeElevation: -69.02000000000004, + elevationGain: 676.46, + elevationLoss: -745.48, + }, + { + dist: 8755.8, + values: { dhm: 344.96 }, + x: 82254.1557978765, + y: 109744.42819692867, + id: '', + cumulativeElevation: -72.08000000000004, + elevationGain: 676.46, + elevationLoss: -748.54, + }, + { + dist: 8852.4, + values: { dhm: 339.98 }, + x: 82350.4935364191, + y: 109751.72362921505, + id: '', + cumulativeElevation: -77.06, + elevationGain: 676.46, + elevationLoss: -753.52, + }, + { + dist: 8949, + values: { dhm: 334.18 }, + x: 82446.83127496172, + y: 109759.01906150141, + id: '', + cumulativeElevation: -82.86000000000001, + elevationGain: 676.46, + elevationLoss: -759.3199999999999, + }, + { + dist: 9045.7, + values: { dhm: 327.52 }, + x: 82543.16901350433, + y: 109766.31449378778, + id: '', + cumulativeElevation: -89.52000000000004, + elevationGain: 676.46, + elevationLoss: -765.98, + }, + { + dist: 9142.3, + values: { dhm: 320.17 }, + x: 82639.50675204695, + y: 109773.60992607416, + id: '', + cumulativeElevation: -96.87, + elevationGain: 676.46, + elevationLoss: -773.3299999999999, + }, + { + dist: 9238.9, + values: { dhm: 314.53 }, + x: 82735.84449058956, + y: 109780.90535836053, + id: '', + cumulativeElevation: -102.51000000000005, + elevationGain: 676.46, + elevationLoss: -778.97, + }, + { + dist: 9335.5, + values: { dhm: 282.94 }, + x: 82832.18222913217, + y: 109788.2007906469, + id: '', + cumulativeElevation: -134.10000000000002, + elevationGain: 676.46, + elevationLoss: -810.56, + }, + { + dist: 9432.1, + values: { dhm: 305.34 }, + x: 82928.51996767477, + y: 109795.49622293326, + id: '', + cumulativeElevation: -111.70000000000005, + elevationGain: 698.86, + elevationLoss: -810.56, + }, + { + dist: 9528.7, + values: { dhm: 304.22 }, + x: 83024.85770621739, + y: 109802.79165521964, + id: '', + cumulativeElevation: -112.82, + elevationGain: 698.86, + elevationLoss: -811.6799999999998, + }, + { + dist: 9625.3, + values: { dhm: 301.6 }, + x: 83121.19544476, + y: 109810.087087506, + id: '', + cumulativeElevation: -115.44, + elevationGain: 698.86, + elevationLoss: -814.2999999999998, + }, +] diff --git a/src/components/common/graph/d3-graph-elevation.fixtures.ts b/src/components/common/graph/d3-graph-elevation.fixtures.ts deleted file mode 100644 index 847fa1ba..00000000 --- a/src/components/common/graph/d3-graph-elevation.fixtures.ts +++ /dev/null @@ -1,1022 +0,0 @@ -export const dataset = [ - { - dist: 0, - values: { dhm: 320.81 }, - x: 72582.425981672, - y: 76416.368834504, - id: '', - cumulativeElevation: 0, - elevationGain: 0, - elevationLoss: 0, - }, - { - dist: 1, - values: { dhm: 320.8 }, - x: 72583.42599654055, - y: 76416.16175568622, - id: '', - cumulativeElevation: -0.009999999999990905, - elevationGain: 0, - elevationLoss: -0.009999999999990905, - }, - { - dist: 2, - values: { dhm: 320.79 }, - x: 72584.4260114091, - y: 76415.95467686845, - id: '', - cumulativeElevation: -0.01999999999998181, - elevationGain: 0, - elevationLoss: -0.01999999999998181, - }, - { - dist: 3.1, - values: { dhm: 320.79 }, - x: 72585.42602627765, - y: 76415.74759805067, - id: '', - cumulativeElevation: -0.01999999999998181, - elevationGain: 0, - elevationLoss: -0.01999999999998181, - }, - { - dist: 4.1, - values: { dhm: 320.76 }, - x: 72586.42604114619, - y: 76415.5405192329, - id: '', - cumulativeElevation: -0.05000000000001137, - elevationGain: 0, - elevationLoss: -0.05000000000001137, - }, - { - dist: 5.1, - values: { dhm: 320.77 }, - x: 72587.42605601474, - y: 76415.33344041512, - id: '', - cumulativeElevation: -0.040000000000020464, - elevationGain: 0.009999999999990905, - elevationLoss: -0.05000000000001137, - }, - { - dist: 6.1, - values: { dhm: 320.76 }, - x: 72588.42607088329, - y: 76415.12636159736, - id: '', - cumulativeElevation: -0.05000000000001137, - elevationGain: 0.009999999999990905, - elevationLoss: -0.060000000000002274, - }, - { - dist: 7.1, - values: { dhm: 320.75 }, - x: 72589.42608575184, - y: 76414.91928277958, - id: '', - cumulativeElevation: -0.060000000000002274, - elevationGain: 0.009999999999990905, - elevationLoss: -0.06999999999999318, - }, - { - dist: 8.2, - values: { dhm: 320.73 }, - x: 72590.42610062039, - y: 76414.71220396181, - id: '', - cumulativeElevation: -0.07999999999998408, - elevationGain: 0.009999999999990905, - elevationLoss: -0.08999999999997499, - }, - { - dist: 9.2, - values: { dhm: 320.67 }, - x: 72591.42611548894, - y: 76414.50512514403, - id: '', - cumulativeElevation: -0.13999999999998636, - elevationGain: 0.009999999999990905, - elevationLoss: -0.14999999999997726, - }, - { - dist: 10.2, - values: { dhm: 320.66 }, - x: 72592.42613035749, - y: 76414.29804632626, - id: '', - cumulativeElevation: -0.14999999999997726, - elevationGain: 0.009999999999990905, - elevationLoss: -0.15999999999996817, - }, - { - dist: 11.2, - values: { dhm: 320.66 }, - x: 72593.42614522604, - y: 76414.09096750848, - id: '', - cumulativeElevation: -0.14999999999997726, - elevationGain: 0.009999999999990905, - elevationLoss: -0.15999999999996817, - }, - { - dist: 12.3, - values: { dhm: 320.66 }, - x: 72594.42616009458, - y: 76413.8838886907, - id: '', - cumulativeElevation: -0.14999999999997726, - elevationGain: 0.009999999999990905, - elevationLoss: -0.15999999999996817, - }, - { - dist: 13.3, - values: { dhm: 320.67 }, - x: 72595.42617496313, - y: 76413.67680987294, - id: '', - cumulativeElevation: -0.13999999999998636, - elevationGain: 0.01999999999998181, - elevationLoss: -0.15999999999996817, - }, - { - dist: 14.3, - values: { dhm: 320.63 }, - x: 72596.42618983168, - y: 76413.46973105516, - id: '', - cumulativeElevation: -0.18000000000000682, - elevationGain: 0.01999999999998181, - elevationLoss: -0.19999999999998863, - }, - { - dist: 15.3, - values: { dhm: 320.67 }, - x: 72597.42620470023, - y: 76413.26265223739, - id: '', - cumulativeElevation: -0.13999999999998636, - elevationGain: 0.060000000000002274, - elevationLoss: -0.19999999999998863, - }, - { - dist: 16.3, - values: { dhm: 320.71 }, - x: 72598.42621956878, - y: 76413.05557341961, - id: '', - cumulativeElevation: -0.10000000000002274, - elevationGain: 0.0999999999999659, - elevationLoss: -0.19999999999998863, - }, - { - dist: 17.4, - values: { dhm: 320.68 }, - x: 72599.42623443733, - y: 76412.84849460184, - id: '', - cumulativeElevation: -0.12999999999999545, - elevationGain: 0.0999999999999659, - elevationLoss: -0.22999999999996135, - }, - { - dist: 18.4, - values: { dhm: 320.6 }, - x: 72600.42624930588, - y: 76412.64141578406, - id: '', - cumulativeElevation: -0.20999999999997954, - elevationGain: 0.0999999999999659, - elevationLoss: -0.30999999999994543, - }, - { - dist: 19.4, - values: { dhm: 320.5 }, - x: 72601.42626417443, - y: 76412.4343369663, - id: '', - cumulativeElevation: -0.3100000000000023, - elevationGain: 0.0999999999999659, - elevationLoss: -0.40999999999996817, - }, - { - dist: 20.4, - values: { dhm: 320.52 }, - x: 72602.42627904296, - y: 76412.22725814852, - id: '', - cumulativeElevation: -0.29000000000002046, - elevationGain: 0.1199999999999477, - elevationLoss: -0.40999999999996817, - }, - { - dist: 21.4, - values: { dhm: 320.54 }, - x: 72603.42629391151, - y: 76412.02017933074, - id: '', - cumulativeElevation: -0.2699999999999818, - elevationGain: 0.13999999999998636, - elevationLoss: -0.40999999999996817, - }, - { - dist: 22.5, - values: { dhm: 320.55 }, - x: 72604.42630878006, - y: 76411.81310051297, - id: '', - cumulativeElevation: -0.2599999999999909, - elevationGain: 0.14999999999997726, - elevationLoss: -0.40999999999996817, - }, - { - dist: 23.5, - values: { dhm: 320.55 }, - x: 72605.42632364861, - y: 76411.60602169519, - id: '', - cumulativeElevation: -0.2599999999999909, - elevationGain: 0.14999999999997726, - elevationLoss: -0.40999999999996817, - }, - { - dist: 24.5, - values: { dhm: 320.5 }, - x: 72606.42633851717, - y: 76411.39894287742, - id: '', - cumulativeElevation: -0.3100000000000023, - elevationGain: 0.14999999999997726, - elevationLoss: -0.45999999999997954, - }, - { - dist: 25.5, - values: { dhm: 320.51 }, - x: 72607.42635338572, - y: 76411.19186405964, - id: '', - cumulativeElevation: -0.30000000000001137, - elevationGain: 0.15999999999996817, - elevationLoss: -0.45999999999997954, - }, - { - dist: 26.6, - values: { dhm: 320.54 }, - x: 72608.42636825427, - y: 76410.98478524188, - id: '', - cumulativeElevation: -0.2699999999999818, - elevationGain: 0.18999999999999773, - elevationLoss: -0.45999999999997954, - }, - { - dist: 27.6, - values: { dhm: 320.53 }, - x: 72609.42638312282, - y: 76410.7777064241, - id: '', - cumulativeElevation: -0.28000000000002956, - elevationGain: 0.18999999999999773, - elevationLoss: -0.4700000000000273, - }, - { - dist: 28.6, - values: { dhm: 320.48 }, - x: 72610.42639799135, - y: 76410.57062760633, - id: '', - cumulativeElevation: -0.3299999999999841, - elevationGain: 0.18999999999999773, - elevationLoss: -0.5199999999999818, - }, - { - dist: 29.6, - values: { dhm: 320.41 }, - x: 72611.4264128599, - y: 76410.36354878855, - id: '', - cumulativeElevation: -0.39999999999997726, - elevationGain: 0.18999999999999773, - elevationLoss: -0.589999999999975, - }, - { - dist: 30.6, - values: { dhm: 320.39 }, - x: 72612.42642772845, - y: 76410.15646997078, - id: '', - cumulativeElevation: -0.4200000000000159, - elevationGain: 0.18999999999999773, - elevationLoss: -0.6100000000000136, - }, - { - dist: 31.7, - values: { dhm: 320.38 }, - x: 72613.426442597, - y: 76409.949391153, - id: '', - cumulativeElevation: -0.4300000000000068, - elevationGain: 0.18999999999999773, - elevationLoss: -0.6200000000000045, - }, - { - dist: 32.7, - values: { dhm: 320.38 }, - x: 72614.4466416126, - y: 76409.92614336428, - id: '', - cumulativeElevation: -0.4300000000000068, - elevationGain: 0.18999999999999773, - elevationLoss: -0.6200000000000045, - }, - { - dist: 33.7, - values: { dhm: 320.39 }, - x: 72615.46684062817, - y: 76409.90289557556, - id: '', - cumulativeElevation: -0.4200000000000159, - elevationGain: 0.19999999999998863, - elevationLoss: -0.6200000000000045, - }, - { - dist: 34.7, - values: { dhm: 320.36 }, - x: 72616.48703964376, - y: 76409.87964778685, - id: '', - cumulativeElevation: -0.44999999999998863, - elevationGain: 0.19999999999998863, - elevationLoss: -0.6499999999999773, - }, - { - dist: 35.7, - values: { dhm: 320.3 }, - x: 72617.50723865934, - y: 76409.85639999813, - id: '', - cumulativeElevation: -0.5099999999999909, - elevationGain: 0.19999999999998863, - elevationLoss: -0.7099999999999795, - }, - { - dist: 36.8, - values: { dhm: 320.25 }, - x: 72618.52743767493, - y: 76409.83315220941, - id: '', - cumulativeElevation: -0.5600000000000023, - elevationGain: 0.19999999999998863, - elevationLoss: -0.7599999999999909, - }, - { - dist: 37.8, - values: { dhm: 320.21 }, - x: 72619.5476366905, - y: 76409.8099044207, - id: '', - cumulativeElevation: -0.6000000000000227, - elevationGain: 0.19999999999998863, - elevationLoss: -0.8000000000000114, - }, - { - dist: 38.8, - values: { dhm: 320.17 }, - x: 72620.5678357061, - y: 76409.78665663199, - id: '', - cumulativeElevation: -0.6399999999999864, - elevationGain: 0.19999999999998863, - elevationLoss: -0.839999999999975, - }, - { - dist: 39.8, - values: { dhm: 320.1 }, - x: 72621.58803472169, - y: 76409.76340884327, - id: '', - cumulativeElevation: -0.7099999999999795, - elevationGain: 0.19999999999998863, - elevationLoss: -0.9099999999999682, - }, - { - dist: 40.8, - values: { dhm: 320.03 }, - x: 72622.60823373726, - y: 76409.74016105455, - id: '', - cumulativeElevation: -0.7800000000000296, - elevationGain: 0.19999999999998863, - elevationLoss: -0.9800000000000182, - }, - { - dist: 41.9, - values: { dhm: 319.98 }, - x: 72623.62843275286, - y: 76409.71691326583, - id: '', - cumulativeElevation: -0.8299999999999841, - elevationGain: 0.19999999999998863, - elevationLoss: -1.0299999999999727, - }, - { - dist: 42.9, - values: { dhm: 319.95 }, - x: 72624.64863176843, - y: 76409.69366547711, - id: '', - cumulativeElevation: -0.8600000000000136, - elevationGain: 0.19999999999998863, - elevationLoss: -1.0600000000000023, - }, - { - dist: 43.9, - values: { dhm: 319.94 }, - x: 72625.66883078402, - y: 76409.6704176884, - id: '', - cumulativeElevation: -0.8700000000000045, - elevationGain: 0.19999999999998863, - elevationLoss: -1.0699999999999932, - }, - { - dist: 44.9, - values: { dhm: 319.95 }, - x: 72626.6890297996, - y: 76409.64716989968, - id: '', - cumulativeElevation: -0.8600000000000136, - elevationGain: 0.20999999999997954, - elevationLoss: -1.0699999999999932, - }, - { - dist: 45.9, - values: { dhm: 319.96 }, - x: 72627.70922881519, - y: 76409.62392211096, - id: '', - cumulativeElevation: -0.8500000000000227, - elevationGain: 0.21999999999997044, - elevationLoss: -1.0699999999999932, - }, - { - dist: 47, - values: { dhm: 319.96 }, - x: 72628.72942783077, - y: 76409.60067432224, - id: '', - cumulativeElevation: -0.8500000000000227, - elevationGain: 0.21999999999997044, - elevationLoss: -1.0699999999999932, - }, - { - dist: 48, - values: { dhm: 319.98 }, - x: 72629.74962684636, - y: 76409.57742653353, - id: '', - cumulativeElevation: -0.8299999999999841, - elevationGain: 0.2400000000000091, - elevationLoss: -1.0699999999999932, - }, - { - dist: 49, - values: { dhm: 319.91 }, - x: 72630.76982586195, - y: 76409.55417874482, - id: '', - cumulativeElevation: -0.8999999999999773, - elevationGain: 0.2400000000000091, - elevationLoss: -1.1399999999999864, - }, - { - dist: 50, - values: { dhm: 319.76 }, - x: 72631.79002487753, - y: 76409.5309309561, - id: '', - cumulativeElevation: -1.0500000000000114, - elevationGain: 0.2400000000000091, - elevationLoss: -1.2900000000000205, - }, - { - dist: 51, - values: { dhm: 319.69 }, - x: 72632.81022389312, - y: 76409.50768316738, - id: '', - cumulativeElevation: -1.1200000000000045, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3600000000000136, - }, - { - dist: 52.1, - values: { dhm: 319.67 }, - x: 72633.8304229087, - y: 76409.48443537866, - id: '', - cumulativeElevation: -1.1399999999999864, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3799999999999955, - }, - { - dist: 53.1, - values: { dhm: 319.67 }, - x: 72634.85062192428, - y: 76409.46118758994, - id: '', - cumulativeElevation: -1.1399999999999864, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3799999999999955, - }, - { - dist: 54.1, - values: { dhm: 319.67 }, - x: 72635.87082093986, - y: 76409.43793980122, - id: '', - cumulativeElevation: -1.1399999999999864, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3799999999999955, - }, - { - dist: 55.1, - values: { dhm: 319.66 }, - x: 72636.89101995545, - y: 76409.4146920125, - id: '', - cumulativeElevation: -1.1499999999999773, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3899999999999864, - }, - { - dist: 56.1, - values: { dhm: 319.66 }, - x: 72637.91121897104, - y: 76409.39144422379, - id: '', - cumulativeElevation: -1.1499999999999773, - elevationGain: 0.2400000000000091, - elevationLoss: -1.3899999999999864, - }, - { - dist: 57.2, - values: { dhm: 319.71 }, - x: 72638.93141798662, - y: 76409.36819643507, - id: '', - cumulativeElevation: -1.1000000000000227, - elevationGain: 0.2899999999999636, - elevationLoss: -1.3899999999999864, - }, - { - dist: 58.2, - values: { dhm: 319.85 }, - x: 72639.95161700221, - y: 76409.34494864635, - id: '', - cumulativeElevation: -0.9599999999999795, - elevationGain: 0.4300000000000068, - elevationLoss: -1.3899999999999864, - }, - { - dist: 59.2, - values: { dhm: 320.05 }, - x: 72640.97181601779, - y: 76409.32170085765, - id: '', - cumulativeElevation: -0.7599999999999909, - elevationGain: 0.6299999999999955, - elevationLoss: -1.3899999999999864, - }, - { - dist: 60.2, - values: { dhm: 320.26 }, - x: 72641.99201503338, - y: 76409.29845306893, - id: '', - cumulativeElevation: -0.5500000000000114, - elevationGain: 0.839999999999975, - elevationLoss: -1.3899999999999864, - }, - { - dist: 61.3, - values: { dhm: 320.42 }, - x: 72643.01221404895, - y: 76409.27520528021, - id: '', - cumulativeElevation: -0.38999999999998636, - elevationGain: 1, - elevationLoss: -1.3899999999999864, - }, - { - dist: 62.3, - values: { dhm: 320.48 }, - x: 72644.03241306455, - y: 76409.25195749149, - id: '', - cumulativeElevation: -0.3299999999999841, - elevationGain: 1.0600000000000023, - elevationLoss: -1.3899999999999864, - }, - { - dist: 63.3, - values: { dhm: 320.54 }, - x: 72645.05261208014, - y: 76409.22870970277, - id: '', - cumulativeElevation: -0.2699999999999818, - elevationGain: 1.1200000000000045, - elevationLoss: -1.3899999999999864, - }, - { - dist: 64.3, - values: { dhm: 320.67 }, - x: 72646.07281109571, - y: 76409.20546191405, - id: '', - cumulativeElevation: -0.13999999999998636, - elevationGain: 1.25, - elevationLoss: -1.3899999999999864, - }, - { - dist: 65.3, - values: { dhm: 320.93 }, - x: 72647.0930101113, - y: 76409.18221412534, - id: '', - cumulativeElevation: 0.12000000000000455, - elevationGain: 1.509999999999991, - elevationLoss: -1.3899999999999864, - }, - { - dist: 66.4, - values: { dhm: 321.25 }, - x: 72648.11320912688, - y: 76409.15896633662, - id: '', - cumulativeElevation: 0.4399999999999977, - elevationGain: 1.829999999999984, - elevationLoss: -1.3899999999999864, - }, - { - dist: 67.4, - values: { dhm: 321.5 }, - x: 72649.13340814247, - y: 76409.1357185479, - id: '', - cumulativeElevation: 0.6899999999999977, - elevationGain: 2.079999999999984, - elevationLoss: -1.3899999999999864, - }, - { - dist: 68.4, - values: { dhm: 321.51 }, - x: 72650.15360715805, - y: 76409.11247075918, - id: '', - cumulativeElevation: 0.6999999999999886, - elevationGain: 2.089999999999975, - elevationLoss: -1.3899999999999864, - }, - { - dist: 69.4, - values: { dhm: 321.29 }, - x: 72651.17380617364, - y: 76409.08922297046, - id: '', - cumulativeElevation: 0.4800000000000182, - elevationGain: 2.089999999999975, - elevationLoss: -1.6099999999999568, - }, - { - dist: 70.4, - values: { dhm: 320.99 }, - x: 72652.19400518923, - y: 76409.06597518176, - id: '', - cumulativeElevation: 0.18000000000000682, - elevationGain: 2.089999999999975, - elevationLoss: -1.9099999999999682, - }, - { - dist: 71.5, - values: { dhm: 320.72 }, - x: 72653.2142042048, - y: 76409.04272739304, - id: '', - cumulativeElevation: -0.08999999999997499, - elevationGain: 2.089999999999975, - elevationLoss: -2.17999999999995, - }, - { - dist: 72.5, - values: { dhm: 320.5 }, - x: 72654.2344032204, - y: 76409.01947960432, - id: '', - cumulativeElevation: -0.3100000000000023, - elevationGain: 2.089999999999975, - elevationLoss: -2.3999999999999773, - }, - { - dist: 73.5, - values: { dhm: 320.39 }, - x: 72655.25460223597, - y: 76408.9962318156, - id: '', - cumulativeElevation: -0.4200000000000159, - elevationGain: 2.089999999999975, - elevationLoss: -2.509999999999991, - }, - { - dist: 74.5, - values: { dhm: 320.34 }, - x: 72656.27480125157, - y: 76408.97298402688, - id: '', - cumulativeElevation: -0.4700000000000273, - elevationGain: 2.089999999999975, - elevationLoss: -2.5600000000000023, - }, - { - dist: 75.5, - values: { dhm: 320.28 }, - x: 72657.29500026714, - y: 76408.94973623817, - id: '', - cumulativeElevation: -0.5300000000000296, - elevationGain: 2.089999999999975, - elevationLoss: -2.6200000000000045, - }, - { - dist: 76.6, - values: { dhm: 320.14 }, - x: 72658.31519928273, - y: 76408.92648844945, - id: '', - cumulativeElevation: -0.6700000000000159, - elevationGain: 2.089999999999975, - elevationLoss: -2.759999999999991, - }, - { - dist: 77.6, - values: { dhm: 319.92 }, - x: 72659.33539829831, - y: 76408.90324066073, - id: '', - cumulativeElevation: -0.8899999999999864, - elevationGain: 2.089999999999975, - elevationLoss: -2.9799999999999613, - }, - { - dist: 78.6, - values: { dhm: 319.73 }, - x: 72660.3555973139, - y: 76408.87999287201, - id: '', - cumulativeElevation: -1.079999999999984, - elevationGain: 2.089999999999975, - elevationLoss: -3.169999999999959, - }, - { - dist: 79.6, - values: { dhm: 319.62 }, - x: 72661.37579632949, - y: 76408.85674508329, - id: '', - cumulativeElevation: -1.1899999999999977, - elevationGain: 2.089999999999975, - elevationLoss: -3.2799999999999727, - }, - { - dist: 80.6, - values: { dhm: 319.55 }, - x: 72662.39599534507, - y: 76408.83349729459, - id: '', - cumulativeElevation: -1.259999999999991, - elevationGain: 2.089999999999975, - elevationLoss: -3.349999999999966, - }, - { - dist: 81.7, - values: { dhm: 319.52 }, - x: 72663.41619436066, - y: 76408.81024950587, - id: '', - cumulativeElevation: -1.2900000000000205, - elevationGain: 2.089999999999975, - elevationLoss: -3.3799999999999955, - }, - { - dist: 82.7, - values: { dhm: 319.5 }, - x: 72664.43639337624, - y: 76408.78700171715, - id: '', - cumulativeElevation: -1.3100000000000023, - elevationGain: 2.089999999999975, - elevationLoss: -3.3999999999999773, - }, - { - dist: 83.7, - values: { dhm: 319.49 }, - x: 72665.45659239183, - y: 76408.76375392843, - id: '', - cumulativeElevation: -1.3199999999999932, - elevationGain: 2.089999999999975, - elevationLoss: -3.409999999999968, - }, - { - dist: 84.7, - values: { dhm: 319.49 }, - x: 72666.4767914074, - y: 76408.74050613971, - id: '', - cumulativeElevation: -1.3199999999999932, - elevationGain: 2.089999999999975, - elevationLoss: -3.409999999999968, - }, - { - dist: 85.7, - values: { dhm: 319.49 }, - x: 72667.496990423, - y: 76408.717258351, - id: '', - cumulativeElevation: -1.3199999999999932, - elevationGain: 2.089999999999975, - elevationLoss: -3.409999999999968, - }, - { - dist: 86.8, - values: { dhm: 319.48 }, - x: 72668.51159593323, - y: 76408.69316674188, - id: '', - cumulativeElevation: -1.329999999999984, - elevationGain: 2.089999999999975, - elevationLoss: -3.419999999999959, - }, - { - dist: 87.8, - values: { dhm: 319.49 }, - x: 72669.52620144347, - y: 76408.66907513276, - id: '', - cumulativeElevation: -1.3199999999999932, - elevationGain: 2.099999999999966, - elevationLoss: -3.419999999999959, - }, - { - dist: 88.8, - values: { dhm: 319.5 }, - x: 72670.54080695371, - y: 76408.64498352364, - id: '', - cumulativeElevation: -1.3100000000000023, - elevationGain: 2.109999999999957, - elevationLoss: -3.419999999999959, - }, - { - dist: 89.8, - values: { dhm: 319.51 }, - x: 72671.55541246395, - y: 76408.62089191453, - id: '', - cumulativeElevation: -1.3000000000000114, - elevationGain: 2.1199999999999477, - elevationLoss: -3.419999999999959, - }, - { - dist: 90.8, - values: { dhm: 319.5 }, - x: 72672.57001797417, - y: 76408.59680030541, - id: '', - cumulativeElevation: -1.3100000000000023, - elevationGain: 2.1199999999999477, - elevationLoss: -3.42999999999995, - }, - { - dist: 91.8, - values: { dhm: 319.5 }, - x: 72673.5846234844, - y: 76408.57270869629, - id: '', - cumulativeElevation: -1.3100000000000023, - elevationGain: 2.1199999999999477, - elevationLoss: -3.42999999999995, - }, - { - dist: 92.8, - values: { dhm: 319.43 }, - x: 72674.59922899464, - y: 76408.54861708717, - id: '', - cumulativeElevation: -1.3799999999999955, - elevationGain: 2.1199999999999477, - elevationLoss: -3.499999999999943, - }, - { - dist: 93.9, - values: { dhm: 319.45 }, - x: 72675.61383450488, - y: 76408.52452547806, - id: '', - cumulativeElevation: -1.3600000000000136, - elevationGain: 2.1399999999999295, - elevationLoss: -3.499999999999943, - }, - { - dist: 94.9, - values: { dhm: 319.49 }, - x: 72676.62844001512, - y: 76408.50043386893, - id: '', - cumulativeElevation: -1.3199999999999932, - elevationGain: 2.17999999999995, - elevationLoss: -3.499999999999943, - }, - { - dist: 95.9, - values: { dhm: 319.53 }, - x: 72677.64304552536, - y: 76408.47634225982, - id: '', - cumulativeElevation: -1.2800000000000296, - elevationGain: 2.2199999999999136, - elevationLoss: -3.499999999999943, - }, - { - dist: 96.9, - values: { dhm: 319.54 }, - x: 72678.6576510356, - y: 76408.4522506507, - id: '', - cumulativeElevation: -1.2699999999999818, - elevationGain: 2.2299999999999613, - elevationLoss: -3.499999999999943, - }, - { - dist: 97.9, - values: { dhm: 319.54 }, - x: 72679.67225654583, - y: 76408.42815904158, - id: '', - cumulativeElevation: -1.2699999999999818, - elevationGain: 2.2299999999999613, - elevationLoss: -3.499999999999943, - }, - { - dist: 98.9, - values: { dhm: 319.52 }, - x: 72680.68686205606, - y: 76408.40406743246, - id: '', - cumulativeElevation: -1.2900000000000205, - elevationGain: 2.2299999999999613, - elevationLoss: -3.519999999999982, - }, - { - dist: 100, - values: { dhm: 319.51 }, - x: 72681.7014675663, - y: 76408.37997582335, - id: '', - cumulativeElevation: -1.3000000000000114, - elevationGain: 2.2299999999999613, - elevationLoss: -3.5299999999999727, - }, - { - dist: 101, - values: { dhm: 319.5 }, - x: 72682.71607307653, - y: 76408.35588421424, - id: '', - cumulativeElevation: -1.3100000000000023, - elevationGain: 2.2299999999999613, - elevationLoss: -3.5399999999999636, - }, - { - dist: 102, - values: { dhm: 319.51 }, - x: 72683.73067858677, - y: 76408.33179260511, - id: '', - cumulativeElevation: -1.3000000000000114, - elevationGain: 2.2399999999999523, - elevationLoss: -3.5399999999999636, - }, - { - dist: 103, - values: { dhm: 319.52 }, - x: 72684.745284097, - y: 76408.307700996, - id: '', - cumulativeElevation: -1.2900000000000205, - elevationGain: 2.249999999999943, - elevationLoss: -3.5399999999999636, - }, -] diff --git a/src/components/common/graph/d3-graph-elevation.spec.ts b/src/components/common/graph/d3-graph-elevation.spec.ts index 5e5f64bf..a539a6c8 100644 --- a/src/components/common/graph/d3-graph-elevation.spec.ts +++ b/src/components/common/graph/d3-graph-elevation.spec.ts @@ -9,6 +9,10 @@ describe('D3GraphElevation', () => { beforeEach(() => { wrapper = mount(D3GraphElevation, { props: { + labelXFormatter: () => '', + labelYFormatter: () => '', + xFormatter: (val: number) => val + '', + yFormatter: (val: number) => val + '', showTooltip: true, }, }) diff --git a/src/components/common/graph/d3-graph-elevation.vue b/src/components/common/graph/d3-graph-elevation.vue index b10c3c42..26699d3b 100644 --- a/src/components/common/graph/d3-graph-elevation.vue +++ b/src/components/common/graph/d3-graph-elevation.vue @@ -7,7 +7,7 @@ import { debounce } from '@/services/utils' import D3GraphElevation from './d3-graph-elevation' import { Elevations, Profile, ProfileOptions } from './d3-graph-elevation.d' import { ProfileData } from './elevation-profile' -// import { dataset } from './d3-graph-elevation.fixtures' // Use these fixtures instead of api if needed (for dev debug only) +// import { dataset } from '@/__fixtures__/d3-graph-elevation.fixtures' // Use these fixtures instead of api if needed (for dev debug only) const emit = defineEmits<{ (e: 'hover:profile', point: any, dist: number, elevations: Elevations): void diff --git a/src/components/common/graph/elevation-profile.spec.ts b/src/components/common/graph/elevation-profile.spec.ts new file mode 100644 index 00000000..52b06ff8 --- /dev/null +++ b/src/components/common/graph/elevation-profile.spec.ts @@ -0,0 +1,42 @@ +import { mount } from '@vue/test-utils' +import { describe, it, expect } from 'vitest' +import ElevationProfile from './elevation-profile.vue' +import D3GraphElevation from './d3-graph-elevation.vue' +import { ProfileData } from './elevation-profile' + +describe('ElevationProfile', () => { + it('Display an image when profileData is empty', () => { + const wrapper = mount(ElevationProfile, { + props: { + profileData: undefined, + }, + }) + + expect(wrapper.find('img').exists()).toBe(true) + expect(wrapper.findComponent(D3GraphElevation).exists()).toBe(false) + }) + + it('Display the graph when profileData has values', () => { + const profileData = [ + { + cumulativeElevation: 42, + elevationGain: 58, + elevationLoss: 2, + }, + { + cumulativeElevation: 250, + elevationGain: 22, + elevationLoss: 42, + }, + ] + const wrapper = mount(ElevationProfile, { + props: { + profileData, + highlightDistance: 10, + }, + }) + + expect(wrapper.findComponent(D3GraphElevation).exists()).toBe(true) + expect(wrapper.find('img').exists()).toBe(false) + }) +}) diff --git a/src/components/draw/feature-menu-popup.vue b/src/components/draw/feature-menu-popup.vue index 39c411d1..6845e4e1 100644 --- a/src/components/draw/feature-menu-popup.vue +++ b/src/components/draw/feature-menu-popup.vue @@ -11,13 +11,13 @@ import { DrawnFeature } from '@/services/draw/drawn-feature' import { exportFeatureService, TFeatExport, - type exportFormat, + type TExportFormat, } from '@/services/export-feature/export-feature.service' const { t } = useTranslation() const feature: DrawnFeature = inject('feature')! -function download(format: exportFormat) { +function download(format: TExportFormat) { exportFeatureService.export( feature.map, format, diff --git a/src/components/feature-elevation-profile/feature-elevation-profil.spec.ts b/src/components/feature-elevation-profile/feature-elevation-profil.spec.ts new file mode 100644 index 00000000..6aa63ac9 --- /dev/null +++ b/src/components/feature-elevation-profile/feature-elevation-profil.spec.ts @@ -0,0 +1,144 @@ +import { nextTick } from 'vue' +import { mount, shallowMount } from '@vue/test-utils' +import { GlobalMountOptions } from '@vue/test-utils/dist/types' +import { createTestingPinia } from '@pinia/testing' +import { describe, it, expect, vi } from 'vitest' +import { Coordinate } from 'ol/coordinate' + +import { dataset as datasetFixtures } from '@/__fixtures__/d3-graph-elevation.fixtures' +import formatMeasureDirective from '@/directives/format-measure.directive' +import { DrawnFeature } from '@/services/draw/drawn-feature' +import FeatureElevationProfile from './feature-elevation-profile.vue' +import { exportFeatureService } from '@/services/export-feature/export-feature.service' +import { useProfilePositionStore } from '@/stores/profile-position.store' +import ElevationProfile from '../common/graph/elevation-profile.vue' + +const global: GlobalMountOptions | undefined = { + plugins: [formatMeasureDirective], +} + +const mockedFeatureWithData = ({ + getProfile: vi.fn(() => Promise.resolve(datasetFixtures)), + profileData: undefined, + map: { getView: () => ({ getProjection: () => 'EPSG:4326' }) }, + label: 'Feature Label with data', +}) + +const mockedFeatureNoData = ({ + getProfile: vi.fn(() => new Promise(() => undefined)), + profileData: undefined, + map: {}, + label: 'Feature Label with NO data', +}) + +vi.mock('ol/proj', () => ({ + transform: (coords: Coordinate) => coords, +})) + +vi.mock('@/services/export-feature/export-feature.service', () => ({ + exportFeatureService: { + export: vi.fn(), + }, +})) + +vi.mock('@/composables/map/map.composable', () => ({ + default: () => ({ + getOlMap: () => ({ + addLayer: vi.fn(), + addFeatureLayer: vi.fn(), + getView: () => ({ getProjection: vi.fn() }), + }), + }), + PROJECTION_LUX: 'EPSG:2169', +})) + +vi.mock('@/composables/map/profile-position.composable', () => ({ + default: () => ({ + constructProfileLine: vi.fn(), + profileData: { value: undefined }, + highlightDistance: { value: undefined }, + }), +})) + +describe('FeatureElevationProfile', () => { + createTestingPinia({ + createSpy: vi.fn, + stubActions: false, + initialState: { + 'profile-position': { + x: 1, + y: 2, + }, + }, + }) + + it('Display elevation ,cumulation gain and loss according to profileData', async () => { + const wrapper = shallowMount(FeatureElevationProfile, { + props: { feature: mockedFeatureWithData }, + global, + }) + + await nextTick() // wait for execution of `onMounted` + await nextTick() + + expect(wrapper.text()).toContain('Δ+699') + expect(wrapper.text()).toContain('Δ-814') + expect(wrapper.text()).toContain('-115') + }) + + it('Display a waiting message when profileData is still loading', async () => { + const wrapper = mount(FeatureElevationProfile, { + props: { feature: mockedFeatureNoData }, + global, + }) + + expect(wrapper.text()).toContain('Please wait, the profile is loading.') + }) + + it('Does not display a close button if there is no listerner for "onClose"', () => { + const wrapper = mount(FeatureElevationProfile, { + global, + }) + + expect(wrapper.find('[aria-label="Close"]').exists()).toBe(false) + }) + + it('Display a close button if there is a listerner for "onClose"', () => { + const wrapper = mount(FeatureElevationProfile, { + props: { + onClose: () => alert('My listener on close'), + feature: mockedFeatureNoData, + }, + global, + }) + + expect(wrapper.find('[aria-label="Close"]').exists()).toBe(true) + }) + + it("Call 'exportFeatureService.export' when on click export csv button", async () => { + const wrapper = shallowMount(FeatureElevationProfile, { + props: { feature: mockedFeatureWithData }, + global, + }) + + await nextTick() + await wrapper.find('[data-cy="featItemProfileCSV"]').trigger('click') + + expect(exportFeatureService.export).toHaveBeenCalled() + }) + + it("Update 'profilePositionStore' when hovering the graph", async () => { + const profilePositionStore = useProfilePositionStore() + const wrapper = mount(FeatureElevationProfile, { + props: { feature: mockedFeatureWithData }, + global, + }) + + await nextTick() + + const elevationProfile = wrapper.findComponent(ElevationProfile) + elevationProfile.vm.$emit('hover:profile', { x: 10, y: 20 }) + + expect(profilePositionStore.setPosition).toHaveBeenCalledWith(10, 20) + }) +}) diff --git a/src/directives/format-measure.directive.ts b/src/directives/format-measure.directive.ts index e69c2da2..3fa1b69a 100644 --- a/src/directives/format-measure.directive.ts +++ b/src/directives/format-measure.directive.ts @@ -4,6 +4,28 @@ import { TFormatMeasureType, } from '@/services/common/formatting.utils' +/** + * Directive for formating to measures of type "elevation", "length", or "area". + * + * Examples of usages: + * - With elevationGain = 200: `{{ elevationGain }}` => 200 + * - With mCounter = 5600987.462 `{{ mCounter }}` => 5600.98km + * - With lengthValue = 42.6598742 `{{ lengthValue }}` => 42.6598m + * + * NB. for unit testings you may encounter a warning saying directive is missing, to fix this, + * this directive must be added to Vue instance when testing: import directing in test file and then add the directive to global plugin + * when mounting/shallowmounting component. + * + * ``` + * import formatMeasureDirective from '@/directives/format-measure.directive' + * const wrapper = mount(Mycomponent, { + * props: { ... }, + * global: { + * plugins: [ formatMeasureDirective ] // <= add the directive here! + * } + * }) + * ``` + */ export default { install(app: App) { app.directive('format-measure', format) diff --git a/src/services/common/formatting.utils.spec.ts b/src/services/common/formatting.utils.spec.ts index 0f8164fc..74fc8e50 100644 --- a/src/services/common/formatting.utils.spec.ts +++ b/src/services/common/formatting.utils.spec.ts @@ -1,4 +1,10 @@ -import { formatDate } from './formatting.utils' +import { + formatArea, + formatDate, + formatElevation, + formatLength, + formatMeasure, +} from './formatting.utils' describe('Formatting utils', () => { describe('#formatDate', () => { @@ -11,4 +17,121 @@ describe('Formatting utils', () => { expect(date).toEqual('6/8/2016') }) }) + + describe('#formatMeasure', () => { + it('formats value as a length (m) by default with 2 digits', () => { + const val = formatMeasure(42.5) + expect(val).toEqual('42.50 m') + }) + + it('formats value as a length (given in m) n km', () => { + const val = formatMeasure(42000) + expect(val).toEqual('42.00 km') + }) + + it('formats value as a length with n given digits', () => { + const val = formatMeasure(42000.5698723, 4) + expect(val).toEqual('42.0006 km') + }) + + it('returns empty string if given value is invalid number', () => { + const val = formatMeasure(('test'), 4) + expect(val).toEqual('') + }) + + it('formats value as elevation', () => { + const val = formatMeasure(110, undefined, 'elevation') + expect(val).toEqual('110 m') + }) + + it('formats value as elevation always in meters', () => { + const val = formatMeasure(11000000, undefined, 'elevation') + expect(val).toEqual('11000000 m') + }) + + it('formats value as elevation with given digits', () => { + const val = formatMeasure(11000000.56, 2, 'elevation') + expect(val).toEqual('11000000.56 m') + }) + + it('returns original value if given value is invalid number', () => { + const val = formatMeasure( + ('wrong elevation'), + 4, + 'elevation' + ) + expect(val).toEqual('wrong elevation') + }) + }) + + describe('#formatElevation', () => { + it('formats value as a elevation (m) by default with no digits', () => { + const val = formatElevation(42.5) + expect(val).toEqual('43 m') + }) + + it('formats value as a elevation (m) with given digits', () => { + const val = formatElevation(42.5, 2) + expect(val).toEqual('42.50 m') + }) + + it('returns original value if given value is invalid number', () => { + const val = formatElevation(('wrong elevation'), 2) + expect(val).toEqual('wrong elevation') + }) + }) + + describe('#formatLength', () => { + it('formats value as a distance by default with 2 digits', () => { + const val = formatLength(42.5) + expect(val).toEqual('42.50 m') + }) + + it('formats value as a distance with no digit', () => { + const val = formatLength(42.5, 0) + expect(val).toEqual('43 m') + }) + + it('formats value as a distance in m', () => { + const val = formatLength(6, 0) + expect(val).toEqual('6 m') + }) + + it('formats value as a distance in km', () => { + const val = formatLength(6789456132.35, 5) + expect(val).toEqual('6789456.13235 km') + }) + + it('returns empty string if given distance is not a valid number', () => { + const val = formatLength(('wrong dist')) + expect(val).toEqual('') + }) + }) + + describe('#formatArea', () => { + it('formats value as an area by default with 2 digits', () => { + const val = formatArea(12) + expect(val).toEqual('12.00 m²') + }) + + it('formats value as an area by default with no digit', () => { + const val = formatArea(12.5, 0) + expect(val).toEqual('13 m²') + }) + + it('formats value as an area in m²', () => { + const val = formatArea(6, 0) + expect(val).toEqual('6 m²') + }) + + it('formats value as an area in km²', () => { + const val = formatArea(6789456132.35, 5) + expect(val).toEqual('6789.45613 km²') + }) + + it('returns empty string if given area is not a valid number', () => { + const val = formatArea(('wrong area')) + expect(val).toEqual('') + }) + }) }) diff --git a/src/services/common/formatting.utils.ts b/src/services/common/formatting.utils.ts index ea54b7a2..6ae0e246 100644 --- a/src/services/common/formatting.utils.ts +++ b/src/services/common/formatting.utils.ts @@ -13,6 +13,14 @@ export function formatDate(dateString: string, language: string = 'fr-FR') { return new Intl.DateTimeFormat(language).format(date) } +/** + * Format a measure value, it can be formatted to "elevation" (always in m), + * length (in m and km if up to 1000) or area (in m² or km² if up to 1000000) + * @param value The value to format + * @param digits The digits to fixed + * @param type The formatter, can be: "elevation" | "length" | "area" + * @returns The formatted value, or the original value if invalid number + */ export function formatMeasure( value: number | null, digits?: number, @@ -33,14 +41,26 @@ export function formatMeasure( } } +/** + * Format a value in meters (no km), 0 digit by default + * @param value The value (in m) to format + * @param digits The digits to fixed + * @returns The formatted value, or the original value if invalid number + */ export function formatElevation(value: number | string, digits = 0): string { return ( (isNaN(+value) ? value : `${(value).toFixed(digits)} m`) ) } +/** + * Format a value in meters (or km if up to 1000), 2 digits by default + * @param value The value (in m) to format + * @param digits The digits to fixed + * @returns The formatted value, or the original value if invalid number + */ export function formatLength(value: number, digits = 2): string { - //null covers API errors or unavailable data (eg. elevation) + // null covers API errors or unavailable data (eg. elevation) if (value === null) { return i18next.t('N/A', { ns: 'client' }) } else if (value < 1000) { @@ -52,6 +72,12 @@ export function formatLength(value: number, digits = 2): string { } } +/** + * Format a value in meters² (or km² if up to 1000000), 2 digits by default + * @param value The value (in m²) to format + * @param digits The digits to fixed + * @returns The formatted value, or the original value if invalid number + */ export function formatArea(value: number, digits = 2): string { if (value === null) { return i18next.t('N/A', { ns: 'client' }) diff --git a/src/services/draw/drawn-feature.spec.ts b/src/services/draw/drawn-feature.spec.ts index 851ba937..3150c6bf 100644 --- a/src/services/draw/drawn-feature.spec.ts +++ b/src/services/draw/drawn-feature.spec.ts @@ -1,11 +1,34 @@ import { Map, View } from 'ol' import { Extent } from 'ol/extent' -import { Geometry } from 'ol/geom' +import { Geometry, LineString, Point } from 'ol/geom' -import { DrawnFeature } from './drawn-feature' import useMap from '@/composables/map/map.composable' +import * as ApiProfileService from '@/services/api/api-profile.service' +import { DrawnFeature } from './drawn-feature' const mockViewSize = [99, 100] +const profileDataFixtures = { + profile: [ + { + dist: 0, + values: { dhm: 417.04 }, + x: 73679.482601148, + y: 110624.051484868, + }, + { + dist: 95.8, + values: { dhm: 447.74 }, + x: 73771.64510032868, + y: 110597.7924035457, + }, + { + dist: 191.7, + values: { dhm: 464.15 }, + x: 73863.80759950935, + y: 110571.53332222339, + }, + ], +} vi.mock('@/composables/map/map.composable', () => ({ default: () => ({ @@ -14,6 +37,12 @@ vi.mock('@/composables/map/map.composable', () => ({ getView: vi.fn(() => {}), })), }), + PROJECTION_LUX: 'EPSG:2169', + PROJECTION_WEBMERCATOR: 'EPSG:3857', +})) + +vi.mock('@/services/api/api-profile.service', () => ({ + getProfileJson: vi.fn(() => profileDataFixtures), })) describe('DrawnFeature', () => { @@ -43,4 +72,68 @@ describe('DrawnFeature', () => { size: mockViewSize, }) }) + + describe('#getProfile', () => { + beforeEach(() => { + vi.spyOn(ApiProfileService, 'getProfileJson').mockReturnValue( + Promise.resolve(profileDataFixtures) + ) + }) + + describe('When feature is of type LineString', () => { + it('should call api to get profileData and calculate cumulative elevation gain/loss', async () => { + const feat = new DrawnFeature() + feat.setGeometry( + new LineString([ + [0, 0], + [2, 2], + ]) + ) + const profile = await feat.getProfile() + const profileDataFixturesExpected = [ + { + dist: 0, + values: { dhm: 417.04 }, + x: 73679.482601148, + y: 110624.051484868, + cumulativeElevation: 0, + elevationGain: 0, + elevationLoss: 0, + }, + { + dist: 95.8, + values: { dhm: 447.74 }, + x: 73771.64510032868, + y: 110597.7924035457, + cumulativeElevation: 30.69999999999999, + elevationGain: 30.69999999999999, + elevationLoss: 0, + }, + { + dist: 191.7, + values: { dhm: 464.15 }, + x: 73863.80759950935, + y: 110571.53332222339, + cumulativeElevation: 47.10999999999996, + elevationGain: 47.10999999999996, + elevationLoss: 0, + }, + ] + + expect(ApiProfileService.getProfileJson).toHaveBeenCalledOnce() + expect(profile).toStrictEqual(profileDataFixturesExpected) + }) + }) + + describe('When feature is NOT a LineString', () => { + it('should not call the profileData api', async () => { + const feat = new DrawnFeature() + feat.setGeometry(new Point([0, 0])) + const profile = await feat.getProfile() + + expect(ApiProfileService.getProfileJson).not.toHaveBeenCalledOnce() + expect(profile).toStrictEqual(undefined) + }) + }) + }) }) diff --git a/src/services/export-feature/export-feature-profile-csv.spec.ts b/src/services/export-feature/export-feature-profile-csv.spec.ts new file mode 100644 index 00000000..dec4c844 --- /dev/null +++ b/src/services/export-feature/export-feature-profile-csv.spec.ts @@ -0,0 +1,63 @@ +import { describe, it, expect, vi } from 'vitest' +import { Map } from 'ol' +import { ExportFeatureProfileCsv } from './export-feature-profile-csv' +import { DrawnFeature } from '@/services/draw/drawn-feature' + +vi.mock('ol/proj', () => ({ + toLonLat: vi.fn(coords => coords.map((c: number) => c + 100)), +})) + +vi.mock('@/services/utils', () => ({ + downloadFile: vi.fn(), + sanitizeFilename: vi.fn(), +})) + +const mockMap = ({ + getView: () => ({ + getProjection: () => 'EPSG:3857', + }), +}) +const exporter = new ExportFeatureProfileCsv(mockMap) +const mockProfileData = [ + { dist: 0, values: { dhm: 100 }, x: 1000, y: 2000 }, + { dist: 10, values: { dhm: 150 }, x: 1500, y: 2500 }, +] +const mockFeatureWithData = ({ + getProfile: vi.fn(() => Promise.resolve(mockProfileData)), +}) +const expectedCsvContent = + 'dist,MNT,y,x,lon,lat\n0,100,1000,2000,1100,2100\n10,150,1500,2500,1600,2600\n' + +describe('ExportFeatureProfileCsv', () => { + describe('#export', () => { + it('Exports a profile into a CSV file', async () => { + const downloadSpy = vi.spyOn(exporter as any, 'download') + + await exporter.export(mockFeatureWithData, 'test-profile') + + expect(downloadSpy).toHaveBeenCalledWith( + 'test-profile', + expectedCsvContent, + 'csv', + 'application/csv' + ) + }) + }) + + describe('#generateContent', () => { + it('Generates content correctly', async () => { + const content = await exporter.generateContent(mockFeatureWithData) + + expect(content).toBe(expectedCsvContent) + }) + + it('Generates empty content if profileData invalid', async () => { + const mockFeatureNoData = ({ + getProfile: () => Promise.resolve(null), + }) + const content = await exporter.generateContent(mockFeatureNoData) + + expect(content).toBe('') + }) + }) +}) diff --git a/src/services/export-feature/export-feature.service.ts b/src/services/export-feature/export-feature.service.ts index 86d9d362..de5af197 100644 --- a/src/services/export-feature/export-feature.service.ts +++ b/src/services/export-feature/export-feature.service.ts @@ -6,13 +6,13 @@ import { ExportFeatureKml } from './export-feature-kml' import { ExportFeatureShapefile } from './export-feature-shapefile' import { ExportFeatureProfileCsv } from './export-feature-profile-csv' -export type exportFormat = 'kml' | 'gpx' | 'shapefile' | 'csv' +export type TExportFormat = 'kml' | 'gpx' | 'shapefile' | 'csv' export type TFeatExport = Feature & Feature[] export class ExportFeatureService { export( map: Map, - format: exportFormat, + format: TExportFormat, features: TFeatExport, fileName: string, isTrack = false diff --git a/src/services/export-feature/export-feature.spec.ts b/src/services/export-feature/export-feature.spec.ts new file mode 100644 index 00000000..b59da887 --- /dev/null +++ b/src/services/export-feature/export-feature.spec.ts @@ -0,0 +1,115 @@ +import { Feature, Map } from 'ol' +import { + Geometry, + GeometryCollection, + MultiLineString, + Point, + Circle, + LineString, +} from 'ol/geom' + +import { PROJECTION_WGS84 } from '@/composables/map/map.composable' +import { DrawnFeature } from '@/services/draw/drawn-feature' +import { convertCircleFeatureToPolygon } from '@/composables/draw/draw-utils' +import { ExportFeature } from './export-feature' + +vi.mock('@/composables/draw/draw-utils', () => ({ + convertCircleFeatureToPolygon: vi.fn(), +})) + +vi.mock('@/services/utils', () => ({ + downloadFile: vi.fn(), + sanitizeFilename: vi.fn((filename: string) => filename), +})) + +describe('ExportFeature', () => { + let exportFeature: ExportFeature> + const mapMock = { + getView: vi.fn(() => ({ + getProjection: vi.fn(() => mockProjection), + })), + } as unknown as Map + const mockProjection = { + getCode: vi.fn().mockReturnValue('EPSG:3857'), + } + + beforeEach(() => { + exportFeature = new (class extends ExportFeature> { + export() {} + generateContent() {} + })(mapMock) + }) + + it('should initialize encodeOptions with correct projections', () => { + expect(exportFeature.encodeOptions.dataProjection).toBe(PROJECTION_WGS84) + expect(exportFeature.encodeOptions.featureProjection).toBe(mockProjection) + }) + + it('should explode features with GeometryCollection', () => { + const geom1 = new Point([0, 0]) + const geom2 = new Point([1, 1]) + const geometryCollection = new GeometryCollection([geom1, geom2]) + + const feature = new Feature(geometryCollection) + const exploded = exportFeature.exploseFeatures(feature) + + expect(exploded.length).toBe(2) + expect(exploded[0].getGeometry()).toEqual(geom1) + expect(exploded[1].getGeometry()).toEqual(geom2) + }) + + it('should explode features with MultiLineString', () => { + const line1 = new LineString([ + [0, 0], + [1, 1], + ]) + const line2 = new LineString([ + [78.65, -32.65], + [-98.65, 12.65], + ]) + const multiLineString = new MultiLineString([ + line1.getCoordinates(), + line2.getCoordinates(), + ]) + + const feature = new Feature(multiLineString) + const exploded = exportFeature.exploseFeatures(feature) + + expect(exploded.length).toBe(2) + expect((exploded[0].getGeometry())?.getCoordinates()).toEqual( + line1.getCoordinates() + ) + expect((exploded[1].getGeometry())?.getCoordinates()).toEqual( + line2.getCoordinates() + ) + }) + + it('should convert Circle to Polygon when exploding features', () => { + const circle = new Circle([0, 0], 5) + const feature = new Feature(circle) + const polygonFeatureMock = new Feature() + + ;(convertCircleFeatureToPolygon).mockReturnValue(polygonFeatureMock) + + const exploded = exportFeature.exploseFeatures(feature) + + expect(convertCircleFeatureToPolygon).toHaveBeenCalledWith( + expect.any(DrawnFeature) + ) + expect(exploded[0]).toBe(polygonFeatureMock) + }) + + it('should clone features with new geometry', () => { + const originalGeometry = new Point([0, 0]) + const newGeometry = new Point([1, 1]) + const feature = new Feature(originalGeometry) + + const clonedFeature = exportFeature.cloneFeatureWithGeom( + feature, + newGeometry + ) + + expect(clonedFeature).not.toBe(feature) + expect(clonedFeature.getGeometry()).toBe(newGeometry) + }) +}) diff --git a/src/services/ol-layer/ol-layer-feature-position.helper.spec.ts b/src/services/ol-layer/ol-layer-feature-position.helper.spec.ts new file mode 100644 index 00000000..3db13ed8 --- /dev/null +++ b/src/services/ol-layer/ol-layer-feature-position.helper.spec.ts @@ -0,0 +1,47 @@ +import { Point } from 'ol/geom' +import Feature from 'ol/Feature' +import VectorSource from 'ol/source/Vector' +import { Style } from 'ol/style' + +import { PositionVectorLayer } from './ol-layer-feature-position.helper' + +vi.mock('./styles.helper', () => ({ + getStyleFeaturePosition: vi.fn(() => new Style()), +})) + +describe('PositionVectorLayer', () => { + const layer = new PositionVectorLayer({}) + layer.createGeomarker() + + it('should initialize with a geoMarker and a VectorSource', () => { + const source = layer.getSource() + + expect(source).toBeInstanceOf(VectorSource) + expect(source?.getFeatures().length).toBe(1) + expect(layer.geoMarker).toBeInstanceOf(Feature) + expect(layer.geoMarker?.getGeometry()).toBeInstanceOf(Point) + }) + + it('should move the geoMarker to given coordinates', () => { + layer.moveGeoMarker(10, 20) + + const coords = layer.geoMarker?.getGeometry()?.getCoordinates() + expect(coords).toEqual([10, 20]) + }) + + it('should create a new geoMarker if none exists when moving', () => { + layer.removeGeomarker() + expect(layer.geoMarker).toBeUndefined() + + layer.moveGeoMarker(15, 25) + expect(layer.geoMarker).toBeInstanceOf(Feature) + expect(layer.geoMarker?.getGeometry()?.getCoordinates()).toEqual([15, 25]) + }) + + it('should remove the geoMarker and clear the source', () => { + layer.removeGeomarker() + + expect(layer.geoMarker).toBeUndefined() + expect(layer.getSource()?.getFeatures().length).toBe(0) + }) +}) diff --git a/src/services/ol-layer/ol-layer-feature-position.helper.ts b/src/services/ol-layer/ol-layer-feature-position.helper.ts index bb3f0500..71df9e24 100644 --- a/src/services/ol-layer/ol-layer-feature-position.helper.ts +++ b/src/services/ol-layer/ol-layer-feature-position.helper.ts @@ -14,14 +14,11 @@ export class PositionVectorLayer extends VectorLayer> { geoMarker: Feature | undefined constructor(options: Options>) { - const geoMarker = new Feature() const source = new VectorSource({ - features: [geoMarker], + features: [], // geoMarker to be added here (@see createGeomarker()) }) super({ ...options, ...{ source } }) - - this.geoMarker = >geoMarker } moveGeoMarker(x: number, y: number) { @@ -34,6 +31,7 @@ export class PositionVectorLayer extends VectorLayer> { createGeomarker() { this.geoMarker = new Feature({ geometry: new Point([0, 0]) }) + this.getSource()?.clear() this.getSource()?.addFeature(this.geoMarker) } diff --git a/src/services/ol-layer/styles.helper.spec.ts b/src/services/ol-layer/styles.helper.spec.ts new file mode 100644 index 00000000..bef5d35c --- /dev/null +++ b/src/services/ol-layer/styles.helper.spec.ts @@ -0,0 +1,26 @@ +import CircleStyle from 'ol/style/Circle' +import Fill from 'ol/style/Fill' +import Stroke from 'ol/style/Stroke' +import Style from 'ol/style/Style' +import { getStyleFeaturePosition } from './styles.helper' + +describe('getStyleFeaturePosition', () => { + it('should return a Style with a Circle image', () => { + const style = getStyleFeaturePosition() + + expect(style).toBeInstanceOf(Style) + expect(style.getImage()).toBeInstanceOf(CircleStyle) + + const image = style.getImage() as CircleStyle + expect(image.getRadius()).toBe(4) + + const fill = image.getFill() + expect(fill).toBeInstanceOf(Fill) + expect(fill.getColor()).toBe('white') + + const stroke = image.getStroke() + expect(stroke).toBeInstanceOf(Stroke) + expect(stroke.getColor()).toBe('white') + expect(stroke.getWidth()).toBe(1) + }) +}) diff --git a/src/services/state-persistor/state-persistor-map.service.spec.ts b/src/services/state-persistor/state-persistor-map.service.spec.ts index a9bb63c8..d2f5f59d 100644 --- a/src/services/state-persistor/state-persistor-map.service.spec.ts +++ b/src/services/state-persistor/state-persistor-map.service.spec.ts @@ -15,7 +15,7 @@ let fakeStorage: { [key: string]: string | number } = {} describe('StatePersistorMapService', () => { const map = useMap() - map.createMap('myMap') + map.createMap() const olMap = map.getOlMap() const view = useMap().getOlMap().getView() diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index 93873254..2014c7b9 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -1,4 +1,9 @@ -import { debounce, sanitizeFilename, stringToNumber } from './utils' +import { + colorStringToRgba, + debounce, + sanitizeFilename, + stringToNumber, +} from './utils' const mock = vi.fn(() => 'function to be debounced') @@ -82,3 +87,35 @@ describe('#sanitizeFilename', () => { expect(sanitizeFilename('###@@@$$$')).toBe('_') }) }) + +describe('#colorStringToRgba', () => { + it('should convert a valid hex color string to an RGBA array', () => { + const result = colorStringToRgba('#ff5733') + expect(result).toEqual([255, 87, 51, 1]) + }) + + it('should use the provided opacity value', () => { + const result = colorStringToRgba('#ff5733', 0.5) + expect(result).toEqual([255, 87, 51, 0.5]) + }) + + it('should handle black color correctly', () => { + const result = colorStringToRgba('#000000') + expect(result).toEqual([0, 0, 0, 1]) + }) + + it('should handle white color correctly', () => { + const result = colorStringToRgba('#ffffff', 0.8) + expect(result).toEqual([255, 255, 255, 0.8]) + }) + + it('should throw an error for invalid hex color strings', () => { + expect(() => colorStringToRgba('invalid')).toThrow() + expect(() => colorStringToRgba('#123')).toThrow() + expect(() => colorStringToRgba('#zzzzzz')).toThrow() + }) + + it('should throw an error for missing "#" in hex color string', () => { + expect(() => colorStringToRgba('ff5733')).toThrow() + }) +}) diff --git a/src/services/utils.ts b/src/services/utils.ts index 86611d97..027b78e3 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -164,6 +164,11 @@ export function downloadFile( } export function colorStringToRgba(colorString: string, opacity = 1) { + const isValidHex = /^#[0-9A-Fa-f]{6}$/.test(colorString) + if (!isValidHex) { + throw new Error(`Invalid hex color string: ${colorString}`) + } + const r = parseInt(colorString.slice(1, 3), 16) const g = parseInt(colorString.slice(3, 5), 16) const b = parseInt(colorString.slice(5, 7), 16)