altpro
Advanced tools
Comparing version 0.0.1 to 0.1.0
0.1.0 / 2019-01-30 | ||
================== | ||
* add support for `altpro-select` event | ||
* add support for elevation label | ||
0.0.1 / 2019-01-30 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -79,3 +79,3 @@ const matrix2d = require('./matrix2d'); | ||
function createCanvas(parent) { | ||
function create(parent) { | ||
@@ -96,2 +96,3 @@ function canvas(wrapper, w, h) { | ||
const wrapper = document.createElement('div'); | ||
wrapper.className = 'altpro-wrapper'; | ||
wrapper.style.position = 'relative'; | ||
@@ -106,3 +107,7 @@ wrapper.style.width = '100%'; | ||
return { bg, fg, w, h }; | ||
const label = document.createElement('div'); | ||
label.className = 'altpro-label'; | ||
wrapper.appendChild(label); | ||
return { bg, fg, label, w, h, }; | ||
} | ||
@@ -114,3 +119,4 @@ | ||
stroke = 'black', | ||
selectedFill = 'orange' | ||
selectedFill = 'orange', | ||
unit = 'm' | ||
} = opts; | ||
@@ -130,3 +136,3 @@ const { | ||
const { bg, fg, w, h } = createCanvas(parent); | ||
const { bg, fg, label, w, h } = create(parent); | ||
@@ -150,2 +156,4 @@ const ctx = bg.getContext('2d'); | ||
let selectedIndex = -1; // nothing selected | ||
return { | ||
@@ -172,2 +180,3 @@ select, | ||
function onmouseleave() { | ||
label.hidden = true; | ||
clear(fgCtx, { w, h }); | ||
@@ -189,5 +198,32 @@ } | ||
} | ||
if (selectedIndex === index) { | ||
return; | ||
} | ||
clear(fgCtx, { w, h }); | ||
drawSelected(fgCtx, items[index - 1], items[index]); | ||
displayLabel(items[index]); | ||
notify(index); | ||
selectedIndex = index; | ||
} | ||
function displayLabel({ elevation }) { | ||
if (unit === 'ft') { | ||
elevation *= 3.28084; | ||
} | ||
elevation = Math.round(elevation); | ||
label.innerText = `${elevation}${unit}`; | ||
label.hidden = false; | ||
} | ||
function notify(index) { | ||
const { distance, elevation } = items[index]; | ||
const detail = { | ||
distance, | ||
elevation, | ||
index | ||
}; | ||
const selectEvent = new CustomEvent('altpro-select', { detail }); | ||
parent.dispatchEvent(selectEvent); | ||
} | ||
} |
{ | ||
"name": "altpro", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Elevation profile widget.", | ||
@@ -17,5 +17,7 @@ "author": { | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "~16", | ||
"canvas": "~2", | ||
"jsdom": "~13", | ||
"jsdom-global": "~3", | ||
"jshint": "~2", | ||
@@ -22,0 +24,0 @@ "mocha": "~5", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9905
275
0
7