diff --git a/js/plugin/Heightgraph.js b/js/plugin/Heightgraph.js index 715ee3f9..cb428494 100644 --- a/js/plugin/Heightgraph.js +++ b/js/plugin/Heightgraph.js @@ -167,7 +167,30 @@ BR.Heightgraph = function (map, layersControl, routing, pois) { } else { $('#no-elevation-data').hide(); } - var geojsonFeatures = geoDataExchange.buildGeojsonFeatures(track.getLatLngs()); + var chartWidth; + if (document.getElementsByClassName('heightgraph-container').length > 0) { + var hgElement = document.getElementsByClassName('heightgraph-container')[0]; + if (hgElement.getElementsByTagName('g').length > 0) { + hgGElement = hgElement.getElementsByTagName('g')[0]; + if (hgGElement.getElementsByClassName('grid').length > 1) { + hgGRectElement = hgGElement.getElementsByClassName('grid')[1]; + chartWidth = hgGRectElement.getBoundingClientRect().width; + } + } + } + // if I cannot get the chart width (e.g. the chart is not visible), + // get the width of the content element - that's close enough + if (typeof chartWidth === 'undefined' || chartWidth === 0) { + var contentElement = document.getElementById('content'); + if (contentElement) { + chartWidth = contentElement.getBoundingClientRect().width; + } + } + var geojsonFeatures = geoDataExchange.buildGeojsonFeatures(track.getLatLngs(), { + interpolate: false, + normalize: true, + chartWidthInPixels: chartWidth, + }); this.addData(geojsonFeatures); // re-add handlers diff --git a/package.json b/package.json index 1386e680..7e99de43 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "datatables": "1.10.18", "fit-file-writer": "tbsmark86/fit-file-writer#3eebe13", "font-awesome": "4.7.0", - "geo-data-exchange": "alexcojocaru/geo-data-exchange#v2.0.0", + "geo-data-exchange": "alexcojocaru/geo-data-exchange#v2.1.0", "i18next": "19.9.2", "i18next-browser-languagedetector": "7.0.2", "i18next-xhr-backend": "3.2.2", diff --git a/yarn.lock b/yarn.lock index c9cb3e09..c5a99e8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5636,9 +5636,9 @@ gensync@^1.0.0-beta.2: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== -geo-data-exchange@alexcojocaru/geo-data-exchange#v2.0.0: - version "2.0.0" - resolved "https://codeload.github.com/alexcojocaru/geo-data-exchange/tar.gz/f3964028483ce194700f98c3d9c241818b54062b" +geo-data-exchange@alexcojocaru/geo-data-exchange#v2.1.0: + version "2.1.0" + resolved "https://codeload.github.com/alexcojocaru/geo-data-exchange/tar.gz/aa1a0bc98f0b3f7233ea3dcbc038bf46a99702d9" dependencies: leaflet "^1.5.0"