abstract-chart
Advanced tools
Comparing version 3.2.9 to 5.0.0
@@ -5,3 +5,3 @@ # Change Log | ||
## [Unreleased](https://github.com/promaster-sdk/property/compare/abstract-chart@3.2.3...master) | ||
## [4.0.1](https://github.com/promaster-sdk/property/compare/abstract-chart@3.2.3...master) | ||
@@ -16,2 +16,4 @@ ### Added | ||
- Ramda | ||
## [v3.2.1](https://github.com/promaster-sdk/property/compare/abstract-chart@3.0.0...abstract-chart@3.2.1) - 2022-06-02 | ||
@@ -18,0 +20,0 @@ |
@@ -30,3 +30,3 @@ "use strict"; | ||
max: max, | ||
label: label | ||
label: label, | ||
}; | ||
@@ -40,3 +40,3 @@ } | ||
max: max, | ||
label: label | ||
label: label, | ||
}; | ||
@@ -67,8 +67,7 @@ } | ||
const ticks = cMax - cMin + 1; | ||
if (!best || | ||
Math.abs(best.ticks - desiredTicks) > Math.abs(ticks - desiredTicks)) { | ||
if (!best || Math.abs(best.ticks - desiredTicks) > Math.abs(ticks - desiredTicks)) { | ||
best = { | ||
min: cMin * step, | ||
step: step, | ||
ticks: ticks | ||
ticks: ticks, | ||
}; | ||
@@ -82,3 +81,3 @@ } | ||
const b = best; | ||
return R.range(0, b.ticks).map(l => b.min + b.step * l); | ||
return R.range(0, b.ticks).map((l) => b.min + b.step * l); | ||
} | ||
@@ -92,3 +91,3 @@ exports.getLinearTicks = getLinearTicks; | ||
[0, 1, 2, 3, 5, 8], | ||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
]; | ||
@@ -98,14 +97,12 @@ function getLogarithmicTicks(desiredTicks, min, max) { | ||
const maxPow = Math.ceil(Math.log10(max)) + 1; | ||
const powers = R.range(0, maxPow - minPow + 1).map(p => minPow + p); | ||
const alternatives = logarithmicAlternatives.map(stepAlt => { | ||
const powers = R.range(0, maxPow - minPow + 1).map((p) => minPow + p); | ||
const alternatives = logarithmicAlternatives.map((stepAlt) => { | ||
const altLines = powers.reduce((lines, power) => { | ||
const base = Math.pow(10, power); | ||
const powerLines = stepAlt.map(i => i * base); | ||
const powerLines = stepAlt.map((i) => i * base); | ||
return lines.concat(powerLines); | ||
}, []); | ||
return altLines.filter(l => l >= min && l <= max); | ||
return altLines.filter((l) => l >= min && l <= max); | ||
}); | ||
const bestLines = alternatives.reduce((prev, alt) => Math.abs(alt.length - desiredTicks) < Math.abs(prev.length - desiredTicks) | ||
? alt | ||
: prev); | ||
const bestLines = alternatives.reduce((prev, alt) => Math.abs(alt.length - desiredTicks) < Math.abs(prev.length - desiredTicks) ? alt : prev); | ||
return bestLines; | ||
@@ -156,4 +153,3 @@ } | ||
if (value > 0) { | ||
return ((Math.log10(value) - Math.log10(min)) / | ||
(Math.log10(max) - Math.log10(min))); | ||
return (Math.log10(value) - Math.log10(min)) / (Math.log10(max) - Math.log10(min)); | ||
} | ||
@@ -160,0 +156,0 @@ else if (value < 0) { |
{ | ||
"name": "abstract-chart", | ||
"version": "3.2.9", | ||
"version": "5.0.0", | ||
"description": "Drawing charts using multiple unit of measure axes as coordinate system", | ||
@@ -18,3 +18,3 @@ "repository": "https://github.com/dividab/abstract-visuals/tree/master/packages/abstract-chart", | ||
"dependencies": { | ||
"abstract-image": "^3.4.3", | ||
"abstract-image": "^6.0.0", | ||
"ramda": "^0.22.1", | ||
@@ -26,3 +26,3 @@ "ts-exhaustive-check": "^1.0.0" | ||
}, | ||
"gitHead": "5b368ba880f15586f9a948e914788ff2bb17c2c7" | ||
"gitHead": "a76bd0a1c26c7e19eb07eb5d7c27a8e0eaa0b2ae" | ||
} |
110
src/axis.ts
@@ -13,7 +13,3 @@ import * as R from "ramda"; | ||
export function createLinearAxis( | ||
min: number, | ||
max: number, | ||
label: string | ||
): LinearAxis { | ||
export function createLinearAxis(min: number, max: number, label: string): LinearAxis { | ||
return { | ||
@@ -23,6 +19,8 @@ type: "linear", | ||
max: max, | ||
label: label | ||
label: label, | ||
}; | ||
} | ||
//dummy | ||
export interface LogarithmicAxis { | ||
@@ -35,7 +33,3 @@ readonly type: "logarithmic"; | ||
export function createLogarithmicAxis( | ||
min: number, | ||
max: number, | ||
label: string | ||
): LogarithmicAxis { | ||
export function createLogarithmicAxis(min: number, max: number, label: string): LogarithmicAxis { | ||
return { | ||
@@ -45,3 +39,3 @@ type: "logarithmic", | ||
max: max, | ||
label: label | ||
label: label, | ||
}; | ||
@@ -70,7 +64,3 @@ } | ||
export function getLinearTicks( | ||
desiredTicks: number, | ||
min: number, | ||
max: number | ||
): Array<number> { | ||
export function getLinearTicks(desiredTicks: number, min: number, max: number): Array<number> { | ||
let best: Alternative | undefined; | ||
@@ -85,10 +75,7 @@ for (const power of linearPowers) { | ||
if ( | ||
!best || | ||
Math.abs(best.ticks - desiredTicks) > Math.abs(ticks - desiredTicks) | ||
) { | ||
if (!best || Math.abs(best.ticks - desiredTicks) > Math.abs(ticks - desiredTicks)) { | ||
best = { | ||
min: cMin * step, | ||
step: step, | ||
ticks: ticks | ||
ticks: ticks, | ||
}; | ||
@@ -103,3 +90,3 @@ } | ||
const b = best; | ||
return R.range(0, b.ticks).map(l => b.min + b.step * l); | ||
return R.range(0, b.ticks).map((l) => b.min + b.step * l); | ||
} | ||
@@ -113,26 +100,19 @@ | ||
[0, 1, 2, 3, 5, 8], | ||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
]; | ||
export function getLogarithmicTicks( | ||
desiredTicks: number, | ||
min: number, | ||
max: number | ||
): Array<number> { | ||
export function getLogarithmicTicks(desiredTicks: number, min: number, max: number): Array<number> { | ||
const minPow = Math.floor(Math.log10(min)) - 1; | ||
const maxPow = Math.ceil(Math.log10(max)) + 1; | ||
const powers = R.range(0, maxPow - minPow + 1).map(p => minPow + p); | ||
const alternatives = logarithmicAlternatives.map(stepAlt => { | ||
const powers = R.range(0, maxPow - minPow + 1).map((p) => minPow + p); | ||
const alternatives = logarithmicAlternatives.map((stepAlt) => { | ||
const altLines = powers.reduce((lines: Array<number>, power: number) => { | ||
const base = Math.pow(10, power); | ||
const powerLines = stepAlt.map(i => i * base); | ||
const powerLines = stepAlt.map((i) => i * base); | ||
return lines.concat(powerLines); | ||
}, []); | ||
return altLines.filter(l => l >= min && l <= max); | ||
return altLines.filter((l) => l >= min && l <= max); | ||
}); | ||
const bestLines = alternatives.reduce( | ||
(prev, alt) => | ||
Math.abs(alt.length - desiredTicks) < Math.abs(prev.length - desiredTicks) | ||
? alt | ||
: prev | ||
const bestLines = alternatives.reduce((prev, alt) => | ||
Math.abs(alt.length - desiredTicks) < Math.abs(prev.length - desiredTicks) ? alt : prev | ||
); | ||
@@ -156,8 +136,3 @@ return bestLines; | ||
export function transformValue( | ||
value: number, | ||
min: number, | ||
max: number, | ||
axis: Axis | undefined | ||
): number { | ||
export function transformValue(value: number, min: number, max: number, axis: Axis | undefined): number { | ||
if (!axis) { | ||
@@ -177,8 +152,3 @@ return value; | ||
export function inverseTransformValue( | ||
value: number, | ||
min: number, | ||
max: number, | ||
axis: Axis | undefined | ||
): number { | ||
export function inverseTransformValue(value: number, min: number, max: number, axis: Axis | undefined): number { | ||
if (!axis) { | ||
@@ -192,7 +162,3 @@ return value; | ||
case "logarithmic": | ||
return inverseLogarithmicTransform( | ||
(value - min) / range, | ||
axis.min, | ||
axis.max | ||
); | ||
return inverseLogarithmicTransform((value - min) / range, axis.min, axis.max); | ||
default: | ||
@@ -203,20 +169,9 @@ return 0; | ||
export function linearTransform( | ||
value: number, | ||
min: number, | ||
max: number | ||
): number { | ||
export function linearTransform(value: number, min: number, max: number): number { | ||
return (value - min) / (max - min); | ||
} | ||
export function logarithmicTransform( | ||
value: number, | ||
min: number, | ||
max: number | ||
): number { | ||
export function logarithmicTransform(value: number, min: number, max: number): number { | ||
if (value > 0) { | ||
return ( | ||
(Math.log10(value) - Math.log10(min)) / | ||
(Math.log10(max) - Math.log10(min)) | ||
); | ||
return (Math.log10(value) - Math.log10(min)) / (Math.log10(max) - Math.log10(min)); | ||
} else if (value < 0) { | ||
@@ -229,19 +184,8 @@ return 0.0; | ||
export function inverseLinearTransform( | ||
value: number, | ||
min: number, | ||
max: number | ||
): number { | ||
export function inverseLinearTransform(value: number, min: number, max: number): number { | ||
return min + value * (max - min); | ||
} | ||
export function inverseLogarithmicTransform( | ||
value: number, | ||
min: number, | ||
max: number | ||
): number { | ||
return Math.pow( | ||
10, | ||
value * (Math.log10(max) - Math.log10(min)) + Math.log10(min) | ||
); | ||
export function inverseLogarithmicTransform(value: number, min: number, max: number): number { | ||
return Math.pow(10, value * (Math.log10(max) - Math.log10(min)) + Math.log10(min)); | ||
} |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
99283
1535
+ Addedabstract-image@6.0.1(transitive)
- Removedabstract-image@3.4.3(transitive)
Updatedabstract-image@^6.0.0