Socket
Socket
Sign inDemoInstall

altpro

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

altpro - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

7

History.md
0.2.0 / 2019-02-04
==================
* add method to change units on displayed profile
* start Y axis at minimum elevation in a data set
* externalize elevation label
0.1.1 / 2019-01-31

@@ -3,0 +10,0 @@ ==================

53

lib/altpro.js

@@ -22,3 +22,3 @@ const findSegment = require('./find-segment');

totalDistance: 0,
minElevation: 0,
minElevation: Number.MAX_VALUE,
maxElevation: 0

@@ -44,3 +44,3 @@ });

function drawPath(ctx, items) {
function drawPath(ctx, items, ref) {
ctx.beginPath();

@@ -51,7 +51,7 @@

ctx.moveTo(0, first.elevation);
ctx.moveTo(0, first.elevation - ref);
for(let i = 1; i < items.length; i++) {
const { elevation, distance } = items[i];
ctx.lineTo(distance, elevation);
ctx.lineTo(distance, elevation - ref);
}

@@ -68,7 +68,7 @@

function drawSelected(ctx, { distance: d1, elevation: e1 }, { distance: d2, elevation: e2 }) {
function drawSelected(ctx, { distance: d1, elevation: e1 }, { distance: d2, elevation: e2 }, ref) {
ctx.beginPath();
ctx.moveTo(d1, 0);
ctx.lineTo(d1, e1);
ctx.lineTo(d2, e2);
ctx.lineTo(d1, e1 - ref);
ctx.lineTo(d2, e2 - ref);
ctx.lineTo(d2, 0);

@@ -86,3 +86,3 @@ ctx.closePath();

function create(parent) {
function create(parent, label) {

@@ -113,5 +113,7 @@ function canvas(wrapper, w, h) {

const label = document.createElement('div');
label.className = 'altpro-label';
wrapper.appendChild(label);
if (!label) {
label = document.createElement('div');
label.className = 'altpro-label';
wrapper.appendChild(label);
}

@@ -122,3 +124,3 @@ return { bg, fg, label, w, h, };

function altpro(parent, data, opts = {}) {
const {
let {
fill = 'chartreuse',

@@ -136,9 +138,10 @@ stroke = 'black',

const ref = minElevation < 0 ? 0 : (minElevation - 0.05 * (maxElevation - minElevation));
const extent = {
x: totalDistance,
y: maxElevation - minElevation,
min: minElevation
y: maxElevation - Math.min(minElevation, ref),
min: Math.min(minElevation, 0)
};
const { bg, fg, label, w, h } = create(parent);
const { bg, fg, label, w, h } = create(parent, opts.label);

@@ -152,3 +155,3 @@ const ctx = bg.getContext('2d');

transformMatric.apply(ctx);
drawPath(ctx, items);
drawPath(ctx, items, ref);

@@ -168,5 +171,19 @@ const fgCtx = fg.getContext('2d');

select,
option,
destroy
};
function option(key, value) {
if (value === undefined) {
return opts[key];
}
opts[key] = value;
if (key === 'unit') {
unit = opts.unit;
if (selectedIndex !== -1) {
displayLabel(items[selectedIndex]);
}
}
}
function destroy() {

@@ -217,3 +234,3 @@ fg.removeEventListener('mousemove', onmousemove);

clear(fgCtx, { w, h });
drawSelected(fgCtx, items[selectedIndex - 1], items[selectedIndex]);
drawSelected(fgCtx, items[selectedIndex - 1], items[selectedIndex], ref);
displayLabel(items[selectedIndex]);

@@ -228,3 +245,3 @@ notify(selectedIndex);

elevation = Math.round(elevation);
label.innerText = `${elevation}${unit}`;
label.innerText = `${elevation}`;
label.hidden = false;

@@ -231,0 +248,0 @@ }

{
"name": "altpro",
"version": "0.1.1",
"version": "0.2.0",
"description": "Elevation profile widget.",

@@ -5,0 +5,0 @@ "author": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc