mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-23 06:33:00 +00:00
Bugfix: Correct and document GenerateCSSGradient().
This commit is contained in:
parent
7b47e44e03
commit
e5303d62f0
2 changed files with 11 additions and 6 deletions
|
@ -3,19 +3,24 @@
|
||||||
function RenderGradient(stops, max) {
|
function RenderGradient(stops, max) {
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
for(let value in stops) {
|
for(let value in stops)
|
||||||
result[value / max] = stops[value];
|
result[value / max] = stops[value];
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GenerateCSSGradient(stops, max) {
|
/**
|
||||||
|
* Generates a CSS gradient, given the output of RenderGradient().
|
||||||
|
* @param {[string, string]} stops The stops specification to create a css linear-gradient from. Should be the output of RenderGradient().
|
||||||
|
* @returns {string} The rendered CSS linear-gradient.
|
||||||
|
*/
|
||||||
|
function GenerateCSSGradient(stops) {
|
||||||
let stops_processed = [];
|
let stops_processed = [];
|
||||||
for(let value in stops) {
|
for(let value in stops) {
|
||||||
stops_processed = `${stops[value]} ${(value/max).toFixed(3)}%`
|
let valueNumber = parseFloat(value);
|
||||||
|
stops_processed.push(`${stops[value]} ${(valueNumber*100).toFixed(3).replace(/\.?[0]+$/, "")}%`);
|
||||||
}
|
}
|
||||||
return `linear-gradient(to bottom, ${stops_processed.join(", ")})`;
|
return `linear-gradient(to bottom, ${stops_processed.join(", ")})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { RenderGradient };
|
export { RenderGradient, GenerateCSSGradient };
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 617fcdb5b9df7f57ccb6639a87be68238f99b9ed
|
Subproject commit aaa2463547d87e01c650815d0778368cce047b0a
|
Loading…
Reference in a new issue