Add gradient service

AW-4620
Willem Dantuma 2022-03-16 14:20:08 +01:00
parent b850f5d621
commit 521b882798
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import {IGradientstop } from '../models/gradient'
@Injectable({
providedIn: 'root',
})
export class GradientService {
constructor() {
}
getGradientStyle(gradient:IGradientstop[],portrait:boolean = false ):any {
let gd = '{ "background": "linear-gradient(to ' + (portrait?'bottom':'right') +',';
for(var i=0;i<gradient.length;i++) {
let gs = gradient[i];
if(i>0) gd+=",";
gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;
gd +=` ${gs.relativestop*100}%`
}
gradient.forEach((gs) => {
});
gd+=')"}';
return JSON.parse(gd);
}
}