@graph-paper/core
Advanced tools
Comparing version 0.0.0-alpha.5 to 0.0.0-alpha.6
@@ -1,5 +0,3 @@ | ||
import { tooltip } from './tooltip' | ||
import { tooltip } from "./tooltip"; | ||
export { | ||
tooltip | ||
} | ||
export { tooltip }; |
/* eslint-disable import/prefer-default-export */ | ||
import { listen } from 'svelte/internal'; | ||
import { placeElement } from '../utils/float-placement'; | ||
import { listen } from "svelte/internal"; | ||
import { placeElement } from "../utils/float-placement"; | ||
const defaults = { | ||
duration: 50, location: 'bottom', alignment: 'center', distance: 4, | ||
duration: 50, | ||
location: "bottom", | ||
alignment: "center", | ||
distance: 4, | ||
}; | ||
@@ -11,9 +14,7 @@ | ||
const options = { ...defaults, ...args }; | ||
const { | ||
duration, location, alignment, distance, | ||
} = options; | ||
const el = document.createElement('div'); | ||
el.className = 'tooltip'; | ||
const { duration, location, alignment, distance } = options; | ||
const el = document.createElement("div"); | ||
el.className = "tooltip"; | ||
el.textContent = options.text; | ||
el.style.position = 'absolute'; | ||
el.style.position = "absolute"; | ||
el.style.transition = `opacity ${duration}ms, transform ${duration}ms`; | ||
@@ -33,3 +34,2 @@ | ||
el.style.left = `${left}px`; | ||
} | ||
@@ -41,6 +41,6 @@ | ||
document.body.appendChild(el); | ||
el.style.opacity = '0'; | ||
el.style.opacity = "0"; | ||
setTimeout(() => { | ||
el.style.opacity = '1'; | ||
el.style.opacity = "1"; | ||
}); | ||
@@ -51,6 +51,8 @@ setLocation(); | ||
function remove() { el.remove(); } | ||
function remove() { | ||
el.remove(); | ||
} | ||
const removeEnter = listen(node, 'mouseenter', append); | ||
const removeLeave = listen(node, 'mouseleave', remove); | ||
const removeEnter = listen(node, "mouseenter", append); | ||
const removeLeave = listen(node, "mouseleave", remove); | ||
@@ -57,0 +59,0 @@ return { |
@@ -1,3 +0,3 @@ | ||
import core from './core.svelte'; | ||
import core from "./core.svelte"; | ||
export default core; |
import "./style.css"; | ||
export * from './base.js'; | ||
export { default } from './base.js'; | ||
export * from "./base.js"; | ||
export { default } from "./base.js"; |
{ | ||
"name": "@graph-paper/core", | ||
"version": "0.0.0-alpha.5", | ||
"version": "0.0.0-alpha.6", | ||
"description": "__DESCRIPTION_FORTHCOMING__", | ||
@@ -18,3 +18,3 @@ "author": "hamilton <hamilton.ulmer@gmail.com>", | ||
}, | ||
"gitHead": "d916947a1ae42aeef105220528458ef14d7118aa" | ||
"gitHead": "c6c560ce4670955b065b379082b1cd7f4253d0a7" | ||
} |
@@ -7,11 +7,19 @@ /* eslint-disable import/prefer-default-export */ | ||
export function mouseLocationToBoundingRect({ | ||
x, y, width = 0, height = 0, | ||
}) { | ||
export function mouseLocationToBoundingRect({ x, y, width = 0, height = 0 }) { | ||
return { | ||
parentPosition: { | ||
width, height, left: x, right: x + width, top: y, bottom: y + height, | ||
width, | ||
height, | ||
left: x, | ||
right: x + width, | ||
top: y, | ||
bottom: y + height, | ||
}, | ||
elementPosition: { | ||
width, height, left: x, right: x + width, top: y, bottom: y + height, | ||
width, | ||
height, | ||
left: x, | ||
right: x + width, | ||
top: y, | ||
bottom: y + height, | ||
}, | ||
@@ -26,3 +34,4 @@ }; | ||
elementPosition, | ||
distance = 0, y = 0, | ||
distance = 0, | ||
y = 0, | ||
windowWidth = window.innerWidth, | ||
@@ -44,7 +53,7 @@ windowHeight = window.innerHeight, | ||
if (location === 'bottom') { | ||
if (location === "bottom") { | ||
top = parentBottom + distance; | ||
} else if (location === 'top') { | ||
} else if (location === "top") { | ||
top = parentTop - elementHeight - distance; | ||
} else if (location === 'left') { | ||
} else if (location === "left") { | ||
// FIXME: is this the left / right default? | ||
@@ -56,3 +65,3 @@ left = parentLeft - elementWidth - distance; | ||
// FIXME: throw warning when location & alignment don't make sense | ||
if (alignment === 'right') { | ||
if (alignment === "right") { | ||
left = parentRight - elementWidth; | ||
@@ -63,3 +72,3 @@ // set right if off window | ||
} | ||
} else if (alignment === 'left') { | ||
} else if (alignment === "left") { | ||
// make it alignment="right" if it exceeds windowWith - elementWidth. | ||
@@ -70,3 +79,3 @@ left = parentLeft; | ||
} | ||
} else if (alignment === 'top') { | ||
} else if (alignment === "top") { | ||
top = parentTop; | ||
@@ -77,3 +86,3 @@ // if bottom edge of float is below height | ||
} | ||
} else if (alignment === 'bottom') { | ||
} else if (alignment === "bottom") { | ||
top = parentBottom - elementHeight; | ||
@@ -83,12 +92,20 @@ if (top < 0) { | ||
} | ||
} else if (location === 'left' || location === 'right') { | ||
} else if (location === "left" || location === "right") { | ||
// align center + location is left or right | ||
// do something here | ||
top = minmax(parentTop - (elementHeight - parentHeight) / 2, distance, windowHeight - distance); | ||
top = minmax( | ||
parentTop - (elementHeight - parentHeight) / 2, | ||
distance, | ||
windowHeight - distance | ||
); | ||
} else { | ||
// align center + location is top or bottom | ||
// location is top or bottom | ||
left = minmax(parentLeft - (elementWidth - parentWidth) / 2, distance, windowWidth - distance); | ||
left = minmax( | ||
parentLeft - (elementWidth - parentWidth) / 2, | ||
distance, | ||
windowWidth - distance | ||
); | ||
} | ||
return [left, top]; | ||
} |
@@ -6,6 +6,10 @@ // taken from d3-array | ||
export function firstIndexAbove({ | ||
value, data, key = 'label', lo = 0, hi = data.length, | ||
value, | ||
data, | ||
key = "label", | ||
lo = 0, | ||
hi = data.length, | ||
}) { | ||
while (lo < hi) { | ||
const mid = lo + hi >>> 1; // eslint-disable-line | ||
const mid = (lo + hi) >>> 1; // eslint-disable-line | ||
if (compare(+data[mid][key], value) < 0) lo = mid + 1; | ||
@@ -18,3 +22,7 @@ else hi = mid; | ||
export function windowIndices({ | ||
value, data, key = 'label', lowestValue = -Infinity, highestValue = Infinity, | ||
value, | ||
data, | ||
key = "label", | ||
lowestValue = -Infinity, | ||
highestValue = Infinity, | ||
}) { | ||
@@ -53,6 +61,14 @@ const lo = firstIndexAbove({ data, value: lowestValue, key }); | ||
export function window1D({ | ||
value, data, key = 'label', lowestValue = -Infinity, highestValue = Infinity, | ||
value, | ||
data, | ||
key = "label", | ||
lowestValue = -Infinity, | ||
highestValue = Infinity, | ||
}) { | ||
const { previous, current, next } = windowIndices({ | ||
value, data, key, lowestValue, highestValue, | ||
value, | ||
data, | ||
key, | ||
lowestValue, | ||
highestValue, | ||
}); | ||
@@ -73,11 +89,20 @@ | ||
function isDate(dt) { | ||
return Object.prototype.toString.call(dt) === '[object Date]'; | ||
return Object.prototype.toString.call(dt) === "[object Date]"; | ||
} | ||
export function window1DPlacement({ | ||
value, data, key = 'label', lowestValue = -Infinity, highestValue = Infinity, | ||
pad = 0.5, scale = (x) => x, | ||
value, | ||
data, | ||
key = "label", | ||
lowestValue = -Infinity, | ||
highestValue = Infinity, | ||
pad = 0.5, | ||
scale = (x) => x, | ||
}) { | ||
const { previous, current, next } = window1D({ | ||
value, data, key, lowestValue, highestValue, | ||
value, | ||
data, | ||
key, | ||
lowestValue, | ||
highestValue, | ||
}); | ||
@@ -84,0 +109,0 @@ const p = previous[key]; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31139
10
1164