Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
actual-vt-capstone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danieljk
actual-vt-capstone
Commits
7a8c3205
Unverified
Commit
7a8c3205
authored
1 year ago
by
Neil
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Custom Reports Donut Graph refactor (#2098)
* donut refactor * notes * fixes
parent
6fbf0fdc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
+86
-61
86 additions, 61 deletions
...sktop-client/src/components/reports/graphs/DonutGraph.tsx
upcoming-release-notes/2098.md
+6
-0
6 additions, 0 deletions
upcoming-release-notes/2098.md
with
92 additions
and
61 deletions
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
+
86
−
61
View file @
7a8c3205
import
React
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
css
}
from
'
glamor
'
;
import
{
PieChart
,
Pie
,
Cell
,
Tooltip
,
ResponsiveContainer
}
from
'
recharts
'
;
import
{
PieChart
,
Pie
,
Cell
,
Sector
,
ResponsiveContainer
}
from
'
recharts
'
;
import
{
amountToCurrency
}
from
'
loot-core/src/shared/util
'
;
import
{
theme
}
from
'
../../../style
'
;
import
{
type
CSSProperties
}
from
'
../../../style
'
;
import
Text
from
'
../../common/Text
'
;
import
PrivacyFilter
from
'
../../PrivacyFilter
'
;
import
Container
from
'
../Container
'
;
import
{
type
DataEntity
}
from
'
../entities
'
;
import
numberFormatterTooltip
from
'
../numberFormatter
'
;
type
PayloadItem
=
{
name
:
string
;
value
:
string
;
color
:
string
;
payload
:
{
date
:
string
;
assets
:
number
|
string
;
debt
:
number
|
string
;
networth
:
number
|
string
;
change
:
number
|
string
;
fill
:
string
;
};
};
type
CustomTooltipProps
=
{
active
?:
boolean
;
payload
?:
PayloadItem
[];
label
?:
string
;
};
const
RADIAN
=
Math
.
PI
/
180
;
const
ActiveShape
=
props
=>
{
const
{
cx
,
cy
,
midAngle
,
innerRadius
,
outerRadius
,
startAngle
,
endAngle
,
fill
,
payload
,
percent
,
value
,
}
=
props
;
const
yAxis
=
payload
.
name
??
payload
.
date
;
const
sin
=
Math
.
sin
(
-
RADIAN
*
midAngle
);
const
cos
=
Math
.
cos
(
-
RADIAN
*
midAngle
);
const
sx
=
cx
+
(
innerRadius
-
10
)
*
cos
;
const
sy
=
cy
+
(
innerRadius
-
10
)
*
sin
;
const
mx
=
cx
+
(
innerRadius
-
30
)
*
cos
;
const
my
=
cy
+
(
innerRadius
-
30
)
*
sin
;
const
ex
=
cx
+
(
cos
>=
0
?
1
:
-
1
)
*
yAxis
.
length
*
4
;
const
ey
=
cy
+
8
;
const
textAnchor
=
cos
<=
0
?
'
start
'
:
'
end
'
;
const
CustomTooltip
=
({
active
,
payload
,
label
}:
CustomTooltipProps
)
=>
{
if
(
active
&&
payload
&&
payload
.
length
)
{
return
(
<
div
className
=
{
`
${
css
({
zIndex
:
1000
,
pointerEvents
:
'
none
'
,
borderRadius
:
2
,
boxShadow
:
'
0 1px 6px rgba(0, 0, 0, .20)
'
,
backgroundColor
:
theme
.
menuBackground
,
color
:
theme
.
menuItemText
,
padding
:
10
,
})}
`
}
return
(
<
g
>
<
Sector
cx
=
{
cx
}
cy
=
{
cy
}
innerRadius
=
{
innerRadius
}
outerRadius
=
{
outerRadius
}
startAngle
=
{
startAngle
}
endAngle
=
{
endAngle
}
fill
=
{
fill
}
/>
<
Sector
cx
=
{
cx
}
cy
=
{
cy
}
startAngle
=
{
startAngle
}
endAngle
=
{
endAngle
}
innerRadius
=
{
outerRadius
+
6
}
outerRadius
=
{
outerRadius
+
10
}
fill
=
{
fill
}
/>
<
path
d
=
{
`M
${
sx
}
,
${
sy
}
L
${
mx
}
,
${
my
}
L
${
ex
}
,
${
ey
}
`
}
stroke
=
{
fill
}
fill
=
"none"
/>
<
circle
cx
=
{
ex
}
cy
=
{
ey
}
r
=
{
3
}
fill
=
{
fill
}
stroke
=
"none"
/>
<
text
x
=
{
ex
+
(
cos
<=
0
?
1
:
-
1
)
*
16
}
y
=
{
ey
}
textAnchor
=
{
textAnchor
}
fill
=
{
fill
}
>
{
`
${
yAxis
}
`
}
</
text
>
<
text
x
=
{
ex
+
(
cos
<=
0
?
1
:
-
1
)
*
16
}
y
=
{
ey
}
dy
=
{
18
}
textAnchor
=
{
textAnchor
}
fill
=
{
fill
}
>
{
`
${
value
.
toFixed
(
2
)}
`
}
</
text
>
<
text
x
=
{
ex
+
(
cos
<=
0
?
1
:
-
1
)
*
16
}
y
=
{
ey
}
dy
=
{
36
}
textAnchor
=
{
textAnchor
}
fill
=
"#999"
>
<
div
>
<
div
style
=
{
{
marginBottom
:
10
}
}
>
<
strong
>
{
payload
[
0
].
name
}
</
strong
>
</
div
>
<
div
style
=
{
{
lineHeight
:
1.5
}
}
>
<
PrivacyFilter
>
<
Text
style
=
{
{
color
:
payload
[
0
].
payload
.
fill
}
}
>
{
amountToCurrency
(
payload
[
0
].
value
)
}
</
Text
>
</
PrivacyFilter
>
</
div
>
</
div
>
</
div
>
);
}
{
`(
${(
percent
*
100
).
toFixed
(
2
)}
%)`
}
</
text
>
</
g
>
);
};
type
DonutGraphProps
=
{
...
...
@@ -90,6 +110,12 @@ function DonutGraph({
}
};
const
[
activeIndex
,
setActiveIndex
]
=
useState
(
0
);
const
onPieEnter
=
(
_
,
index
)
=>
{
setActiveIndex
(
index
);
};
return
(
<
Container
style
=
{
{
...
...
@@ -103,18 +129,17 @@ function DonutGraph({
<
div
>
{
!
compact
&&
<
div
style
=
{
{
marginTop
:
'
15px
'
}
}
/>
}
<
PieChart
width
=
{
width
}
height
=
{
height
}
>
<
Tooltip
content
=
{
<
CustomTooltip
/>
}
formatter
=
{
numberFormatterTooltip
}
isAnimationActive
=
{
false
}
/>
<
Pie
activeIndex
=
{
activeIndex
}
activeShape
=
{
ActiveShape
}
dataKey
=
{
val
=>
getVal
(
val
)
}
nameKey
=
{
yAxis
}
isAnimationActive
=
{
false
}
data
=
{
data
[
splitData
]
}
innerRadius
=
{
Math
.
min
(
width
,
height
)
*
0.2
}
fill
=
"#8884d8"
labelLine
=
{
false
}
onMouseEnter
=
{
onPieEnter
}
>
{
data
.
legend
.
map
((
entry
,
index
)
=>
(
<
Cell
key
=
{
`cell-
${
index
}
`
}
fill
=
{
entry
.
color
}
/>
...
...
This diff is collapsed.
Click to expand it.
upcoming-release-notes/2098.md
0 → 100644
+
6
−
0
View file @
7a8c3205
---
category
:
Enhancements
authors
:
[
carkom
]
---
Changing the view and functions for donut graph in custom reports.
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