Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
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
Grégoire Locqueville
purescript-gargantext
Commits
0548858f
Commit
0548858f
authored
Sep 27, 2022
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[sigma] some work on making selector element functional
parent
a6636be4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
33 deletions
+51
-33
SlideButton.purs
...gantext/Components/GraphExplorer/Toolbar/SlideButton.purs
+2
-0
Sigma.js
src/Gargantext/Hooks/Sigmax/Sigma.js
+49
-33
No files found.
src/Gargantext/Components/GraphExplorer/Toolbar/SlideButton.purs
View file @
0548858f
...
...
@@ -98,5 +98,7 @@ mouseSelectorSizeButton sigmaRef state =
Sigma.setSettings s {
mouseSelectorSize: newValue
}
here.log "[mouseSelectorSizeButton] write start"
T.write_ newValue state
here.log "[mouseSelectorSizeButton] write stop"
}
src/Gargantext/Hooks/Sigmax/Sigma.js
View file @
0548858f
...
...
@@ -59,41 +59,44 @@ sigma.canvas.nodes.selected = (node, context, settings) => {
//CustomShapes.init();
/*
let
sigmaMouseSelector
=
function
(
sigma
,
options
)
{
sigma.plugins = sigma.plugins || {}
;
const
distance
=
(
x1
,
y1
,
x2
,
y2
)
=>
Math
.
sqrt
(
Math
.
pow
(
x1
-
x2
,
2
)
+
Math
.
pow
(
y1
-
y2
,
2
))
;
sigma.plugins.mouseSelector = (s, renderer
) => {
let
mouseSelector
=
(
)
=>
{
let
_self
=
this
;
let
_offset
=
null
;
const _s = s;
const _renderer = renderer;
const _container = _renderer.container;
const
_s
=
sigma
;
//const _renderer = renderer;
const
captor
=
sigma
.
mouseCaptor
;
const
_container
=
captor
.
container
;
//renderer.initDOM('canvas', 'mouseSelector');
// A hack to force resize to be called (there is a width/height equality
// check which can't be escaped in any other way).
//renderer.resize(renderer.width - 1, renderer.height - 1);
//renderer.resize(renderer.width + 1, renderer.height + 1);
const _context = _renderer.contexts.mouseSelector;
//const _context = _renderer.contexts.mouseSelector;
const
_context
=
_container
.
getContext
(
'2d'
);
// These are used to prevent using the 'click' event when in fact this was a drag
let
_clickPositionX
=
null
;
let
_clickPositionY
=
null
;
let
_isValidClick
=
false
;
_container.onmousemove = function(e) { return mouseMove(e); };
_context.canvas.onclick = function(e) { return onClick(e); };
_container.onmousedown = function(e) { return onMouseDown(e); }
_container.onmouseup = function(e) { return onMouseUp(e); }
s.bind('click', function(e) { return onClick(e); })
_container
.
onmousemove
=
(
e
)
=>
{
return
mouseMove
(
e
);
};
_container
.
onclick
=
(
e
)
=>
{
return
onClick
(
e
);
};
//_context.canvas.onclick = function(e) { return onClick(e); };
_container
.
onmousedown
=
(
e
)
=>
{
return
onMouseDown
(
e
);
}
_container
.
onmouseup
=
(
e
)
=>
{
return
onMouseUp
(
e
);
}
captor
.
on
(
'click'
,
(
e
)
=>
{
return
onClick
(
e
);
});
// The mouseSelector canvas will pass its events down to the "mouse" canvas.
_context.canvas.style.pointerEvents = 'none';
//
_context.canvas.style.pointerEvents = 'none';
s
.bind
('kill', () => _self.unbindAll());
s
igma
.
on
(
'kill'
,
()
=>
_self
.
unbindAll
());
this
.
unbindAll
=
()
=>
{
// console.log('[sigmaMouseSelector] unbinding');
_container
.
onclick
=
null
;
_context.canvas.onmousemove = null;
//_context.canvas.onmousemove = null;
_container
.
onmousemove
=
null
;
_container
.
onmousedown
=
null
;
_container
.
onmouseup
=
null
;
}
...
...
@@ -115,9 +118,11 @@ let sigmaMouseSelector = function(sigma, options) {
}
const
mouseMove
=
(
e
)
=>
{
const size = _s.settings('mouseSelectorSize') || 3;
const x = e.clientX + document.body.scrollLeft - _offset.left - size/2;
const y = e.clientY + document.body.scrollTop - _offset.top - size/2;
const
size
=
sigma
.
settings
[
'mouseSelectorSize'
]
||
3
;
//const x = e.clientX + document.body.scrollLeft - _offset.left - size/2;
//const y = e.clientY + document.body.scrollTop - _offset.top - size/2;
const
x
=
e
.
layerX
;
const
y
=
e
.
layerY
;
_context
.
clearRect
(
0
,
0
,
_context
.
canvas
.
width
,
_context
.
canvas
.
height
);
_context
.
fillStyle
=
'rgba(91, 192, 222, 0.7)'
;
...
...
@@ -138,23 +143,31 @@ let sigmaMouseSelector = function(sigma, options) {
if
(
!
_isValidClick
)
{
return
;
}
const size =
_s.settings('mouseSelectorSize')
|| 3;
const x = e.data.clientX + document.body.scrollLeft - _offset.left - size/2;
const y = e.data.clientY + document.body.scrollTop - _offset.top - size/2;
const prefix = _renderer.options.prefix;
const
size
=
sigma
.
settings
[
'mouseSelectorSize'
]
||
3
;
//
const x = e.data.clientX + document.body.scrollLeft - _offset.left - size/2;
//
const y = e.data.clientY + document.body.scrollTop - _offset.top - size/2;
//
const prefix = _renderer.options.prefix;
//console.log('[sigmaMouseSelector] clicked', e, x, y, size);
let
nodes
=
[];
_s.graph.nodes().forEach((node) => {
const nodeX = node[prefix + 'x'];
const nodeY = node[prefix + 'y'];
if(sigma.utils.getDistance(x, y, nodeX, nodeY) <= size) {
for
(
let
node
in
sigma
.
nodeDataCache
)
{
let
data
=
sigma
.
nodeDataCache
[
node
];
let
position
=
sigma
.
framedGraphToViewport
(
data
);
if
(
distance
(
e
.
x
,
e
.
y
,
position
.
x
,
position
.
y
)
<=
size
)
{
nodes
.
push
(
node
);
}
}
/*
sigma.graph.forEachNode((node, attrs) => {
if(distance(x, y, attrs.x, attrs.y) <= size) {
nodes.push(node);
}
});
});
*/
console
.
log
(
'clicked node ids'
,
nodes
);
//console.log('[sigmaMouseSelector] nodes', nodes);
_renderer.dispatchEvent('clickNodes
', {
node: nodes
,
captor: e.data
sigma
.
emit
(
'clickNode
'
,
{
node
:
nodes
//
captor: e.data
})
_clickPositionX
=
null
;
_clickPositionY
=
null
;
...
...
@@ -179,17 +192,20 @@ let sigmaMouseSelector = function(sigma, options) {
const
_resizeObserver
=
new
ResizeObserver
(
onContainerResize
);
_resizeObserver
.
observe
(
_container
);
}
mouseSelector
();
}
sigmaMouseSelector(sigma);
*/
//sigmaMouseSelector(sigma);
function
_sigma
(
left
,
right
,
el
,
opts
)
{
try
{
let
graph
=
new
Graph
();
console
.
log
(
'initializing sigma with el'
,
el
);
console
.
log
(
'initializing sigma with opts'
,
opts
);
return
right
(
new
sigma
(
graph
,
el
,
opts
));
let
s
=
new
sigma
(
graph
,
el
,
opts
);
sigmaMouseSelector
(
s
);
return
right
(
s
);
}
catch
(
e
)
{
return
left
(
e
);
}
...
...
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