comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/GraphicsRenderingModule/GraphicsRenderingModule.20-Renderer.similarity-matrix.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 "use strict";
2
3 App.module("GraphicsRenderingModule", function(GraphicsRenderingModule, App, Backbone, Marionette, $, _, Logger) {
4
5 GraphicsRenderingModule.addInitializer(function(options){
6
7 GraphicsRenderingModule.registerRenderer({
8 id: "similarity-matrix",
9 inherit: "_",
10
11 defaultVegaConfig: {
12 comparisonMode: null,
13
14 colorForData: "#3182bd",
15
16 padding: {"top": 5, "left": 0, "bottom": 0, "right": 0},
17 },
18
19
20 _formVC: function(vc, data) {
21 vc.enoughSpaceForAxisLabels = vc.totalWidth > 200;
22 vc.width = vc.totalWidth - vc.padding.left - vc.padding.right;
23 vc.height = vc.totalHeight - vc.padding.top - vc.padding.bottom;
24
25 var stats = {
26 list: [],
27 distance: []
28 }
29 if (data.self.stats) {
30 data.self.stats = stats
31 }
32 var recordingCount = stats.list.length;
33
34
35 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36 // Data
37 var distance = stats.distance;
38 var list = stats.list;
39
40 // .............................................................
41 // Data - cells
42 var cellsInVegaData = [];
43 var maxDistance = 0;
44 for (var column = 0; column < recordingCount; ++column) {
45 for (var row = 0; row < recordingCount; ++row) {
46 var currentDistance = distance[row][column];
47 if (currentDistance < 1E-5) {
48 currentDistance = 0;
49 }
50 var cellInVegaData = {
51 column: column,
52 row: row,
53 nextColumn: column + 1,
54 nextRow: row + 1,
55 distance: currentDistance
56 };
57 if (column != row) {
58 cellInVegaData.tooltip = "↔ " + list[row].label
59 + "<br/>↕   " + list[column].label
60 + "<br/>" + GraphicsRenderingModule._formatNumberForTooltip(cellInVegaData.distance);
61 } else {
62 cellInVegaData.tooltip = list[row].label;
63 }
64
65 cellsInVegaData.push(cellInVegaData);
66 if (cellInVegaData.distance > maxDistance) {
67 maxDistance = cellInVegaData.distance;
68 }
69 }
70 }
71
72 vc.data.push({
73 "name": "cells",
74 "values": cellsInVegaData
75 });
76
77
78 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
79 // Scales
80
81 // .............................................................
82 // Scale - columns
83 vc.scales.push({
84 //"type": "ordinal",
85 "name": "column",
86 "domainMin": 0,
87 "domainMax": recordingCount,
88 "point": true,
89 "round": true,
90 "range": [0, vc.width]
91 });
92
93 // .............................................................
94 // Scale - rows
95 vc.scales.push({
96 //"type": "ordinal",
97 "name": "row",
98 "domainMin": 0,
99 "domainMax": recordingCount,
100 "point": true,
101 "round": true,
102 "range": [0, vc.height]
103 });
104
105 // .............................................................
106 // Scale - fill opacity
107 vc.scales.push({
108 "name": "fillOpacity",
109 "type": "linear",
110 "domain": [0, maxDistance],
111 "point": true,
112 "range": [0, 1]
113 });
114
115
116 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
117 // Marks
118
119 // .............................................................
120 // Mark - background (to catch mouse events and remove tooltips)
121 vc.marks.push({
122 "type": "rect",
123 "properties": {
124 "enter": {
125 "x": {"value": -vc.padding.left},
126 "y": {"value": -vc.padding.top},
127 "fill": {"value": "#fff"},
128 "y2": {"field": {"group": "height"}, "offset": vc.padding.left + vc.padding.right},
129 "x2": {"field": {"group": "width"}, "offset": vc.padding.top + vc.padding.bottom},
130 }
131 }
132 });
133
134
135 // .............................................................
136 // Mark - cells
137
138 vc.marks.push({
139 "type": "rect",
140 "from": {"data": "cells"},
141 "properties": {
142 "enter": {
143 "x": {"field": "column", "scale": "column"},
144 "x2": {"field": "nextColumn", "scale": "column", "offset": -1},
145 "y": {"field": "row", "scale": "row"},
146 "y2": {"field": "nextRow", "scale": "row", "offset": -1},
147 "fill": {"value": vc.colorForData},
148 "fillOpacity": {"field": "distance", "scale": "fillOpacity"},
149 }
150 }
151 });
152
153 },
154 });
155 });
156 }, Logger);