@chasi/ui
Advanced tools
Comparing version 0.2.65 to 0.2.66
@@ -1,2 +0,2 @@ | ||
import { throttle } from '../CGraph/utils.js'; | ||
import { throttle } from '../utils.js'; | ||
export default (node, params) => { | ||
@@ -3,0 +3,0 @@ let x; |
@@ -1,2 +0,2 @@ | ||
import { throttle } from '../CGraph/utils.js'; | ||
import { throttle } from '../utils.js'; | ||
export default (node, params) => { | ||
@@ -3,0 +3,0 @@ let dist; |
@@ -7,2 +7,1 @@ export { default as CGraph } from './CGraph.svelte'; | ||
export { default as CAxisY } from './CAxis-y.svelte'; | ||
export * from './utils.js'; |
@@ -7,2 +7,1 @@ export { default as CGraph } from './CGraph.svelte'; | ||
export { default as CAxisY } from './CAxis-y.svelte'; | ||
export * from './utils.js'; |
@@ -14,3 +14,4 @@ export { default as CIcon } from './CIcon/CIcon.svelte'; | ||
export { default as CAvatar } from './CAvatar/CAvatar.svelte'; | ||
export * from './CGraph/index.js'; | ||
export type { Rule } from './CForms/rules.js'; | ||
export type { ThemeGeneratorConfig } from './theme.js'; |
@@ -14,1 +14,2 @@ export { default as CIcon } from './CIcon/CIcon.svelte'; | ||
export { default as CAvatar } from './CAvatar/CAvatar.svelte'; | ||
export * from './CGraph/index.js'; |
export declare function isEqual(a: any, b: any): boolean; | ||
export declare function distance(p1: [number, number], p2: [number, number]): number; | ||
export declare function isInside(point: [number, number], polygonVertices: [number, number][]): boolean; | ||
export declare function randomNumber(min?: number, max?: number): number; | ||
export declare function polyArea(vertices: [number, number][]): number; | ||
export declare function max(data: number[]): number; | ||
export declare function min(data: number[]): number; | ||
export declare function linearScale(point: number, minD: number, maxD: number, minR: number, maxR: number): number; | ||
export declare function zoom(point: number, z: number, centroid: number): number; | ||
export declare function randomColor(): string; | ||
export declare function ticks(min: number, max: number, count: number): number[]; | ||
type ThrottledFunction<T extends (...args: any) => any> = (...args: Parameters<T>) => ReturnType<T>; | ||
export declare function throttle<T extends (...args: any) => any>(func: T, limit: number): ThrottledFunction<T>; | ||
export {}; |
@@ -0,1 +1,2 @@ | ||
import d3Ticks from './CGraph/ticks.js'; | ||
export function isEqual(a, b) { | ||
@@ -30,1 +31,83 @@ if (a === b) | ||
} | ||
export function distance(p1, p2) { | ||
return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2)); | ||
} | ||
export function isInside(point, polygonVertices) { | ||
const x = point[0]; | ||
const y = point[1]; | ||
let inside = false; | ||
for (let i = 0, j = polygonVertices.length - 1; i < polygonVertices.length; j = i++) { | ||
const xi = polygonVertices[i][0]; | ||
const yi = polygonVertices[i][1]; | ||
const xj = polygonVertices[j][0]; | ||
const yj = polygonVertices[j][1]; | ||
const intersect = ((yi > y) !== (yj > y)) && | ||
(x < (xj - xi) * (y - yi) / (yj - yi) + xi); | ||
if (intersect) | ||
inside = !inside; | ||
} | ||
return inside; | ||
} | ||
export function randomNumber(min = 0, max = 1) { | ||
return Math.random() * (max - min) + min; | ||
} | ||
export function polyArea(vertices) { | ||
let total = 0; | ||
for (let i = 0, l = vertices.length; i < l; i++) { | ||
let addX = vertices[i][0]; | ||
let addY = vertices[i === vertices.length - 1 ? 0 : i + 1][1]; | ||
let subX = vertices[i === vertices.length - 1 ? 0 : i + 1][0]; | ||
let subY = vertices[i][1]; | ||
total += (addX * addY * 0.5); | ||
total -= (subX * subY * 0.5); | ||
} | ||
return Math.abs(total); | ||
} | ||
export function max(data) { | ||
let max = Number.NEGATIVE_INFINITY; | ||
for (let i = 0; i < data.length; i++) { | ||
const point = data[i]; | ||
max = Number(point > max ? point : max); | ||
} | ||
return max; | ||
} | ||
export function min(data) { | ||
let min = Number.POSITIVE_INFINITY; | ||
for (let i = 0; i < data.length; i++) { | ||
const point = data[i]; | ||
min = Number(point < min ? point : min); | ||
} | ||
return min; | ||
} | ||
export function linearScale(point, minD, maxD, minR, maxR) { | ||
if (minD === maxD) | ||
return point; | ||
const ratio = (maxR - minR) / (maxD - minD); | ||
return minR + ratio * (point - minD); | ||
} | ||
export function zoom(point, z, centroid) { | ||
const t = point - centroid; | ||
const zoom = z < 0 ? t * 0.9 : t * 1.1; | ||
return zoom + centroid; | ||
} | ||
export function randomColor() { | ||
return `hsla(${Math.floor(Math.random() * 360)}, 100%, 50%, 1)`; | ||
} | ||
export function ticks(min, max, count) { | ||
return d3Ticks(min, max, count); | ||
} | ||
export function throttle(func, limit) { | ||
let inThrottle; | ||
let lastResult; | ||
return function () { | ||
const args = arguments; | ||
const context = this; | ||
if (!inThrottle) { | ||
inThrottle = true; | ||
setTimeout(() => (inThrottle = false), limit); | ||
// @ts-ignore | ||
lastResult = func.apply(context, args); | ||
} | ||
return lastResult; | ||
}; | ||
} |
{ | ||
"name": "@chasi/ui", | ||
"version": "0.2.65", | ||
"version": "0.2.66", | ||
"bin": { | ||
@@ -24,3 +24,3 @@ "gen-theme": "./dist/bin/theme.js" | ||
"./actions": "./dist/Actions/index.js", | ||
"./CGraph": "./dist/CGraph/index.js" | ||
"./utils": "./dist/utils.js" | ||
}, | ||
@@ -27,0 +27,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117597
77