Skip to content

Commit

Permalink
距離と標高の更新を切り出した
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Dec 5, 2022
1 parent b39f332 commit d99be13
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ maxDistanceInput?.addEventListener('input', event => {
updateMaximumMinDistance(maxDistance)
}

updateChart(croppedData(minDistance, maxDistance))
updateDistance()

sendChangeChartSettingsEvent()
}, 500)
Expand All @@ -60,18 +60,20 @@ minDistanceInput?.addEventListener('input', event => {
updateMinimumMaxDistance(minDistance)
}

updateChart(croppedData(minDistance, maxDistance))
updateDistance()

sendChangeChartSettingsEvent()
}, 500)
})

function updateDistance() {
updateChart(croppedData(minDistance, maxDistance))
}

maxAltitudeInput?.addEventListener('input', event => {
debounce(() => {
var parsed = parseFloat((event.target as HTMLInputElement).value)

if (chart.options.scales?.['y'] == undefined) { return }

if (isNaN(parsed)) {
const altitudes = (chart.data.datasets?.[0].data as Chart.ChartPoint[])
.map(point => point.y)
Expand All @@ -80,14 +82,19 @@ maxAltitudeInput?.addEventListener('input', event => {
parsed = (Math.floor(max / 100) + 1) * 100
}

chart.options.scales['y'].max = parsed

chart.update()
updateAltitude(parsed)

sendChangeChartSettingsEvent()
}, 500)
})

function updateAltitude(altitude: number) {
if (chart.options.scales?.['y'] == undefined) { return }

chart.options.scales['y'].max = altitude
chart.update()
}

var timerID: number
function debounce(func: TimerHandler, delay: number) {
clearTimeout(timerID)
Expand Down Expand Up @@ -375,6 +382,8 @@ function updateMinimumMaxDistance(minDistance: number) {
maxDistanceInput.min = minDistance.toString()
}

// Google Tag Manager

function retrieveDisplaySettings() {
return {
'min_distance': maxDistanceInput.value,
Expand Down

0 comments on commit d99be13

Please sign in to comment.