-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapping.js
73 lines (64 loc) · 2.31 KB
/
mapping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* This file contains code for color and other visual mappings.
*
* Mapping functions are provided by the connectors and are cached here for
* better performance.
*
* Mapping is only the constructor, the global variable MAPPING has to be
* used in order to access mapping functions.
*/
class Mapping {
constructor() { }
/**
* cache RGB colors additionally to hex codes (since canvas views need RGB)
*/
communityRGBcachedConstructor() {
// 18 is the number of colors (see connectorType.js)
const colors = new Array(18).fill(0).map((d, i) => {
const { r, g, b } = lib.hexColorToRGB(this.communityColor(i));
return `rgba(${r}, ${g}, ${b},`;
});
colors[-1] = CONFIG.UI.darkTheme ? "rgba(255,255,255," : "rgba(0,0,0,";
return community => colors[community % colors.length];
};
/**
* Sets the current connector, since it contains the various mapping functions.
*/
setConnector(c) {
this.connector = c;
}
/**
* Updates mappings for the current filter, since min, max, etc. might have
* changed and therefore the mappings have to be adapted.
*/
update(data) {
if (
!CONNECTOR
|| !CONNECTOR.mapNodeColor
|| !CONNECTOR.mapNodeRadius
|| !CONNECTOR.mapNodeOpacity
|| !CONNECTOR.mapLinkWidth
|| !CONNECTOR.mapLinkOpacity
|| !CONNECTOR.mapCommunityColor
) {
// connector not yet ready when page first loads
return;
}
// get current and total maximum node value
const currentMax = data.states ? data.maxState : data.transitionsPerRegion.max;
const totalMax = data.model.additionalData.max || currentMax;
// console.log(`max ${currentMax} tmax ${totalMax}`);
// create node color mapping for current and total maximum
this.nodeColor = CONNECTOR.mapNodeColor(0, currentMax);
this.nodeColorTotal = CONNECTOR.mapNodeColor(0, totalMax);
this.nodeRadius = CONNECTOR.mapNodeRadius(0, currentMax);
this.nodeOpacity = CONNECTOR.mapNodeOpacity(0, currentMax);
// links
this.linkWidth = CONNECTOR.mapLinkWidth(data.transitionWeights.min, data.transitionWeights.max);
this.linkOpacity = CONNECTOR.mapLinkOpacity(data.transitionWeights.min, data.transitionWeights.max);
// communities
this.communityColor = CONNECTOR.mapCommunityColor();
this.communityRGBcached = this.communityRGBcachedConstructor();
this.timelineGradient = CONNECTOR.mapNodeColor(0, 100);
}
}