Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
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
david Chavalarias
clinicaltrials
Commits
e013a462
Commit
e013a462
authored
Oct 09, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project explorer test: shuffled array seems more logical than sorting function
parent
a0d7fd82
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
13 deletions
+36
-13
sigmaUtils.js
tinawebJS/sigmaUtils.js
+36
-13
No files found.
tinawebJS/sigmaUtils.js
View file @
e013a462
...
...
@@ -11,7 +11,7 @@ SigmaUtils = function () {
console
.
log
(
catDict
)
for
(
var
i
in
nodes
)
{
var
n
=
nodes
[
i
];
if
(
initialState
[
catDict
[
n
.
type
]])
{
var
node
=
({
id
:
n
.
id
,
...
...
@@ -24,10 +24,10 @@ SigmaUtils = function () {
})
if
(
n
.
shape
)
node
.
shape
=
n
.
shape
;
// console.log(node)
if
(
Number
(
n
.
id
)
==
287
)
console
.
log
(
"coordinates of node 287: ( "
+
n
.
x
+
" , "
+
n
.
y
+
" ) "
)
graph
.
addNode
(
n
.
id
,
node
);
// fill the "labels" global variable
updateSearchLabels
(
n
.
id
,
n
.
label
,
n
.
type
);
}
...
...
@@ -70,7 +70,7 @@ function showMeSomeLabels(N){
minIn
=
50
,
maxIn
=
0
,
minOut
=
50
,
maxOut
=
0
;
maxOut
=
0
;
TW
.
partialGraph
.
iterNodes
(
function
(
n
){
if
(
n
.
hidden
==
false
){
if
(
parseInt
(
n
.
inDegree
)
<
minIn
)
minIn
=
n
.
inDegree
;
...
...
@@ -162,7 +162,7 @@ function find(lquery){
// string.indexOf(substring) faster than search/match
if
(
possiblematch
.
indexOf
(
lquery
)
!==-
1
)
{
results
.
push
(
n
);
}
}
}
}
}
...
...
@@ -199,7 +199,7 @@ function getNodeIDs(elems){
}
function
getSelections
(){
function
getSelections
(){
params
=
[];
for
(
var
i
in
selections
){
params
.
push
(
TW
.
Nodes
[
i
].
label
);
...
...
@@ -210,7 +210,7 @@ function getSelections(){
//This receives an array not a dict!
// i added an excpt... why
function
getNeighs
(
sels
,
arr
)
{
function
getNeighs
(
sels
,
arr
)
{
neighDict
=
{};
for
(
var
i
in
sels
)
{
id
=
sels
[
i
]
...
...
@@ -221,13 +221,13 @@ function getNeighs(sels,arr) {
}
neighDict
[
id
]
=
1
;
}
}
}
return
Object
.
keys
(
neighDict
);
}
//It returns an array not a dict!
//Using bipartiteN2D or bipartiteD2N
//This receives an array not a dict!
function
getNeighs2
(
sels
,
arr
){
function
getNeighs2
(
sels
,
arr
){
neighDict
=
{};
for
(
var
i
in
sels
)
{
id
=
sels
[
i
]
...
...
@@ -238,7 +238,7 @@ function getNeighs2(sels,arr){
}
// neighDict[id]=1;
}
}
}
return
Object
.
keys
(
neighDict
);
}
//It returns an array not a dict!
...
...
@@ -342,7 +342,7 @@ function clustersBy(daclass) {
}
function
colorsBy
(
daclass
)
{
pr
(
""
)
pr
(
" = = = = = = = = = = = = = = = = = "
)
pr
(
" = = = = = = = = = = = = = = = = = "
)
...
...
@@ -359,12 +359,13 @@ function colorsBy(daclass) {
}
var
v_nodes
=
getVisibleNodes
();
colorList
.
sort
(
function
(){
return
Math
.
random
()
-
0.5
;
});
// shuffle on entire array is better than random sorting function on each element
var
randomColorList
=
shuffle
(
colorList
)
for
(
var
i
in
v_nodes
)
{
var
the_node
=
TW
.
Nodes
[
v_nodes
[
i
].
id
]
var
attval
=
(
isUndef
(
the_node
.
attributes
)
||
isUndef
(
the_node
.
attributes
[
daclass
])
)?
v_nodes
[
i
][
daclass
]:
the_node
.
attributes
[
daclass
];
TW
.
partialGraph
.
_core
.
graph
.
nodesIndex
[
v_nodes
[
i
].
id
].
color
=
c
olorList
[
attval
]
TW
.
partialGraph
.
_core
.
graph
.
nodesIndex
[
v_nodes
[
i
].
id
].
color
=
randomC
olorList
[
attval
]
}
TW
.
partialGraph
.
draw
();
...
...
@@ -395,3 +396,25 @@ function makeEdgeWeightUndef() {
TW
.
partialGraph
.
_core
.
graph
.
edges
[
e
].
weight
=
1
;
}
}
// shuffle algo from stackoverflow.com/a/6274398/2489184
function
shuffle
(
array
)
{
var
counter
=
array
.
length
;
// While there are elements in the array
while
(
counter
>
0
)
{
// Pick a random index
let
index
=
Math
.
floor
(
Math
.
random
()
*
counter
);
// Decrease counter by 1
counter
--
;
// And swap the last element with it
let
temp
=
array
[
counter
];
array
[
counter
]
=
array
[
index
];
array
[
index
]
=
temp
;
}
return
array
;
}
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