diff options
Diffstat (limited to '')
11 files changed, 621 insertions, 533 deletions
diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js b/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js index 9b31b5c..dfb775d 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/acceleration.js @@ -1,64 +1,64 @@ -export function Acceleration() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let acceleration = {};
-
- acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²');
- opts.accelerationFactor = opts.accelerationFactor || 1;
-
- return {
- name: 'acceleration',
- unit: acceleration.label,
- deltaMax: this.options.accelerationDeltaMax,
- clampRange: this.options.accelerationRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dv = (this._data[i].speed - this._data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor);
- let dt = (this._data[i].time - this._data[i > 0 ? i - 1 : i].time) / 1000;
- return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: 0, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'Acceleration',
- yAttr : 'acceleration',
- scaleX : 'distance',
- scaleY : 'acceleration',
- color : '#050402',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: {
- chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label,
- marker: (item) => Math.round(item.acceleration) + " " + acceleration.label,
- order: 60,
- },
- summary: {
- "minacceleration" : {
- label: "Min Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_min || 0) + ' ' + unit,
- order: 60
- },
- "maxacceleration" : {
- label: "Max Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_max || 0) + ' ' + unit,
- order: 61
- },
- "avgacceleration": {
- label: "Avg Acceleration: ",
- value: (track, unit) => Math.round(track.acceleration_avg || 0) + ' ' + unit,
- order: 62
- },
- }
- };
-}
+export function Acceleration() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let acceleration = {}; + + acceleration.label = opts.accelerationLabel || L._(opts.imperial ? 'ft/s²' : 'm/s²'); + opts.accelerationFactor = opts.accelerationFactor || 1; + + return { + name: 'acceleration', + unit: acceleration.label, + deltaMax: this.options.accelerationDeltaMax, + clampRange: this.options.accelerationRange, + decimals: 2, + pointToAttr: (_, i) => { + let dv = (this._data[i].speed - this._data[i > 0 ? i - 1 : i].speed) * (1000 / opts.timeFactor); + let dt = (this._data[i].time - this._data[i > 0 ? i - 1 : i].time) / 1000; + return dt > 0 ? Math.abs((dv / dt)) * opts.accelerationFactor : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "right", + scale : { min: 0, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'Acceleration', + yAttr : 'acceleration', + scaleX : 'distance', + scaleY : 'acceleration', + color : '#050402', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: { + chart: (item) => L._("a: ") + item.acceleration + " " + acceleration.label, + marker: (item) => Math.round(item.acceleration) + " " + acceleration.label, + order: 60, + }, + summary: { + "minacceleration" : { + label: "Min Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_min || 0) + ' ' + unit, + order: 60 + }, + "maxacceleration" : { + label: "Max Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_max || 0) + ' ' + unit, + order: 61 + }, + "avgacceleration": { + label: "Avg Acceleration: ", + value: (track, unit) => Math.round(track.acceleration_avg || 0) + ' ' + unit, + order: 62 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js b/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js index b7fe6e3..5f6d6c8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/altitude.js @@ -1,78 +1,78 @@ -export function Altitude() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let altitude = {};
-
- let theme = opts.theme.split(' ')[0].replace('-theme', '');
- let color = _.Colors[theme] || {};
-
- opts.altitudeFactor = opts.imperial ? this.__footFactor : (opts.altitudeFactor || 1); // 1 m = (1 m)
- altitude.label = opts.imperial ? "ft" : opts.yLabel;
-
- return {
- name: 'altitude',
- required: this.options.slope,
- meta: 'z',
- unit: altitude.label,
- statsName: 'elevation',
- deltaMax: this.options.altitudeDeltaMax,
- clampRange: this.options.altitudeRange,
- // init: ({point}) => {
- // // "alt" property is generated inside "leaflet"
- // if ("alt" in point) point.meta.ele = point.alt;
- // },
- pointToAttr: (point, i) => {
- if ("alt" in point) point.meta.ele = point.alt; // "alt" property is generated inside "leaflet"
- return this._data[i].z *= opts.altitudeFactor;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- grid: {
- axis : "y",
- position : "left",
- scale : "y" // this._chart._y,
- },
- scale: {
- axis : "y",
- position: "left",
- scale : "y", // this._chart._y,
- labelX : -3,
- labelY : -8,
- },
- path: {
- label : 'Altitude',
- scaleX : 'distance',
- scaleY : 'altitude',
- className : 'area',
- color : color.area || theme,
- strokeColor : opts.detached ? color.stroke : '#000',
- strokeOpacity: "1",
- fillOpacity : opts.detached ? (color.alpha || '0.8') : 1,
- preferCanvas : opts.preferCanvas,
- },
- tooltip: {
- name: 'y',
- chart: (item) => L._("y: ") + _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label,
- marker: (item) => _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label,
- order: 10,
- },
- summary: {
- "minele" : {
- label: "Min Elevation: ",
- value: (track, unit) => (track.elevation_min || 0).toFixed(2) + ' ' + unit,
- order: 30,
- },
- "maxele" : {
- label: "Max Elevation: ",
- value: (track, unit) => (track.elevation_max || 0).toFixed(2) + ' ' + unit,
- order: 31,
- },
- "avgele" : {
- label: "Avg Elevation: ",
- value: (track, unit) => (track.elevation_avg || 0).toFixed(2) + ' ' + unit,
- order: 32,
- },
- }
- };
-}
+export function Altitude() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let altitude = {}; + + let theme = opts.theme.split(' ')[0].replace('-theme', ''); + let color = _.Colors[theme] || {}; + + opts.altitudeFactor = opts.imperial ? this.__footFactor : (opts.altitudeFactor || 1); // 1 m = (1 m) + altitude.label = opts.imperial ? "ft" : opts.yLabel; + + return { + name: 'altitude', + required: this.options.slope, + meta: 'z', + unit: altitude.label, + statsName: 'elevation', + deltaMax: this.options.altitudeDeltaMax, + clampRange: this.options.altitudeRange, + // init: ({point}) => { + // // "alt" property is generated inside "leaflet" + // if ("alt" in point) point.meta.ele = point.alt; + // }, + pointToAttr: (point, i) => { + if ("alt" in point) point.meta.ele = point.alt; // "alt" property is generated inside "leaflet" + return this._data[i].z *= opts.altitudeFactor; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + grid: { + axis : "y", + position : "left", + scale : "y" // this._chart._y, + }, + scale: { + axis : "y", + position: "left", + scale : "y", // this._chart._y, + labelX : -3, + labelY : -8, + }, + path: { + label : 'Altitude', + scaleX : 'distance', + scaleY : 'altitude', + className : 'area', + color : color.area || theme, + strokeColor : opts.detached ? color.stroke : '#000', + strokeOpacity: "1", + fillOpacity : opts.detached ? (color.alpha || '0.8') : 1, + preferCanvas : opts.preferCanvas, + }, + tooltip: { + name: 'y', + chart: (item) => L._("y: ") + _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label, + marker: (item) => _.round(item[opts.yAttr], opts.decimalsY) + " " + altitude.label, + order: 10, + }, + summary: { + "minele" : { + label: "Min Elevation: ", + value: (track, unit) => (track.elevation_min || 0).toFixed(2) + ' ' + unit, + order: 30, + }, + "maxele" : { + label: "Max Elevation: ", + value: (track, unit) => (track.elevation_max || 0).toFixed(2) + ' ' + unit, + order: 31, + }, + "avgele" : { + label: "Avg Elevation: ", + value: (track, unit) => (track.elevation_avg || 0).toFixed(2) + ' ' + unit, + order: 32, + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js b/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js index 0ad7704..db1a6d7 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/cadence.js @@ -1,54 +1,54 @@ -export function Cadence() {
-
- const _ = L.Control.Elevation.Utils;
-
- return {
- name: 'cadence', // <-- Your custom option name (eg. "cadence: true")
- unit: 'rpm',
- meta: 'cad', // <-- point.meta.cad
- coordinateProperties: ["cads", "cadences", "cad", "cadence"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON"
- pointToAttr: (point, i) => (point.cad ?? point.meta.cad ?? point.prev('cadence')) || 0,
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: -1, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'RPM',
- yAttr : 'cadence',
- scaleX : 'distance',
- scaleY : 'cadence',
- color : '#FFF',
- strokeColor : 'blue',
- strokeOpacity: "0.85",
- fillOpacity : "0.1",
- },
- tooltip: {
- name: 'cadence',
- chart: (item) => L._("cad: ") + item.cadence + " " + 'rpm',
- marker: (item) => Math.round(item.cadence) + " " + 'rpm',
- order: 1
- },
- summary: {
- "minrpm": {
- label: "Min RPM: ",
- value: (track, unit) => Math.round(track.cadence_min || 0) + ' ' + unit,
- // order: 30
- },
- "maxrpm": {
- label: "Max RPM: ",
- value: (track, unit) => Math.round(track.cadence_max || 0) + ' ' + unit,
- // order: 30
- },
- "avgrpm": {
- label: "Avg RPM: ",
- value: (track, unit) => Math.round(track.cadence_avg || 0) + ' ' + unit,
- // order: 20
- },
- }
- };
+export function Cadence() { + + const _ = L.Control.Elevation.Utils; + + return { + name: 'cadence', // <-- Your custom option name (eg. "cadence: true") + unit: 'rpm', + meta: 'cad', // <-- point.meta.cad + coordinateProperties: ["cads", "cadences", "cad", "cadence"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON" + pointToAttr: (point, i) => (point.cad ?? point.meta.cad ?? point.prev('cadence')) || 0, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "right", + scale : { min: -1, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'RPM', + yAttr : 'cadence', + scaleX : 'distance', + scaleY : 'cadence', + color : '#FFF', + strokeColor : 'blue', + strokeOpacity: "0.85", + fillOpacity : "0.1", + }, + tooltip: { + name: 'cadence', + chart: (item) => L._("cad: ") + item.cadence + " " + 'rpm', + marker: (item) => Math.round(item.cadence) + " " + 'rpm', + order: 1 + }, + summary: { + "minrpm": { + label: "Min RPM: ", + value: (track, unit) => Math.round(track.cadence_min || 0) + ' ' + unit, + // order: 30 + }, + "maxrpm": { + label: "Max RPM: ", + value: (track, unit) => Math.round(track.cadence_max || 0) + ' ' + unit, + // order: 30 + }, + "avgrpm": { + label: "Avg RPM: ", + value: (track, unit) => Math.round(track.cadence_avg || 0) + ' ' + unit, + // order: 20 + }, + } + }; }
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/heart.js b/assets/static/vendor/leaflet-elevation/src/handlers/heart.js index 1930f60..1e81b3a 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/heart.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/heart.js @@ -1,53 +1,53 @@ -export function Heart() {
-
- const _ = L.Control.Elevation.Utils;
-
- return {
- name: 'heart', // <-- Your custom option name (eg. "heart: true")
- unit: 'bpm',
- meta: 'hr', // <-- point.meta.hr
- coordinateProperties: ["heart", "heartRates", "heartRate"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON"
- pointToAttr: (point, i) => (point.hr ?? point.meta.hr ?? point.prev('heart')) || 0,
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale: {
- axis : "y",
- position : "left",
- scale : { min: -1, max: +1 },
- tickPadding: 25,
- labelX : -30,
- labelY : -8,
- },
- path: {
- label : 'ECG',
- yAttr : 'heart',
- scaleX : 'distance',
- scaleY : 'heart',
- color : 'white',
- strokeColor : 'red',
- strokeOpacity: "0.85",
- fillOpacity : "0.1",
- },
- tooltip: {
- chart: (item) => L._("hr: ") + item.heart + " " + 'bpm',
- marker: (item) => Math.round(item.heart) + " " + 'bpm',
- order: 1
- },
- summary: {
- "minbpm": {
- label: "Min BPM: ",
- value: (track, unit) => Math.round(track.heart_min || 0) + ' ' + unit,
- // order: 30
- },
- "maxbpm": {
- label: "Max BPM: ",
- value: (track, unit) => Math.round(track.heart_max || 0) + ' ' + unit,
- // order: 30
- },
- "avgbpm": {
- label: "Avg BPM: ",
- value: (track, unit) => Math.round(track.heart_avg || 0) + ' ' + unit,
- // order: 20
- },
- }
- };
+export function Heart() { + + const _ = L.Control.Elevation.Utils; + + return { + name: 'heart', // <-- Your custom option name (eg. "heart: true") + unit: 'bpm', + meta: 'hr', // <-- point.meta.hr + coordinateProperties: ["heart", "heartRates", "heartRate"], // List of GPX Extensions ("coordinateProperties") to be handled by "@tmcw/toGeoJSON" + pointToAttr: (point, i) => (point.hr ?? point.meta.hr ?? point.prev('heart')) || 0, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale: { + axis : "y", + position : "left", + scale : { min: -1, max: +1 }, + tickPadding: 25, + labelX : -30, + labelY : -8, + }, + path: { + label : 'ECG', + yAttr : 'heart', + scaleX : 'distance', + scaleY : 'heart', + color : 'white', + strokeColor : 'red', + strokeOpacity: "0.85", + fillOpacity : "0.1", + }, + tooltip: { + chart: (item) => L._("hr: ") + item.heart + " " + 'bpm', + marker: (item) => Math.round(item.heart) + " " + 'bpm', + order: 1 + }, + summary: { + "minbpm": { + label: "Min BPM: ", + value: (track, unit) => Math.round(track.heart_min || 0) + ' ' + unit, + // order: 30 + }, + "maxbpm": { + label: "Max BPM: ", + value: (track, unit) => Math.round(track.heart_max || 0) + ' ' + unit, + // order: 30 + }, + "avgbpm": { + label: "Avg BPM: ", + value: (track, unit) => Math.round(track.heart_avg || 0) + ' ' + unit, + // order: 20 + }, + } + }; };
\ No newline at end of file diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/labels.js b/assets/static/vendor/leaflet-elevation/src/handlers/labels.js index 31b3cd6..4deb0c7 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/labels.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/labels.js @@ -17,25 +17,24 @@ export function Labels() { if (90 == Math.abs(textRotation)) { - pointG.selectAll('text') - .attr('dy', '4px') - .attr("dx", (d, i, el) => Math.sign(textRotation) * (this._height() - d3.select(el[i].parentElement).datum().y - 8) + 'px') - .attr('text-anchor', textRotation > 0 ? 'end' : 'start') - .attr('transform', 'rotate(' + textRotation + ')') + pointG.querySelectorAll('text').forEach(text => L.Control.Elevation.Utils.setAttributes(text, { + dy: '4px', + dx: Math.sign(textRotation) * (this._height() - Number(text.parentElement.dataset.y) - 8) + 'px', + 'text-anchor': textRotation > 0 ? 'end' : 'start', + transform: 'rotate(' + textRotation + ')', + })); - pointG.selectAll('circle') - .attr('r', '2.5') - .attr('fill', '#fff') - .attr("stroke", '#000') - .attr("stroke-width", '1.1'); + pointG.querySelectorAll('circle').forEach(circle => L.Control.Elevation.Utils.setAttributes(circle, { + r: 2.5, fill: '#fff', stroke: '#000', 'stroke-width': 1.1, + })); } else if (!isNaN(textRotation)) { - pointG.selectAll('text') - .attr("dx", "4px") - .attr("dy", "-9px") - .attr('text-anchor', textAnchor ?? (0 == textRotation ? 'start' : 'middle')) - .attr('transform', 'rotate('+ -textRotation +')') + pointG.querySelectorAll('text').forEach(text => L.Control.Elevation.Utils.setAttributes(text, { + dx: '4px', dy: '-9px', + 'text-anchor': textAnchor ?? (0 == textRotation ? 'start' : 'middle'), + transform: 'rotate(' + -textRotation + ')', + })); } diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js b/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js index 90e33ce..ccf5d73 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/lineargradient.js @@ -16,6 +16,7 @@ * }, * }) * ``` + * `min` and `max` can also be numeric bounds. */ export function LinearGradient() { @@ -60,7 +61,7 @@ export function LinearGradient() { }; const { preferCanvas } = this.options; - const { attr, path: path_name, range, min, max } = L.extend({ + const { attr, path: path_name, range, min, max } = Object.assign({ attr: 'z', path: 'altitude', range: { 0.0: '#008800', 0.5: '#ffff00', 1.0: '#ff0000' }, @@ -80,8 +81,8 @@ export function LinearGradient() { const { defs } = chart._chart.utils; const palette = get_palette({ - min: isFinite(this.track_info[min]) ? this.track_info[min] : 0, - max: isFinite(this.track_info[max]) ? this.track_info[max] : 1, + min: isFinite(min) ? Number(min) : (isFinite(this.track_info[min]) ? this.track_info[min] : 0), + max: isFinite(max) ? Number(max) : (isFinite(this.track_info[max]) ? this.track_info[max] : 1), range, }); @@ -91,15 +92,22 @@ export function LinearGradient() { /** ref: `path.__fillStyle` within L.Control.Elevation.Utils::drawCanvas(ctx, path) */ path.__fillStyle = gradient = chart._context.createLinearGradient(0, 0, chart._width(), 0); } else { - defs.select('#' + gradient_id).remove(); - gradient = defs.append('svg:linearGradient').attr('id', gradient_id); - gradient.addColorStop = function(offset, color) { gradient.append('svg:stop').attr('offset', offset).attr('stop-color', color) }; - path.attr('fill', 'url(#' + gradient_id + ')').classed('area', false); + defs.querySelector('#' + gradient_id)?.remove(); + gradient = _.create('svg:linearGradient', '', { id: gradient_id }, defs); + gradient.addColorStop = (offset, color) => _.create('svg:stop', '', { offset, 'stop-color': color }, gradient); + path.setAttribute('fill', 'url(#' + gradient_id + ')'); + path.classList.remove('area'); } // Generate gradient for each segment picking colors from palette - for (let i = 0, data = this._data; i < data.length; i++) { - gradient.addColorStop((i) / data.length, palette.getRGBColor(data[i][attr])); + const data = this._data; + const xAttr = chart._props.areas[path_name].xAttr; + const minX = data[0][xAttr]; + const xRange = data[data.length - 1][xAttr] - minX; + + for (let i = 0; i < data.length; i++) { + const offset = xRange ? (data[i][xAttr] - minX) / xRange : 0; + gradient.addColorStop(offset, palette.getRGBColor(data[i][attr])); } }); @@ -108,14 +116,15 @@ export function LinearGradient() { this.on('elechart_updated', () => { const chart = this._chart; const { defs } = chart._chart.utils; - defs.select('#' + legend_id).remove(); - const legendGradient = defs.append('svg:linearGradient').attr('id', legend_id); - Object.keys(range).sort().forEach(i => legendGradient.append('svg:stop').attr('offset', i).attr('stop-color', range[i])); + defs.querySelector('#' + legend_id)?.remove(); + const legendGradient = _.create('svg:linearGradient', '', { id: legend_id }, defs); + Object.keys(range).sort().forEach(i => _.create('svg:stop', '', { offset: i, 'stop-color': range[i] }, legendGradient)); - chart._container - .select('.legend-' + path_name + ' > rect') - .attr('fill', 'url(#' + legend_id + ')') - .classed('area', false); + const rect = chart._container.querySelector('.legend-' + path_name + ' > rect'); + if (rect) { + rect.setAttribute('fill', 'url(#' + legend_id + ')'); + rect.classList.remove('area'); + } }); return { }; diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/pace.js b/assets/static/vendor/leaflet-elevation/src/handlers/pace.js index 9017f39..7f0c260 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/pace.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/pace.js @@ -1,65 +1,65 @@ -export function Pace() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let pace = {};
-
- pace.label = opts.paceLabel || L._(opts.imperial ? 'min/mi' : 'min/km');
- opts.paceFactor = opts.paceFactor || 60; // 1 min = 60 sec
-
- return {
- name: 'pace',
- unit: pace.label,
- deltaMax: this.options.paceDeltaMax,
- clampRange: this.options.paceRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
- return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale : (this.options.pace && this.options.pace != "summary") && {
- axis : "y",
- position : "right",
- scale : { min : 0, max : +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: (this.options.pace && this.options.pace != "summary") && {
- // name : 'pace',
- label : 'Pace',
- yAttr : "pace",
- scaleX : 'distance',
- scaleY : 'pace',
- color : '#03ffff',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: (this.options.pace) && {
- chart: (item) => L._('pace: ') + item.pace + " " + pace.label,
- marker: (item) => Math.round(item.pace) + " " + pace.label,
- order: 50,
- },
- summary: (this.options.pace) && {
- "minpace" : {
- label: "Min Pace: ",
- value: (track, unit) => Math.round(track.pace_min || 0) + ' ' + unit,
- order: 51
- },
- "maxpace" : {
- label: "Max Pace: ",
- value: (track, unit) => Math.round(track.pace_max || 0) + ' ' + unit,
- order: 51
- },
- "avgpace": {
- label: "Avg Pace: ",
- value: (track, unit) => Math.round(track.pace_avg || 0) + ' ' + unit,
- order: 52
- },
- }
- };
-}
+export function Pace() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let pace = {}; + + pace.label = opts.paceLabel || L._(opts.imperial ? 'min/mi' : 'min/km'); + opts.paceFactor = opts.paceFactor || 60; // 1 min = 60 sec + + return { + name: 'pace', + unit: pace.label, + deltaMax: this.options.paceDeltaMax, + clampRange: this.options.paceRange, + decimals: 2, + pointToAttr: (_, i) => { + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time; + return dx > 0 ? Math.abs((dt / dx) / opts.paceFactor) : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale : (this.options.pace && this.options.pace != "summary") && { + axis : "y", + position : "right", + scale : { min : 0, max : +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: (this.options.pace && this.options.pace != "summary") && { + // name : 'pace', + label : 'Pace', + yAttr : "pace", + scaleX : 'distance', + scaleY : 'pace', + color : '#03ffff', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: (this.options.pace) && { + chart: (item) => L._('pace: ') + item.pace + " " + pace.label, + marker: (item) => Math.round(item.pace) + " " + pace.label, + order: 50, + }, + summary: (this.options.pace) && { + "minpace" : { + label: "Min Pace: ", + value: (track, unit) => Math.round(track.pace_min || 0) + ' ' + unit, + order: 51 + }, + "maxpace" : { + label: "Max Pace: ", + value: (track, unit) => Math.round(track.pace_max || 0) + ' ' + unit, + order: 51 + }, + "avgpace": { + label: "Avg Pace: ", + value: (track, unit) => Math.round(track.pace_avg || 0) + ' ' + unit, + order: 52 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/runner.js b/assets/static/vendor/leaflet-elevation/src/handlers/runner.js index 30dd80a..8135edd 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/runner.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/runner.js @@ -1,18 +1,20 @@ /** - * @see https://github.com/Igor-Vladyka/leaflet.motion + * Animate a track with requestAnimationFrame; motion speed is in km/h and duration in ms. * + * Inspired by: https://github.com/Igor-Vladyka/leaflet.motion + * * @example * ```js * L.control.Elevation({ handlers: [ 'Runner' ], runnerOptions: { polyline: {..}, motion: {..}, marker {..} } }) * ``` */ -export async function Runner() { +export function Runner() { - await this.import(this.__LMOTION || 'https://unpkg.com/leaflet.motion@0.3.2/dist/leaflet.motion.min.js', typeof L.Motion !== 'object') + const _ = L.Control.Elevation.Utils; let { runnerOptions } = this.options; - runnerOptions = L.extend( + runnerOptions = Object.assign( { polyline: {}, motion: {}, marker: undefined }, 'object' === typeof runnerOptions ? runnerOptions : {} ); @@ -40,13 +42,10 @@ export async function Runner() { this.addRunner = function (runner) { let x = this._x(runner.dist); let y = this._y(this._findItemForX(x).z) - let g = d3.select(this._container) - .select('svg > g') - .append("svg:circle") - .attr("class", "runner " + this.options.theme + " height-focus circle-lower") - .attr("r", 6) - .attr("cx", x) - .attr("cy", y); + let g = _.create('svg:circle', '', { + class: "runner " + this.options.theme + " height-focus circle-lower", + r: 6, cx: x, cy: y, + }, this._container.querySelector('svg > g')); return g; } @@ -71,13 +70,36 @@ export async function Runner() { curr = this._findItemForX(x); } - runner - .attr("cx", x) - .attr("cy", this._y(curr.z)); + runner.setAttribute("cx", x); + runner.setAttribute("cy", this._y(curr.z)); this.setPositionFromLatLng(curr.latlng); }; this.animate = function (layer, speed = 1500) { + const latlngs = []; + const collect = segment => { + if (segment instanceof L.Polyline) { + const append = points => { + if (L.LineUtil.isFlat(points)) latlngs.push(...points); + else points.forEach(append); + }; + append(segment.getLatLngs()); + } else if (segment.eachLayer) segment.eachLayer(collect); + }; + collect(layer); + if (!latlngs.length) throw new Error('The runner requires a track with coordinates.'); + + const distances = [0]; + for (let i = 1; i < latlngs.length; i++) { + distances.push(distances[i - 1] + latlngs[i - 1].distanceTo(latlngs[i])); + } + const length = distances[distances.length - 1]; + const motion = Object.assign({ auto: true, speed, easing: value => value }, runnerOptions.motion); + const duration = motion.duration || (motion.speed ? length / motion.speed * 3600 : 0); + if (!Number.isFinite(duration) || duration < 0 || !Number.isFinite(motion.speed) || motion.speed < 0) { + throw new Error('Runner speed and duration must be finite, non-negative numbers.'); + } + if (typeof motion.easing !== 'function') throw new Error('Runner easing must be a function.'); if (this._runner) { this._runner.remove(); @@ -85,24 +107,75 @@ export async function Runner() { layer.setStyle({ opacity: 0.5 }); - const geo = L.geoJson(layer.toGeoJSON(), { coordsToLatLng: (coords) => L.latLng(coords[0], coords[1], coords[2] * (this.options.altitudeFactor || 1)) }); - this._runner = L.motion.polyline( - geo.toGeoJSON().features[0].geometry.coordinates, - L.extend({}, { color: 'red', pane: 'elevationPane', attribution: '' }, runnerOptions.polyline), - L.extend({}, { auto: true, speed: speed, }, runnerOptions.motion), - runnerOptions.marker || undefined - ); + const runner = this._runner = new L.Polyline([], Object.assign( + { color: 'red', pane: 'elevationPane', attribution: '' }, runnerOptions.polyline + )); + const marker = runnerOptions.marker ? new L.Marker(latlngs[0], runnerOptions.marker) : null; + let circle; + let frame; + let started; + let elapsed = 0; + let running = false; - // Override default function behavior: `L.Motion.Polyline::_drawMarker()` - this._runner._drawMarker = new Proxy(this._runner._drawMarker, { - apply: (target, thisArg, argArray) => { - thisArg._runner = thisArg._runner || this.addRunner({ dist: 0 }); - this.updateRunnerPos(thisArg._runner, argArray[0]); - return target.apply(thisArg, argArray); + const draw = progress => { + const distance = length * progress; + let index = 1; + while (index < distances.length - 1 && distances[index] < distance) index++; + index = Math.min(index, latlngs.length - 1); + const previous = Math.max(0, index - 1); + const segmentLength = distances[index] - distances[previous]; + const ratio = segmentLength ? (distance - distances[previous]) / segmentLength : 0; + const from = this._map.project(latlngs[previous]); + const to = this._map.project(latlngs[index]); + const position = this._map.unproject(from.add(to.subtract(from).multiplyBy(ratio))); + runner.setLatLngs([...latlngs.slice(0, index), position]); + circle = circle || this.addRunner({ dist: 0 }); + this.updateRunnerPos(circle, position); + if (marker) marker.setLatLng(position).addTo(this._map); + }; + const advance = timestamp => { + started = started ?? timestamp - elapsed; + elapsed = timestamp - started; + const progress = duration ? Math.min(1, elapsed / duration) : 1; + draw(progress === 1 ? 1 : Math.max(0, Math.min(1, motion.easing(progress, elapsed, 0, 1, duration)))); + if (progress < 1) frame = requestAnimationFrame(advance); + else { + running = false; + if (runnerOptions.marker?.removeOnEnd) marker.remove(); + runner.fire('motion-ended', { layer: runner }); } + }; + runner.motionPause = () => { + cancelAnimationFrame(frame); + running = false; + started = undefined; + return runner; + }; + runner.motionResume = () => { + if (!running && runner._map) { + running = true; + frame = requestAnimationFrame(advance); + } + return runner; + }; + runner.motionStart = () => { + runner.motionPause(); + elapsed = 0; + return runner.motionResume(); + }; + runner.getMarker = () => marker; + runner.on('remove', () => { + runner.motionPause(); + circle?.remove(); + marker?.remove(); + this.off('eledata_clear', remove); + this.off('remove', remove); }); - - this._runner.addTo(this._map); + const remove = () => runner.remove(); + this.on('eledata_clear', remove); + this.on('remove', remove); + runner.addTo(this._map); + if (motion.auto) runner.motionStart(); }; return {}; diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/slope.js b/assets/static/vendor/leaflet-elevation/src/handlers/slope.js index 37291b3..1ed65af 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/slope.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/slope.js @@ -1,79 +1,79 @@ -export function Slope() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let slope = {};
-
- slope.label = opts.slopeLabel || '%';
-
- return {
- name: 'slope',
- meta: 'slope',
- unit: slope.label,
- deltaMax: this.options.slopedDeltaMax,
- clampRange: this.options.slopeRange,
- decimals: 2,
- pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100;
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
- return dx !== 0 ? (dy / dx) * 100 : NaN;
- },
- onPointAdded: (_, i) => {
- let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr];
- if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent
- else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, },
- scale: {
- axis : "y",
- position : "right",
- scale : { min: -1, max: +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: {
- label : 'Slope',
- yAttr : 'slope',
- scaleX : 'distance',
- scaleY : 'slope',
- color : '#F00',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: {
- chart: (item) => L._("m: ") + item.slope + slope.label,
- marker: (item) => Math.round(item.slope) + slope.label,
- order: 40,
- },
- summary: {
- "minslope": {
- label: "Min Slope: ",
- value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit,
- order: 40
- },
- "maxslope": {
- label: "Max Slope: ",
- value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit,
- order: 41
- },
- "avgslope": {
- label: "Avg Slope: ",
- value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit,
- order: 42
- },
- "ascent" : {
- label: "Total Ascent: ",
- value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
- order: 43
- },
- "descent" : {
- label: "Total Descent: ",
- value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'),
- order: 45
- },
- }
- };
-}
+export function Slope() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let slope = {}; + + slope.label = opts.slopeLabel || '%'; + + return { + name: 'slope', + meta: 'slope', + unit: slope.label, + deltaMax: this.options.slopedDeltaMax, + clampRange: this.options.slopeRange, + decimals: 2, + pointToAttr: (_, i) => { // slope in % = ( dy / dx ) * 100; + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dy = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr]; + return dx !== 0 ? (dy / dx) * 100 : NaN; + }, + onPointAdded: (_, i) => { + let dz = this._data[i][this.options.yAttr] - this._data[i > 0 ? i - 1 : i][this.options.yAttr]; + if (dz > 0) this.track_info.ascent = (this.track_info.ascent || 0) + dz; // Total Ascent + else if (dz < 0) this.track_info.descent = (this.track_info.descent || 0) - dz; // Total Descent + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg, }, + scale: { + axis : "y", + position : "right", + scale : { min: -1, max: +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: { + label : 'Slope', + yAttr : 'slope', + scaleX : 'distance', + scaleY : 'slope', + color : '#F00', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: { + chart: (item) => L._("m: ") + item.slope + slope.label, + marker: (item) => Math.round(item.slope) + slope.label, + order: 40, + }, + summary: { + "minslope": { + label: "Min Slope: ", + value: (track, unit) => Math.round(track.slope_min || 0) + ' ' + unit, + order: 40 + }, + "maxslope": { + label: "Max Slope: ", + value: (track, unit) => Math.round(track.slope_max || 0) + ' ' + unit, + order: 41 + }, + "avgslope": { + label: "Avg Slope: ", + value: (track, unit) => Math.round(track.slope_avg || 0) + ' ' + unit, + order: 42 + }, + "ascent" : { + label: "Total Ascent: ", + value: (track, unit) => Math.round(track.ascent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'), + order: 43 + }, + "descent" : { + label: "Total Descent: ", + value: (track, unit) => Math.round(track.descent || 0) + ' ' + (this.options.imperial ? 'ft' : 'm'), + order: 45 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/speed.js b/assets/static/vendor/leaflet-elevation/src/handlers/speed.js index 534b340..52068e8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/speed.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/speed.js @@ -1,66 +1,66 @@ -export function Speed() {
-
- const _ = L.Control.Elevation.Utils;
-
- let opts = this.options;
- let speed = {};
-
- speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h');
- opts.speedFactor = opts.speedFactor || 1;
-
- return {
- name: 'speed',
- required: (this.options.acceleration),
- unit: speed.label,
- deltaMax: this.options.speedDeltaMax,
- clampRange: this.options.speedRange,
- decimals: 2,
- pointToAttr: (_, i) => {
- let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000;
- let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time;
- return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : NaN;
- },
- stats: { max: _.iMax, min: _.iMin, avg: _.iAvg },
- scale : (this.options.speed && this.options.speed != "summary") && {
- axis : "y",
- position : "right",
- scale : { min : 0, max : +1 },
- tickPadding: 16,
- labelX : 25,
- labelY : -8,
- },
- path: (this.options.speed && this.options.speed != "summary") && {
- // name : 'speed',
- label : 'Speed',
- yAttr : "speed",
- scaleX : 'distance',
- scaleY : 'speed',
- color : '#03ffff',
- strokeColor : '#000',
- strokeOpacity: "0.5",
- fillOpacity : "0.25",
- },
- tooltip: (this.options.speed) && {
- chart: (item) => L._('v: ') + item.speed + " " + speed.label,
- marker: (item) => Math.round(item.speed) + " " + speed.label,
- order: 50,
- },
- summary: (this.options.speed) && {
- "minspeed" : {
- label: "Min Speed: ",
- value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit,
- order: 51
- },
- "maxspeed" : {
- label: "Max Speed: ",
- value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit,
- order: 51
- },
- "avgspeed": {
- label: "Avg Speed: ",
- value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit,
- order: 52
- },
- }
- };
-}
+export function Speed() { + + const _ = L.Control.Elevation.Utils; + + let opts = this.options; + let speed = {}; + + speed.label = opts.speedLabel || L._(opts.imperial ? 'mph' : 'km/h'); + opts.speedFactor = opts.speedFactor || 1; + + return { + name: 'speed', + required: (this.options.acceleration), + unit: speed.label, + deltaMax: this.options.speedDeltaMax, + clampRange: this.options.speedRange, + decimals: 2, + pointToAttr: (_, i) => { + let dx = (this._data[i].dist - this._data[i > 0 ? i - 1 : i].dist) * 1000; + let dt = this._data[i].time - this._data[ i > 0 ? i - 1 : i].time; + return dt > 0 ? Math.abs((dx / dt) * opts.timeFactor) * opts.speedFactor : NaN; + }, + stats: { max: _.iMax, min: _.iMin, avg: _.iAvg }, + scale : (this.options.speed && this.options.speed != "summary") && { + axis : "y", + position : "right", + scale : { min : 0, max : +1 }, + tickPadding: 16, + labelX : 25, + labelY : -8, + }, + path: (this.options.speed && this.options.speed != "summary") && { + // name : 'speed', + label : 'Speed', + yAttr : "speed", + scaleX : 'distance', + scaleY : 'speed', + color : '#03ffff', + strokeColor : '#000', + strokeOpacity: "0.5", + fillOpacity : "0.25", + }, + tooltip: (this.options.speed) && { + chart: (item) => L._('v: ') + item.speed + " " + speed.label, + marker: (item) => Math.round(item.speed) + " " + speed.label, + order: 50, + }, + summary: (this.options.speed) && { + "minspeed" : { + label: "Min Speed: ", + value: (track, unit) => Math.round(track.speed_min || 0) + ' ' + unit, + order: 51 + }, + "maxspeed" : { + label: "Max Speed: ", + value: (track, unit) => Math.round(track.speed_max || 0) + ' ' + unit, + order: 51 + }, + "avgspeed": { + label: "Avg Speed: ", + value: (track, unit) => Math.round(track.speed_avg || 0) + ' ' + unit, + order: 52 + }, + } + }; +} diff --git a/assets/static/vendor/leaflet-elevation/src/handlers/time.js b/assets/static/vendor/leaflet-elevation/src/handlers/time.js index d94b136..b1f08b8 100644 --- a/assets/static/vendor/leaflet-elevation/src/handlers/time.js +++ b/assets/static/vendor/leaflet-elevation/src/handlers/time.js @@ -40,7 +40,7 @@ export function Time() { if (!point.meta || !point.meta.time) { point.meta = point.meta || {}; if (i > 0) { - let dx = (this._data[i].dist - this._data[i - 1].dist); + let dx = this._data[i].latlng.distanceTo(this._data[i - 1].latlng) / 1000; let t0 = this._data[i - 1].time.getTime(); point.meta.time = new Date(t0 + ( dx / this._timeAVGSpeed) * this.options.timeFactor * 1000); } else { @@ -57,27 +57,34 @@ export function Time() { scale: (opts.time && opts.time != "summary" && !L.Browser.mobile) && { axis : "x", position : "top", - scale : { - attr : "duration", - min : 0, - }, + scale : "x", label : time.label, labelY : -10, labelX : () => this._width(), name : "time", ticks : () => _.clamp(this._chart._xTicks() / 2, [4, +Infinity]), - tickFormat : (d) => (d == 0 ? '' : opts.xTimeFormat(d)), + tickFormat : (distance) => { + const data = this._data; + if (!data.length) return ''; + const i = _.bisect(data, distance, opts.xAttr, true); + const start = data[Math.max(0, i - 1)]; + const end = data[Math.min(i, data.length - 1)]; + const span = end[opts.xAttr] - start[opts.xAttr]; + // Time is only linear between consecutive recorded points, not across the whole track. + const fraction = span ? _.clamp((distance - start[opts.xAttr]) / span, [0, 1]) : 0; + const duration = start.duration + fraction * (end.duration - start.duration); + return duration == 0 ? '' : opts.xTimeFormat(duration); + }, onAxisMount: axis => { - axis.select(".domain") - .remove(); - axis.selectAll("text") - .attr('opacity', 0.65) - .style('font-family', 'Monospace') - .style('font-size', '110%'); - axis.selectAll(".tick line") - .attr('y2', this._height()) - .attr('stroke-dasharray', 2) - .attr('opacity', 0.75); + axis.querySelector(".domain").remove(); + axis.querySelectorAll("text").forEach(text => { + text.setAttribute('opacity', 0.65); + text.style.fontFamily = 'Monospace'; + text.style.fontSize = '110%'; + }); + axis.querySelectorAll(".tick line").forEach(line => _.setAttributes(line, { + y2: this._height(), 'stroke-dasharray': 2, opacity: 0.75, + })); } }, tooltips: [ |
