Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
43841070
authored
Apr 29, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(charts): enhance tooltip functionality and improve data sorting logic
parent
75af3db1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
33 deletions
+65
-33
web/default/src/features/dashboard/lib/charts.ts
+65
-33
No files found.
web/default/src/features/dashboard/lib/charts.ts
View file @
43841070
...
@@ -9,6 +9,16 @@ import type {
...
@@ -9,6 +9,16 @@ import type {
}
from
'@/features/dashboard/types'
}
from
'@/features/dashboard/types'
type
TFunction
=
(
key
:
string
)
=>
string
type
TFunction
=
(
key
:
string
)
=>
string
type
TooltipLineItem
=
{
key
:
string
value
:
string
|
number
datum
?:
Record
<
string
,
unknown
>
hasShape
?:
boolean
shapeType
?:
string
shapeFill
?:
string
shapeStroke
?:
string
shapeSize
?:
number
}
function
getVChartDefaultColors
(
domainLength
:
number
)
{
function
getVChartDefaultColors
(
domainLength
:
number
)
{
const
scheme
=
const
scheme
=
...
@@ -19,15 +29,6 @@ function getVChartDefaultColors(domainLength: number) {
...
@@ -19,15 +29,6 @@ function getVChartDefaultColors(domainLength: number) {
return
scheme
.
scheme
return
scheme
.
scheme
}
}
function
buildModelColorSpec
(
models
:
string
[])
{
const
domain
=
Array
.
from
(
new
Set
(
models
))
return
{
type
:
'ordinal'
,
domain
,
range
:
getVChartDefaultColors
(
domain
.
length
),
}
}
function
renderQuotaCompat
(
rawQuota
:
number
,
digits
=
4
):
string
{
function
renderQuotaCompat
(
rawQuota
:
number
,
digits
=
4
):
string
{
const
{
config
,
meta
}
=
getCurrencyDisplay
()
const
{
config
,
meta
}
=
getCurrencyDisplay
()
if
(
meta
.
kind
===
'tokens'
)
return
rawQuota
.
toLocaleString
()
if
(
meta
.
kind
===
'tokens'
)
return
rawQuota
.
toLocaleString
()
...
@@ -59,19 +60,24 @@ export function processChartData(
...
@@ -59,19 +60,24 @@ export function processChartData(
const
formatQuotaTotal
=
(
value
:
number
)
=>
renderQuotaCompat
(
value
,
2
)
const
formatQuotaTotal
=
(
value
:
number
)
=>
renderQuotaCompat
(
value
,
2
)
const
MAX_TOOLTIP_MODELS
=
15
const
MAX_TOOLTIP_MODELS
=
15
const
isOtherTooltipKey
=
(
key
:
string
)
=>
key
===
'Other'
||
key
===
otherLabel
const
makeTooltipDimensionUpdateContent
=
(
options
?:
{
collapseOverflow
?:
boolean
})
=>
{
const
collapseOverflow
=
options
?.
collapseOverflow
??
true
return
(
array
:
TooltipLineItem
[])
=>
{
const
modelItems
=
array
.
filter
((
item
)
=>
!
isOtherTooltipKey
(
item
.
key
))
const
otherItems
=
array
.
filter
((
item
)
=>
isOtherTooltipKey
(
item
.
key
))
modelItems
.
sort
(
(
a
,
b
)
=>
(
Number
(
b
.
value
)
||
0
)
-
(
Number
(
a
.
value
)
||
0
)
)
array
=
[...
modelItems
,
...
otherItems
]
const
makeTooltipDimensionUpdateContent
=
()
=>
{
return
(
array
:
Array
<
{
key
:
string
value
:
string
|
number
datum
?:
Record
<
string
,
unknown
>
}
>
)
=>
{
array
.
sort
((
a
,
b
)
=>
(
Number
(
b
.
value
)
||
0
)
-
(
Number
(
a
.
value
)
||
0
))
let
sum
=
0
let
sum
=
0
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
array
[
i
].
key
===
'Other'
||
array
[
i
].
key
===
otherLabel
)
continue
const
v
=
Number
(
array
[
i
].
value
)
||
0
const
v
=
Number
(
array
[
i
].
value
)
||
0
if
(
if
(
array
[
i
].
datum
&&
array
[
i
].
datum
&&
...
@@ -83,20 +89,27 @@ export function processChartData(
...
@@ -83,20 +89,27 @@ export function processChartData(
array
[
i
].
value
=
formatQuotaValue
(
v
)
array
[
i
].
value
=
formatQuotaValue
(
v
)
}
}
if
(
array
.
length
>
MAX_TOOLTIP_MODELS
)
{
if
(
collapseOverflow
&&
array
.
length
>
MAX_TOOLTIP_MODELS
)
{
const
visible
=
array
.
slice
(
0
,
MAX_TOOLTIP_MODELS
)
const
visible
=
modelItems
.
slice
(
0
,
MAX_TOOLTIP_MODELS
)
let
otherSum
=
0
const
otherSum
=
[...
modelItems
.
slice
(
MAX_TOOLTIP_MODELS
),
...
otherItems
]
for
(
let
i
=
MAX_TOOLTIP_MODELS
;
i
<
array
.
length
;
i
++
)
{
.
reduce
((
sum
,
item
)
=>
{
const
raw
=
array
[
i
]
.
datum
const
raw
=
item
.
datum
?
Number
((
array
[
i
]
.
datum
as
Record
<
string
,
unknown
>
)?.
rawQuota
)
||
0
?
Number
((
item
.
datum
as
Record
<
string
,
unknown
>
)?.
rawQuota
)
||
0
:
0
:
0
otherSum
+=
raw
return
sum
+
raw
}
},
0
)
visible
.
push
({
array
=
[
...
visible
,
{
key
:
otherLabel
,
key
:
otherLabel
,
value
:
formatQuotaValue
(
otherSum
),
value
:
formatQuotaValue
(
otherSum
),
})
hasShape
:
true
,
array
=
visible
shapeType
:
'square'
,
shapeFill
:
otherTooltipColor
,
shapeStroke
:
otherTooltipColor
,
shapeSize
:
8
,
},
]
}
}
array
.
unshift
({
array
.
unshift
({
...
@@ -226,7 +239,16 @@ export function processChartData(
...
@@ -226,7 +239,16 @@ export function processChartData(
const
allModels
=
Array
.
from
(
modelTotalsMap
.
keys
())
const
allModels
=
Array
.
from
(
modelTotalsMap
.
keys
())
const
sortedTimes
=
Array
.
from
(
timeModelMap
.
keys
()).
sort
()
const
sortedTimes
=
Array
.
from
(
timeModelMap
.
keys
()).
sort
()
const
sortedModels
=
[...
allModels
].
sort
()
const
sortedModels
=
[...
allModels
].
sort
()
const
modelColor
=
buildModelColorSpec
([...
sortedModels
,
otherLabel
])
const
modelColorDomain
=
Array
.
from
(
new
Set
([...
sortedModels
,
otherLabel
]))
const
modelColorRange
=
getVChartDefaultColors
(
modelColorDomain
.
length
)
const
otherColor
=
modelColorRange
[
modelColorDomain
.
indexOf
(
otherLabel
)]
const
otherTooltipColor
=
typeof
otherColor
===
'string'
?
otherColor
:
'#FF8A00'
const
modelColor
=
{
type
:
'ordinal'
,
domain
:
modelColorDomain
,
range
:
modelColorRange
,
}
// Pad time points if too few (default 7 points)
// Pad time points if too few (default 7 points)
const
MAX_TREND_POINTS
=
MAX_CHART_TREND_POINTS
const
MAX_TREND_POINTS
=
MAX_CHART_TREND_POINTS
...
@@ -508,7 +530,9 @@ export function processChartData(
...
@@ -508,7 +530,9 @@ export function processChartData(
Number
(
datum
?.
rawQuota
)
||
0
,
Number
(
datum
?.
rawQuota
)
||
0
,
},
},
],
],
updateContent
:
makeTooltipDimensionUpdateContent
(),
updateContent
:
makeTooltipDimensionUpdateContent
({
collapseOverflow
:
false
,
}),
},
},
},
},
area
:
{
area
:
{
...
@@ -564,9 +588,17 @@ export function processChartData(
...
@@ -564,9 +588,17 @@ export function processChartData(
value
:
string
|
number
value
:
string
|
number
}
>
}
>
)
=>
{
)
=>
{
array
.
sort
(
const
modelItems
=
array
.
filter
(
(
item
)
=>
!
isOtherTooltipKey
(
item
.
key
)
)
const
otherItems
=
array
.
filter
((
item
)
=>
isOtherTooltipKey
(
item
.
key
)
)
modelItems
.
sort
(
(
a
,
b
)
=>
(
Number
(
b
.
value
)
||
0
)
-
(
Number
(
a
.
value
)
||
0
)
(
a
,
b
)
=>
(
Number
(
b
.
value
)
||
0
)
-
(
Number
(
a
.
value
)
||
0
)
)
)
array
=
[...
modelItems
,
...
otherItems
]
let
sum
=
0
let
sum
=
0
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
const
v
=
Number
(
array
[
i
].
value
)
||
0
const
v
=
Number
(
array
[
i
].
value
)
||
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment