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
33db9f29
Commit
33db9f29
authored
Apr 19, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coloring: quantiles to find good bin thresholds
parent
5f574220
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
39 deletions
+77
-39
sigmaUtils.js
tinawebJS/sigmaUtils.js
+77
-39
No files found.
tinawebJS/sigmaUtils.js
View file @
33db9f29
...
@@ -202,12 +202,12 @@ SigmaUtils = function () {
...
@@ -202,12 +202,12 @@ SigmaUtils = function () {
var
defSize
=
edge
[
prefix
+
'size'
]
||
settings
(
"minEdgeSize"
)
||
1
;
var
defSize
=
edge
[
prefix
+
'size'
]
||
settings
(
"minEdgeSize"
)
||
1
;
if
(
edge
.
customAttrs
.
activeEdge
)
{
if
(
edge
.
customAttrs
.
activeEdge
)
{
size
=
defSize
*
2
size
=
(
defSize
*
2
)
+
1
// color with no opacity
// color with no opacity
// cf. sigmaTools.edgeRGB
// cf. sigmaTools.edgeRGB
color
=
'rgb('
+
edge
.
customAttrs
.
rgb
+
')'
color
=
'rgb('
+
edge
.
customAttrs
.
rgb
+
')'
// console.log("drawing activeEdge with size", size)
// console.log("drawing activeEdge with size", size)
edge
.
customAttrs
.
activeEdge
=
fals
e
// edge.customAttrs.activeEdge = false // for one-tim
e
}
}
else
if
(
edge
.
customAttrs
.
grey
)
{
else
if
(
edge
.
customAttrs
.
grey
)
{
color
=
TW
.
edgeGreyColor
color
=
TW
.
edgeGreyColor
...
@@ -745,9 +745,7 @@ function clustersBy(daclass) {
...
@@ -745,9 +745,7 @@ function clustersBy(daclass) {
// for debug of colorsRelByBins
// for debug of colorsRelByBins
var
totalsPerBinMin
=
{
var
totalsPerBinMin
=
{}
'-1000000'
:
0
,
'-75'
:
0
,
'-50'
:
0
,
'-25'
:
0
,
'-10'
:
0
,
'10'
:
0
,
'25'
:
0
,
'50'
:
0
,
'75'
:
0
,
'100'
:
0
,
'125'
:
0
,
'150'
:
0
}
// Edge-colour by source-target nodes-colours combination
// Edge-colour by source-target nodes-colours combination
// TODO rm because duplicate with edgeRGB
// TODO rm because duplicate with edgeRGB
...
@@ -775,6 +773,36 @@ function repaintEdges() {
...
@@ -775,6 +773,36 @@ function repaintEdges() {
// /!\ age and growth_rate attributes referred to by name
// /!\ age and growth_rate attributes referred to by name
function
colorsRelByBins
(
daclass
)
{
function
colorsRelByBins
(
daclass
)
{
var
nTicksParam
=
12
// do first loop entirely to get percentiles => bins, then modify alt_color
// estimating ticks
let
ticksArray
=
[]
let
valArray
=
[]
for
(
var
j
=
0
;
j
<
TW
.
nNodes
;
j
++
)
{
let
n
=
TW
.
partialGraph
.
graph
.
nodes
(
TW
.
nodeIds
[
j
])
if
(
!
n
.
hidden
&&
n
.
attributes
&&
n
.
attributes
.
category
==
'terms'
&&
n
.
attributes
[
daclass
]
!=
undefined
)
{
valArray
.
push
(
Number
(
n
.
attributes
[
daclass
]))
}
}
var
len
=
valArray
.
length
for
(
var
l
=
0
;
l
<
nTicksParam
;
l
++
)
{
let
nthVal
=
Math
.
floor
(
len
*
l
/
nTicksParam
)
ticksArray
.
push
(
valArray
[
nthVal
])
}
console
.
info
(
`===|===|===
${
nTicksParam
}
color ticks ===|===|===\n`
,
ticksArray
)
cancelSelection
(
false
);
cancelSelection
(
false
);
// 12 colors
// 12 colors
var
binColors
=
[
var
binColors
=
[
...
@@ -798,15 +826,15 @@ function colorsRelByBins(daclass) {
...
@@ -798,15 +826,15 @@ function colorsRelByBins(daclass) {
// £TODO put colors and thresholds as params or calculate thresholds like eg d3.histogram
// £TODO put colors and thresholds as params or calculate thresholds like eg d3.histogram
if
(
daclass
==
'age'
)
{
if
(
daclass
==
'age'
)
{
tickThresholds
=
[
-
1000000
,
1992
,
1994
,
1996
,
1998
,
2000
,
2002
,
2004
,
2006
,
2008
,
2010
,
2012
,
2014
,
1451606400000
]
tickThresholds
=
ticksArray
// and add a grey color for the first timeperiod
// and add a grey color for the first timeperiod
binColors
.
unshift
(
"#F9F7ED"
)
binColors
.
unshift
(
"#F9F7ED"
)
console
.
log
(
"======> doing AGE"
)
//
console.log("======> doing AGE")
}
}
else
if
(
daclass
==
'growth_rate'
)
{
else
if
(
daclass
==
'growth_rate'
)
{
tickThresholds
=
[
0
,.
001
,.
01
,.
1
,.
5
,
1
,
1.5
,
2
,
2.5
,
3
,
3.5
,
5
,
1000000
]
tickThresholds
=
ticksArray
binColors
[
4
]
=
""
binColors
[
4
]
=
""
binColors
=
[
binColors
=
[
"#005197"
,
//blue binMin -∞
"#005197"
,
//blue binMin -∞
...
@@ -826,46 +854,56 @@ function colorsRelByBins(daclass) {
...
@@ -826,46 +854,56 @@ function colorsRelByBins(daclass) {
}
}
// new strategy
// do first loop entirely to get percentiles => bins, then modify alt_color
// get the nodes
// get the nodes
var
v_nodes
=
getVisibleNodes
();
for
(
var
j
=
0
;
j
<
TW
.
nNodes
;
j
++
)
{
for
(
var
i
in
v_nodes
)
{
let
n
=
TW
.
partialGraph
.
graph
.
nodes
(
TW
.
nodeIds
[
j
])
var
theId
=
v_nodes
[
i
].
id
if
(
!
n
.
hidden
var
theNode
=
TW
.
Nodes
[
theId
]
&&
n
.
attributes
var
attval
=
(
isUndef
(
theNode
.
attributes
)
||
isUndef
(
theNode
.
attributes
[
daclass
])
)?
v_nodes
[
i
][
daclass
]:
theNode
.
attributes
[
daclass
];
&&
n
.
attributes
.
category
==
'terms'
&&
!
isUndef
(
n
.
attributes
[
daclass
])
var
theVal
=
parseFloat
(
attval
)
)
{
var
theVal
=
parseFloat
(
n
.
attributes
[
daclass
])
var
foundBin
=
false
var
foundBin
=
false
console
.
log
(
'theVal:'
,
theVal
)
// console.log('theVal:',theVal)
if
(
!
isNaN
(
theVal
)
)
{
//is float
if
(
!
isNaN
(
theVal
)
)
{
//is float
// iterate over bins
// iterate over bins
for
(
var
j
=
0
;
j
<
tickThresholds
.
length
-
1
;
j
++
)
{
for
(
var
k
=
0
;
k
<
tickThresholds
.
length
-
1
;
k
++
)
{
var
binMin
=
tickThresholds
[
j
]
var
binMin
=
tickThresholds
[
k
]
var
binMax
=
tickThresholds
[(
j
+
1
)]
var
binMax
=
tickThresholds
[(
k
+
1
)]
if
((
theVal
>=
binMin
)
&&
(
theVal
<
binMax
))
{
if
((
theVal
>=
binMin
)
&&
(
theVal
<
binMax
))
{
// TW.partialGraph._core.graph.nodesIndex[theId].binMin = binMin
// TW.partialGraph._core.graph.nodesIndex[n.id].binMin = binMin
// TW.partialGraph._core.graph.nodesIndex[theId].color = binColors[j]
// TW.partialGraph._core.graph.nodesIndex[n.id].color = binColors[j]
TW
.
partialGraph
.
graph
.
nodes
(
theId
).
binMin
=
binMin
TW
.
partialGraph
.
graph
.
nodes
(
n
.
id
).
binMin
=
binMin
TW
.
partialGraph
.
graph
.
nodes
(
theId
).
color
=
binColors
[
j
]
TW
.
partialGraph
.
graph
.
nodes
(
n
.
id
).
color
=
binColors
[
k
]
TW
.
partialGraph
.
graph
.
nodes
(
theId
).
customAttrs
.
alt_color
=
binColors
[
j
]
TW
.
partialGraph
.
graph
.
nodes
(
n
.
id
).
customAttrs
.
alt_color
=
binColors
[
k
]
TW
.
partialGraph
.
graph
.
nodes
(
n
.
id
).
customAttrs
.
handpickedcolor
=
true
foundBin
=
true
totalsPerBinMin
[
binMin
]
++
// £TODO handpickedcolor flag support in sigmaUtils subrenderers
break
foundBin
=
true
// console.log(`theVal ${theVal} => found its bin ${binMin} ... ${binColors[k]}`)
if
(
!
totalsPerBinMin
[
binMin
])
{
totalsPerBinMin
[
binMin
]
=
1
}
}
else
{
totalsPerBinMin
[
binMin
]
++
}
break
}
}
}
if
(
!
foundBin
)
{
if
(
!
foundBin
)
{
TW
.
partialGraph
.
graph
.
nodes
(
theI
d
).
binMin
=
null
TW
.
partialGraph
.
graph
.
nodes
(
n
.
i
d
).
binMin
=
null
TW
.
partialGraph
.
graph
.
nodes
(
theI
d
).
color
=
'#555'
TW
.
partialGraph
.
graph
.
nodes
(
n
.
i
d
).
color
=
'#555'
TW
.
partialGraph
.
graph
.
nodes
(
theI
d
).
customAttrs
.
alt_color
=
'#555'
TW
.
partialGraph
.
graph
.
nodes
(
n
.
i
d
).
customAttrs
.
alt_color
=
'#555'
}
}
}
}
}
}
}
console
.
info
(
'coloring distribution per tick thresholds'
,
totalsPerBinMin
[
binMin
])
// [ Edge-colour by source-target nodes-colours combination ]
// [ Edge-colour by source-target nodes-colours combination ]
// repaintEdges()
// repaintEdges()
...
...
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