Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
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
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
7be4b214
Commit
7be4b214
authored
2 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): extract tooltip logic of chart
parent
36f09b6c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/client/src/components/chart.vue
+2
-41
2 additions, 41 deletions
packages/client/src/components/chart.vue
packages/client/src/scripts/use-chart-tooltip.ts
+50
-0
50 additions, 0 deletions
packages/client/src/scripts/use-chart-tooltip.ts
with
52 additions
and
41 deletions
packages/client/src/components/chart.vue
+
2
−
41
View file @
7be4b214
...
...
@@ -39,7 +39,7 @@ import zoomPlugin from 'chartjs-plugin-zoom';
//import gradient from 'chartjs-plugin-gradient';
import
*
as
os
from
'
@/os
'
;
import
{
defaultStore
}
from
'
@/store
'
;
import
Mk
ChartTooltip
from
'
@/
components/
chart-tooltip
.vue
'
;
import
{
use
ChartTooltip
}
from
'
@/
scripts/use-
chart-tooltip
'
;
const
props
=
defineProps
({
src
:
{
...
...
@@ -160,42 +160,7 @@ const format = (arr) => {
}));
};
const
tooltipShowing
=
ref
(
false
);
const
tooltipX
=
ref
(
0
);
const
tooltipY
=
ref
(
0
);
const
tooltipTitle
=
ref
(
null
);
const
tooltipSeries
=
ref
(
null
);
let
disposeTooltipComponent
;
os
.
popup
(
MkChartTooltip
,
{
showing
:
tooltipShowing
,
x
:
tooltipX
,
y
:
tooltipY
,
title
:
tooltipTitle
,
series
:
tooltipSeries
,
},
{}).
then
(({
dispose
})
=>
{
disposeTooltipComponent
=
dispose
;
});
function
externalTooltipHandler
(
context
)
{
if
(
context
.
tooltip
.
opacity
===
0
)
{
tooltipShowing
.
value
=
false
;
return
;
}
tooltipTitle
.
value
=
context
.
tooltip
.
title
[
0
];
tooltipSeries
.
value
=
context
.
tooltip
.
body
.
map
((
b
,
i
)
=>
({
backgroundColor
:
context
.
tooltip
.
labelColors
[
i
].
backgroundColor
,
borderColor
:
context
.
tooltip
.
labelColors
[
i
].
borderColor
,
text
:
b
.
lines
[
0
],
}));
const
rect
=
context
.
chart
.
canvas
.
getBoundingClientRect
();
tooltipShowing
.
value
=
true
;
tooltipX
.
value
=
rect
.
left
+
window
.
pageXOffset
+
context
.
tooltip
.
caretX
;
tooltipY
.
value
=
rect
.
top
+
window
.
pageYOffset
+
context
.
tooltip
.
caretY
;
}
const
{
handler
:
externalTooltipHandler
}
=
useChartTooltip
();
const
render
=
()
=>
{
if
(
chartInstance
)
{
...
...
@@ -891,10 +856,6 @@ watch(() => [props.src, props.span], fetchAndRender);
onMounted
(()
=>
{
fetchAndRender
();
});
onUnmounted
(()
=>
{
if
(
disposeTooltipComponent
)
disposeTooltipComponent
();
});
/* eslint-enable id-denylist */
</
script
>
...
...
This diff is collapsed.
Click to expand it.
packages/client/src/scripts/use-chart-tooltip.ts
0 → 100644
+
50
−
0
View file @
7be4b214
import
{
onUnmounted
,
ref
}
from
'
vue
'
;
import
*
as
os
from
'
@/os
'
;
import
MkChartTooltip
from
'
@/components/chart-tooltip.vue
'
;
export
function
useChartTooltip
()
{
const
tooltipShowing
=
ref
(
false
);
const
tooltipX
=
ref
(
0
);
const
tooltipY
=
ref
(
0
);
const
tooltipTitle
=
ref
(
null
);
const
tooltipSeries
=
ref
(
null
);
let
disposeTooltipComponent
;
os
.
popup
(
MkChartTooltip
,
{
showing
:
tooltipShowing
,
x
:
tooltipX
,
y
:
tooltipY
,
title
:
tooltipTitle
,
series
:
tooltipSeries
,
},
{}).
then
(({
dispose
})
=>
{
disposeTooltipComponent
=
dispose
;
});
onUnmounted
(()
=>
{
if
(
disposeTooltipComponent
)
disposeTooltipComponent
();
});
function
handler
(
context
)
{
if
(
context
.
tooltip
.
opacity
===
0
)
{
tooltipShowing
.
value
=
false
;
return
;
}
tooltipTitle
.
value
=
context
.
tooltip
.
title
[
0
];
tooltipSeries
.
value
=
context
.
tooltip
.
body
.
map
((
b
,
i
)
=>
({
backgroundColor
:
context
.
tooltip
.
labelColors
[
i
].
backgroundColor
,
borderColor
:
context
.
tooltip
.
labelColors
[
i
].
borderColor
,
text
:
b
.
lines
[
0
],
}));
const
rect
=
context
.
chart
.
canvas
.
getBoundingClientRect
();
tooltipShowing
.
value
=
true
;
tooltipX
.
value
=
rect
.
left
+
window
.
pageXOffset
+
context
.
tooltip
.
caretX
;
tooltipY
.
value
=
rect
.
top
+
window
.
pageYOffset
+
context
.
tooltip
.
caretY
;
}
return
{
handler
,
};
}
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