Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sascha Herzinger
AdaCharts
Commits
fc27b6d2
Commit
fc27b6d2
authored
Jan 29, 2019
by
Sascha Herzinger
Browse files
tooltip map
parent
465c75c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/assets/css/scatterplot.css
View file @
fc27b6d2
...
...
@@ -9,7 +9,7 @@
}
.ac-scatter-invisible-canvas
{
visibility
:
hidden
;
}
.ac-scatter-svg
{
...
...
src/charts/impl/Scatterplot.js
View file @
fc27b6d2
...
...
@@ -19,6 +19,8 @@ export default class extends Chart {
.
append
(
'
g
'
);
this
.
values
=
[];
this
.
callback
=
()
=>
{};
this
.
colorToTooltipMap
=
{};
}
static
get
name
()
{
...
...
@@ -121,9 +123,13 @@ export default class extends Chart {
.
attr
(
'
class
'
,
'
ac-scatter-brush
'
)
.
call
(
brush
);
this
.
svg
.
on
(
'
mousemove
'
,
function
()
{
const
[
xPos
,
yPos
]
=
d3
.
mouse
(
this
);
this
.
hiddenCanvas
this
.
svg
.
on
(
'
mousemove
'
,
(
d
,
i
,
nodes
)
=>
{
const
[
xPos
,
yPos
]
=
d3
.
mouse
(
nodes
[
i
]);
const
ctx
=
this
.
hiddenCanvas
.
node
().
getContext
(
'
2d
'
);
const
[
r
,
g
,
b
]
=
ctx
.
getImageData
(
xPos
,
yPos
,
1
,
1
).
data
;
const
tooltip
=
this
.
colorToTooltipMap
[
`
${
r
}
:
${
g
}
:
${
b
}
`
];
if
(
typeof
tooltip
===
'
undefined
'
)
return
;
// background color
});
const
point
=
this
.
memory
.
selectAll
(
'
.ac-scatter-point
'
)
...
...
@@ -134,7 +140,12 @@ export default class extends Chart {
.
attr
(
'
dx
'
,
d
=>
x
(
d
[
0
]))
.
attr
(
'
dy
'
,
d
=>
y
(
d
[
1
]))
.
attr
(
'
r
'
,
Math
.
ceil
(
width
/
200
))
.
attr
(
'
fillStyle
'
,
d
=>
color
(
d
[
2
]));
.
attr
(
'
fillStyle
'
,
d
=>
color
(
d
[
2
]))
.
attr
(
'
title
'
,
d
=>
`
${
d
[
0
]}
</br>
${
d
[
1
]}
</br>
${
d
[
2
]}
</br>
`
);
point
.
exit
()
.
remove
();
...
...
@@ -142,7 +153,7 @@ export default class extends Chart {
const
nodes
=
this
.
memory
.
selectAll
(
'
circle
'
).
nodes
();
const
ctx
=
this
.
canvas
.
node
().
getContext
(
'
2d
'
);
const
hiddenCtx
=
this
.
hiddenCanvas
.
node
().
getContext
(
'
2d
'
);
this
.
colorToTooltipMap
=
{};
ctx
.
clearRect
(
0
,
0
,
width
,
height
);
hiddenCtx
.
clearRect
(
0
,
0
,
width
,
height
);
nodes
.
forEach
((
node
,
i
)
=>
{
...
...
@@ -160,12 +171,14 @@ export default class extends Chart {
ctx
.
fill
();
// draw invisible square with unique color
const
colorCode
=
i
+
1
;
// eslint-disable-next-line no-bitwise
const
r
=
i
>>
16
;
const
r
=
colorCode
>>
16
;
// eslint-disable-next-line no-bitwise
const
g
=
i
-
(
r
<<
16
)
>>
8
;
const
g
=
colorCode
-
(
r
<<
16
)
>>
8
;
// eslint-disable-next-line no-bitwise
const
b
=
i
-
(
r
<<
16
)
-
(
g
<<
8
);
const
b
=
colorCode
-
(
r
<<
16
)
-
(
g
<<
8
);
this
.
colorToTooltipMap
[
`
${
r
}
:
${
g
}
:
${
b
}
`
]
=
node
.
getAttribute
(
'
title
'
);
hiddenCtx
.
fillStyle
=
`rgb(
${
r
}
,
${
g
}
,
${
b
}
)`
;
hiddenCtx
.
fillRect
(
parseInt
(
node
.
getAttribute
(
'
dx
'
)
-
node
.
getAttribute
(
'
r
'
),
10
),
...
...
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