Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7a84590c
Commit
7a84590c
authored
Feb 23, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust label size if value is too long
parent
622c0e0b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
ChartTooltip.tsx
ui/shared/chart/ChartTooltip.tsx
+18
-8
ChartWidgetGraph.tsx
ui/shared/chart/ChartWidgetGraph.tsx
+0
-1
No files found.
ui/shared/chart/ChartTooltip.tsx
View file @
7a84590c
...
@@ -9,7 +9,6 @@ import type { Pointer } from 'ui/shared/chart/utils/pointerTracker';
...
@@ -9,7 +9,6 @@ import type { Pointer } from 'ui/shared/chart/utils/pointerTracker';
import
{
trackPointer
}
from
'
ui/shared/chart/utils/pointerTracker
'
;
import
{
trackPointer
}
from
'
ui/shared/chart/utils/pointerTracker
'
;
interface
Props
{
interface
Props
{
chartId
?:
string
;
width
?:
number
;
width
?:
number
;
tooltipWidth
?:
number
;
tooltipWidth
?:
number
;
height
?:
number
;
height
?:
number
;
...
@@ -23,8 +22,9 @@ const TEXT_LINE_HEIGHT = 12;
...
@@ -23,8 +22,9 @@ const TEXT_LINE_HEIGHT = 12;
const
PADDING
=
16
;
const
PADDING
=
16
;
const
LINE_SPACE
=
10
;
const
LINE_SPACE
=
10
;
const
POINT_SIZE
=
16
;
const
POINT_SIZE
=
16
;
const
LABEL_WIDTH
=
80
;
const
ChartTooltip
=
({
chartId
,
xScale
,
yScale
,
width
,
tooltipWidth
,
height
,
data
,
anchorEl
,
...
props
}:
Props
)
=>
{
const
ChartTooltip
=
({
xScale
,
yScale
,
width
,
tooltipWidth
=
200
,
height
,
data
,
anchorEl
,
...
props
}:
Props
)
=>
{
const
lineColor
=
useToken
(
'
colors
'
,
'
gray.400
'
);
const
lineColor
=
useToken
(
'
colors
'
,
'
gray.400
'
);
const
titleColor
=
useToken
(
'
colors
'
,
'
blue.100
'
);
const
titleColor
=
useToken
(
'
colors
'
,
'
blue.100
'
);
const
textColor
=
useToken
(
'
colors
'
,
'
white
'
);
const
textColor
=
useToken
(
'
colors
'
,
'
white
'
);
...
@@ -78,13 +78,23 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
...
@@ -78,13 +78,23 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
);
);
const
updateDisplayedValue
=
React
.
useCallback
((
d
:
TimeChartItem
,
i
:
number
)
=>
{
const
updateDisplayedValue
=
React
.
useCallback
((
d
:
TimeChartItem
,
i
:
number
)
=>
{
d3
.
selectAll
(
`
${
chartId
?
`#
${
chartId
}
`
:
''
}
.ChartTooltip__value`
)
const
nodes
=
d3
.
select
(
ref
.
current
)
.
selectAll
<
Element
,
TimeChartData
>
(
'
.ChartTooltip__value
'
)
.
filter
((
td
,
tIndex
)
=>
tIndex
===
i
)
.
filter
((
td
,
tIndex
)
=>
tIndex
===
i
)
.
text
(
.
text
(
(
data
[
i
].
valueFormatter
?.(
d
.
value
)
||
d
.
value
.
toLocaleString
())
+
(
data
[
i
].
valueFormatter
?.(
d
.
value
)
||
d
.
value
.
toLocaleString
())
+
(
data
[
i
].
units
?
`
${
data
[
i
].
units
}
`
:
''
),
(
data
[
i
].
units
?
`
${
data
[
i
].
units
}
`
:
''
),
);
)
},
[
data
,
chartId
]);
.
nodes
();
const
widthLimit
=
tooltipWidth
-
2
*
PADDING
-
LABEL_WIDTH
;
const
width
=
nodes
.
map
((
node
)
=>
node
?.
getBoundingClientRect
?.().
width
);
const
maxNodeWidth
=
Math
.
max
(...
width
);
d3
.
select
(
ref
.
current
)
.
select
(
'
.ChartTooltip__contentBg
'
)
.
attr
(
'
width
'
,
tooltipWidth
+
Math
.
max
(
0
,
(
maxNodeWidth
-
widthLimit
)));
},
[
data
,
tooltipWidth
]);
const
drawPoints
=
React
.
useCallback
((
x
:
number
)
=>
{
const
drawPoints
=
React
.
useCallback
((
x
:
number
)
=>
{
const
xDate
=
xScale
.
invert
(
x
);
const
xDate
=
xScale
.
invert
(
x
);
...
@@ -233,7 +243,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
...
@@ -233,7 +243,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
rx=
{
12
}
rx=
{
12
}
ry=
{
12
}
ry=
{
12
}
fill=
{
bgColor
}
fill=
{
bgColor
}
width=
{
tooltipWidth
||
200
}
width=
{
tooltipWidth
}
height=
{
2
*
PADDING
+
(
data
.
length
+
1
)
*
TEXT_LINE_HEIGHT
+
data
.
length
*
LINE_SPACE
}
height=
{
2
*
PADDING
+
(
data
.
length
+
1
)
*
TEXT_LINE_HEIGHT
+
data
.
length
*
LINE_SPACE
}
/>
/>
<
g
transform=
{
`translate(${ PADDING },${ PADDING })`
}
>
<
g
transform=
{
`translate(${ PADDING },${ PADDING })`
}
>
...
@@ -249,7 +259,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
...
@@ -249,7 +259,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
</
text
>
</
text
>
<
text
<
text
className=
"ChartTooltip__contentDate"
className=
"ChartTooltip__contentDate"
transform=
"translate(80,0)"
transform=
{
`translate(${ LABEL_WIDTH },0)`
}
fontSize=
"12px"
fontSize=
"12px"
fontWeight=
"500"
fontWeight=
"500"
fill=
{
textColor
}
fill=
{
textColor
}
...
@@ -272,7 +282,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
...
@@ -272,7 +282,7 @@ const ChartTooltip = ({ chartId, xScale, yScale, width, tooltipWidth, height, da
{
name
}
{
name
}
</
text
>
</
text
>
<
text
<
text
transform=
"translate(80,0)"
transform=
{
`translate(${ LABEL_WIDTH },0)`
}
className=
"ChartTooltip__value"
className=
"ChartTooltip__value"
fontSize=
"12px"
fontSize=
"12px"
fill=
{
textColor
}
fill=
{
textColor
}
...
...
ui/shared/chart/ChartWidgetGraph.tsx
View file @
7a84590c
...
@@ -122,7 +122,6 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
...
@@ -122,7 +122,6 @@ const ChartWidgetGraph = ({ isEnlarged, items, onZoom, isZoomResetInitial, title
<
ChartOverlay
ref=
{
overlayRef
}
width=
{
innerWidth
}
height=
{
innerHeight
}
>
<
ChartOverlay
ref=
{
overlayRef
}
width=
{
innerWidth
}
height=
{
innerHeight
}
>
<
ChartTooltip
<
ChartTooltip
chartId=
{
chartId
}
anchorEl=
{
overlayRef
.
current
}
anchorEl=
{
overlayRef
.
current
}
width=
{
innerWidth
}
width=
{
innerWidth
}
tooltipWidth=
{
isGroupedValues
?
280
:
200
}
tooltipWidth=
{
isGroupedValues
?
280
:
200
}
...
...
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