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
Show 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 =
...
@@ -98,5 +98,7 @@ mouseSelectorSizeButton sigmaRef state =
Sigma.setSettings s {
Sigma.setSettings s {
mouseSelectorSize: newValue
mouseSelectorSize: newValue
}
}
here.log "[mouseSelectorSizeButton] write start"
T.write_ newValue state
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) => {
...
@@ -59,41 +59,44 @@ sigma.canvas.nodes.selected = (node, context, settings) => {
//CustomShapes.init();
//CustomShapes.init();
/*
let
sigmaMouseSelector
=
function
(
sigma
,
options
)
{
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
_self
=
this
;
let
_offset
=
null
;
let
_offset
=
null
;
const _s = s;
const
_s
=
sigma
;
const _renderer = renderer;
//const _renderer = renderer;
const _container = _renderer.container;
const
captor
=
sigma
.
mouseCaptor
;
const
_container
=
captor
.
container
;
//renderer.initDOM('canvas', 'mouseSelector');
//renderer.initDOM('canvas', 'mouseSelector');
// A hack to force resize to be called (there is a width/height equality
// A hack to force resize to be called (there is a width/height equality
// check which can't be escaped in any other way).
// 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);
//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
// These are used to prevent using the 'click' event when in fact this was a drag
let
_clickPositionX
=
null
;
let
_clickPositionX
=
null
;
let
_clickPositionY
=
null
;
let
_clickPositionY
=
null
;
let
_isValidClick
=
false
;
let
_isValidClick
=
false
;
_container.onmousemove = function(e) { return mouseMove(e); };
_container
.
onmousemove
=
(
e
)
=>
{
return
mouseMove
(
e
);
};
_context.canvas.onclick = function(e) { return onClick(e); };
_container
.
onclick
=
(
e
)
=>
{
return
onClick
(
e
);
};
_container.onmousedown = function(e) { return onMouseDown(e); }
//_context.canvas.onclick = function(e) { return onClick(e); };
_container.onmouseup = function(e) { return onMouseUp(e); }
_container
.
onmousedown
=
(
e
)
=>
{
return
onMouseDown
(
e
);
}
s.bind('click', function(e) { return onClick(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.
// 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
=
()
=>
{
this
.
unbindAll
=
()
=>
{
// console.log('[sigmaMouseSelector] unbinding');
// console.log('[sigmaMouseSelector] unbinding');
_container
.
onclick
=
null
;
_container
.
onclick
=
null
;
_context.canvas.onmousemove = null;
//_context.canvas.onmousemove = null;
_container
.
onmousemove
=
null
;
_container
.
onmousedown
=
null
;
_container
.
onmousedown
=
null
;
_container
.
onmouseup
=
null
;
_container
.
onmouseup
=
null
;
}
}
...
@@ -115,9 +118,11 @@ let sigmaMouseSelector = function(sigma, options) {
...
@@ -115,9 +118,11 @@ let sigmaMouseSelector = function(sigma, options) {
}
}
const
mouseMove
=
(
e
)
=>
{
const
mouseMove
=
(
e
)
=>
{
const size = _s.settings('mouseSelectorSize') || 3;
const
size
=
sigma
.
settings
[
'mouseSelectorSize'
]
||
3
;
const x = e.clientX + document.body.scrollLeft - _offset.left - size/2;
//const x = e.clientX + document.body.scrollLeft - _offset.left - size/2;
const y = e.clientY + document.body.scrollTop - _offset.top - 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
.
clearRect
(
0
,
0
,
_context
.
canvas
.
width
,
_context
.
canvas
.
height
);
_context
.
fillStyle
=
'rgba(91, 192, 222, 0.7)'
;
_context
.
fillStyle
=
'rgba(91, 192, 222, 0.7)'
;
...
@@ -138,23 +143,31 @@ let sigmaMouseSelector = function(sigma, options) {
...
@@ -138,23 +143,31 @@ let sigmaMouseSelector = function(sigma, options) {
if
(
!
_isValidClick
)
{
if
(
!
_isValidClick
)
{
return
;
return
;
}
}
const size =
_s.settings('mouseSelectorSize')
|| 3;
const
size
=
sigma
.
settings
[
'mouseSelectorSize'
]
||
3
;
const x = e.data.clientX + document.body.scrollLeft - _offset.left - size/2;
//
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 y = e.data.clientY + document.body.scrollTop - _offset.top - size/2;
const prefix = _renderer.options.prefix;
//
const prefix = _renderer.options.prefix;
//console.log('[sigmaMouseSelector] clicked', e, x, y, size);
//console.log('[sigmaMouseSelector] clicked', e, x, y, size);
let
nodes
=
[];
let
nodes
=
[];
_s.graph.nodes().forEach((node) => {
for
(
let
node
in
sigma
.
nodeDataCache
)
{
const nodeX = node[prefix + 'x'];
let
data
=
sigma
.
nodeDataCache
[
node
];
const nodeY = node[prefix + 'y'];
let
position
=
sigma
.
framedGraphToViewport
(
data
);
if(sigma.utils.getDistance(x, y, nodeX, nodeY) <= size) {
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);
nodes.push(node);
}
}
});
});
*/
console
.
log
(
'clicked node ids'
,
nodes
);
//console.log('[sigmaMouseSelector] nodes', nodes);
//console.log('[sigmaMouseSelector] nodes', nodes);
_renderer.dispatchEvent('clickNodes
', {
sigma
.
emit
(
'clickNode
'
,
{
node: nodes
,
node
:
nodes
captor: e.data
//
captor: e.data
})
})
_clickPositionX
=
null
;
_clickPositionX
=
null
;
_clickPositionY
=
null
;
_clickPositionY
=
null
;
...
@@ -179,17 +192,20 @@ let sigmaMouseSelector = function(sigma, options) {
...
@@ -179,17 +192,20 @@ let sigmaMouseSelector = function(sigma, options) {
const
_resizeObserver
=
new
ResizeObserver
(
onContainerResize
);
const
_resizeObserver
=
new
ResizeObserver
(
onContainerResize
);
_resizeObserver
.
observe
(
_container
);
_resizeObserver
.
observe
(
_container
);
}
}
mouseSelector
();
}
}
sigmaMouseSelector(sigma);
//sigmaMouseSelector(sigma);
*/
function
_sigma
(
left
,
right
,
el
,
opts
)
{
function
_sigma
(
left
,
right
,
el
,
opts
)
{
try
{
try
{
let
graph
=
new
Graph
();
let
graph
=
new
Graph
();
console
.
log
(
'initializing sigma with el'
,
el
);
console
.
log
(
'initializing sigma with el'
,
el
);
console
.
log
(
'initializing sigma with opts'
,
opts
);
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
)
{
}
catch
(
e
)
{
return
left
(
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