Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Cosy-Bio
Drugst.One
plugin
Commits
8d551650
Commit
8d551650
authored
3 years ago
by
Michael Hartung
Browse files
Options
Downloads
Patches
Plain Diff
pie charts color gradient
parent
5cf32039
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/utils.ts
+18
-5
18 additions, 5 deletions
src/app/utils.ts
with
18 additions
and
5 deletions
src/app/utils.ts
+
18
−
5
View file @
8d551650
...
...
@@ -101,7 +101,7 @@ export function rgbToHex(rgb) {
}
// https://stackoverflow.com/questions/1573053/javascript-function-to-convert-color-names-to-hex-codes/47355187#47355187
export
function
standardize
_c
olor
(
str
){
export
function
standardize
C
olor
(
str
){
var
ctx
=
document
.
createElement
(
"
canvas
"
).
getContext
(
"
2d
"
);
ctx
.
fillStyle
=
str
;
return
ctx
.
fillStyle
.
toString
();
...
...
@@ -133,6 +133,19 @@ export function downLoadFile(data: any, type: string, fmt: string) {
a
.
click
();
}
export
function
RGBAtoRGB
(
rgbaString
)
{
const
rgbaStringSplit
=
rgbaString
.
slice
(
5
,
-
1
).
split
(
"
,
"
);
const
RGBA
=
{
red
:
rgbaStringSplit
[
0
],
green
:
rgbaStringSplit
[
1
],
blue
:
rgbaStringSplit
[
2
],
alpha
:
rgbaStringSplit
[
3
]};
// assume white background
const
bg
=
{
red
:
255
,
green
:
255
,
blue
:
255
};
const
RGB
=
{
red
:
undefined
,
green
:
undefined
,
blue
:
undefined
};
const
alpha
=
1
-
RGBA
.
alpha
;
RGB
.
red
=
Math
.
round
((
RGBA
.
alpha
*
(
RGBA
.
red
/
255
)
+
(
alpha
*
(
bg
.
red
/
255
)))
*
255
);
RGB
.
green
=
Math
.
round
((
RGBA
.
alpha
*
(
RGBA
.
green
/
255
)
+
(
alpha
*
(
bg
.
green
/
255
)))
*
255
);
RGB
.
blue
=
Math
.
round
((
RGBA
.
alpha
*
(
RGBA
.
blue
/
255
)
+
(
alpha
*
(
bg
.
blue
/
255
)))
*
255
);
return
`rgb(
${
RGB
.
red
}
,
${
RGB
.
green
}
,
${
RGB
.
blue
}
)`
;
}
export
function
pieChartContextRenderer
({
ctx
,
x
,
y
,
state
:
{
selected
,
hover
},
style
,
label
})
{
console
.
log
(
style
)
ctx
.
drawPieLabel
=
function
(
style
,
x
,
y
,
label
)
{
...
...
@@ -145,7 +158,6 @@ export function pieChartContextRenderer({ ctx, x, y, state: { selected, hover },
ctx
.
drawPie
=
function
(
style
,
x
,
y
)
{
const
total
=
1
;
let
lastend
=
0
;
// draw shadow
if
(
style
.
shadow
)
{
...
...
@@ -157,13 +169,14 @@ export function pieChartContextRenderer({ ctx, x, y, state: { selected, hover },
ctx
.
fillStyle
=
style
.
color
?
style
.
color
:
'
rgba(255, 0, 0, 1)
'
;
// set alpha value to 1
ctx
.
fillStyle
=
ctx
.
fillStyle
.
replace
(
/
[^
,
]
+
(?=\))
/
,
'
1
'
)
// ctx.fillStyle = ctx.fillStyle.replace(/[^,]+(?=\))/, '1')
ctx
.
fillStyle
=
RGBAtoRGB
(
ctx
.
fillStyle
)
ctx
.
strokeStyle
=
"
black
"
;
ctx
.
lineWidth
=
2
;
ctx
.
beginPath
();
ctx
.
moveTo
(
x
,
y
);
var
len
=
style
.
opacity
/
total
*
2
*
Math
.
PI
;
ctx
.
arc
(
x
,
y
,
style
.
size
,
lastend
,
lastend
+
len
,
false
);
const
len
=
style
.
opacity
/
total
*
2
*
Math
.
PI
;
ctx
.
arc
(
x
,
y
,
style
.
size
,
0
,
0
+
len
,
false
);
ctx
.
lineTo
(
x
,
y
);
ctx
.
fill
();
if
(
style
.
opacity
!==
total
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment