Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Vũ Hoàng Anh
canifa_note
Commits
0dc37755
Commit
0dc37755
authored
Jul 15, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix hover heatmap
parent
8a91b0ad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
31 deletions
+23
-31
UsageHeatMap.tsx
web/src/components/UsageHeatMap.tsx
+7
-15
consts.ts
web/src/helpers/consts.ts
+1
-1
usage-heat-map.less
web/src/less/usage-heat-map.less
+15
-15
No files found.
web/src/components/UsageHeatMap.tsx
View file @
0dc37755
...
@@ -37,10 +37,8 @@ const UsageHeatMap: React.FC<Props> = () => {
...
@@ -37,10 +37,8 @@ const UsageHeatMap: React.FC<Props> = () => {
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
(
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
));
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
(
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
));
const
[
popupStat
,
setPopupStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
popupRef
=
useRef
<
HTMLDivElement
>
(
null
);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
newStat
:
DailyUsageStat
[]
=
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
);
const
newStat
:
DailyUsageStat
[]
=
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
);
...
@@ -54,18 +52,17 @@ const UsageHeatMap: React.FC<Props> = () => {
...
@@ -54,18 +52,17 @@ const UsageHeatMap: React.FC<Props> = () => {
},
[
memos
]);
},
[
memos
]);
const
handleUsageStatItemMouseEnter
=
useCallback
((
event
:
React
.
MouseEvent
,
item
:
DailyUsageStat
)
=>
{
const
handleUsageStatItemMouseEnter
=
useCallback
((
event
:
React
.
MouseEvent
,
item
:
DailyUsageStat
)
=>
{
setPopupStat
(
item
);
const
tempDiv
=
document
.
createElement
(
"div"
);
if
(
!
popupRef
.
current
)
{
tempDiv
.
className
=
"usage-detail-container pop-up"
;
return
;
}
const
bounding
=
utils
.
getElementBounding
(
event
.
target
as
HTMLElement
);
const
bounding
=
utils
.
getElementBounding
(
event
.
target
as
HTMLElement
);
popupRef
.
current
.
style
.
left
=
bounding
.
left
+
"px"
;
tempDiv
.
style
.
left
=
bounding
.
left
+
"px"
;
popupRef
.
current
.
style
.
top
=
bounding
.
top
-
4
+
"px"
;
tempDiv
.
style
.
top
=
bounding
.
top
-
2
+
"px"
;
tempDiv
.
innerHTML
=
`
${
item
.
count
}
memos on <span className="date-text">
${
new
Date
(
item
.
timestamp
as
number
).
toDateString
()}
</span>`
;
document
.
body
.
appendChild
(
tempDiv
);
},
[]);
},
[]);
const
handleUsageStatItemMouseLeave
=
useCallback
(()
=>
{
const
handleUsageStatItemMouseLeave
=
useCallback
(()
=>
{
setPopupStat
(
null
);
document
.
body
.
querySelectorAll
(
"div.usage-detail-container.pop-up"
).
forEach
((
node
)
=>
node
.
remove
()
);
},
[]);
},
[]);
const
handleUsageStatItemClick
=
useCallback
((
item
:
DailyUsageStat
)
=>
{
const
handleUsageStatItemClick
=
useCallback
((
item
:
DailyUsageStat
)
=>
{
...
@@ -89,11 +86,6 @@ const UsageHeatMap: React.FC<Props> = () => {
...
@@ -89,11 +86,6 @@ const UsageHeatMap: React.FC<Props> = () => {
<
span
className=
"tip-text"
></
span
>
<
span
className=
"tip-text"
></
span
>
<
span
className=
"tip-text"
>
Sat
</
span
>
<
span
className=
"tip-text"
>
Sat
</
span
>
</
div
>
</
div
>
<
div
ref=
{
popupRef
}
className=
{
"usage-detail-container pop-up "
+
(
popupStat
?
""
:
"hidden"
)
}
>
{
popupStat
?.
count
}
memos on
<
span
className=
"date-text"
>
{
new
Date
(
popupStat
?.
timestamp
as
number
).
toDateString
()
}
</
span
>
</
div
>
<
div
className=
"usage-heat-map"
>
<
div
className=
"usage-heat-map"
>
{
allStat
.
map
((
v
,
i
)
=>
{
{
allStat
.
map
((
v
,
i
)
=>
{
const
count
=
v
.
count
;
const
count
=
v
.
count
;
...
...
web/src/helpers/consts.ts
View file @
0dc37755
...
@@ -11,7 +11,7 @@ export const TOAST_ANIMATION_DURATION = 400;
...
@@ -11,7 +11,7 @@ export const TOAST_ANIMATION_DURATION = 400;
export
const
DAILY_TIMESTAMP
=
3600
*
24
*
1000
;
export
const
DAILY_TIMESTAMP
=
3600
*
24
*
1000
;
// tag regex
// tag regex
export
const
TAG_REG
=
/#
(
.
+
?)
/g
;
export
const
TAG_REG
=
/#
(
\S
+
?)
/g
;
// markdown image regex
// markdown image regex
export
const
IMAGE_URL_REG
=
/!
\[
.*
?\]\((
.+
?)\)
/g
;
export
const
IMAGE_URL_REG
=
/!
\[
.*
?\]\((
.+
?)\)
/g
;
...
...
web/src/less/usage-heat-map.less
View file @
0dc37755
...
@@ -55,8 +55,9 @@
...
@@ -55,8 +55,9 @@
}
}
}
}
}
}
}
>
.usage-detail-container {
.usage-detail-container {
@apply fixed left-0 top-0 ml-2 -mt-9 p-2 z-100 -translate-x-1/2 select-none text-white text-xs rounded whitespace-nowrap;
@apply fixed left-0 top-0 ml-2 -mt-9 p-2 z-100 -translate-x-1/2 select-none text-white text-xs rounded whitespace-nowrap;
background-color: rgba(0, 0, 0, 0.8);
background-color: rgba(0, 0, 0, 0.8);
...
@@ -73,5 +74,4 @@
...
@@ -73,5 +74,4 @@
border-right: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 4px solid rgba(0, 0, 0, 0.8);
border-top: 4px solid rgba(0, 0, 0, 0.8);
}
}
}
}
}
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