comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/GraphicsRenderingModule/GraphicsRenderingModule.20-Renderer.similarity-plane.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-plane",
9 inherit: "_",
10
11 defaultVegaConfig: {
12 comparisonMode: null,
13
14 symbolSize: 20,
15 internalSpaceOffset: 6,
16 colorForData: "#3182bd",
17
18 padding: {"top": 10, "left": 10, "bottom": 10, "right": 10},
19 },
20
21
22 _formVC: function(vc, data) {
23 vc.enoughSpaceForAxisLabels = vc.totalWidth > 200;
24 vc.width = vc.totalWidth - vc.padding.left - vc.padding.right;
25 vc.height = vc.totalHeight - vc.padding.top - vc.padding.bottom;
26
27 var stats = {
28 mds: [],
29 list: []
30 }
31 if (data.self.stats) {
32 data.self.stats = stats
33 }
34 var recordingCount = stats.list.length;
35
36 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
37 // Data
38 var mds = stats.mds;
39 var list = stats.list;
40
41 // .............................................................
42 // Data - points
43 var pointsInVegaData = [];
44 for (var i = 0; i < recordingCount; ++i) {
45 var pointInVegaData = {
46 x: mds[i][0],
47 y: mds[i][1]
48 };
49 pointInVegaData.tooltip = list[i].label;
50 // + "<br/>x: " + GraphicsRenderingModule._formatNumberForTooltip(pointInVegaData.x)
51 // + "<br/>y: " + GraphicsRenderingModule._formatNumberForTooltip(pointInVegaData.y)
52
53 pointsInVegaData.push(pointInVegaData);
54 }
55
56 vc.data.push({
57 "name": "points",
58 "values": pointsInVegaData
59 });
60
61
62 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
63 // Scales
64
65 // .............................................................
66 // Scale - x
67 vc.scales.push({
68 "name": "x",
69 "domain": {"data": "points", "field": "x"},
70 "point": true,
71 "round": true,
72 "zero": true,
73 "range": [vc.internalSpaceOffset, vc.width - vc.internalSpaceOffset]
74 });
75
76 // .............................................................
77 // Scale - y
78 vc.scales.push({
79 "name": "y",
80 "domain": {"data": "points", "field": "y"},
81 "point": true,
82 "round": true,
83 "zero": true,
84 "inverse": true,
85 "range": [vc.internalSpaceOffset, vc.height - vc.internalSpaceOffset]
86 });
87
88
89 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
90 // Marks
91
92 // .............................................................
93 // Mark - background (to catch mouse events and remove tooltips)
94 vc.marks.push({
95 "type": "rect",
96 "properties": {
97 "enter": {
98 "x": {"value": -vc.padding.left},
99 "y": {"value": -vc.padding.top},
100 "fill": {"value": "#fff"},
101 "y2": {"field": {"group": "height"}, "offset": vc.padding.left + vc.padding.right},
102 "x2": {"field": {"group": "width"}, "offset": vc.padding.top + vc.padding.bottom},
103 }
104 }
105 });
106
107
108 // .............................................................
109 // Mark - frame
110 vc.marks.push({
111 "type": "rect",
112 "properties": {
113 "enter": {
114 "y": {"value": 0, "offset": .5},
115 "y2": {"field": {"group": "height"}, "offset": -.5},
116 "x": {"value": 0, "offset": .5},
117 "x2": {"field": {"group": "width"}, "offset": -.5},
118 "stroke": {"value": vc.colorForAxes},
119 "strokeWidth": {"value": 1},
120 // "x": {"value": 0, "scale": "x" "offset": -1},
121 // "width": {"value": 1},
122 }
123 }
124 });
125
126 // .............................................................
127 // Mark - x axis
128 // vc.marks.push({
129 // "type": "rect",
130 // "properties": {
131 // "enter": {
132 // "x": {"value": 0},
133 // "x2": {"field": {"group": "width"}},
134 // "fill": {"value": vc.colorForAxes},
135 // "y": {"value": 0, "scale": "y"},
136 // "height": {"value": 1},
137 // }
138 // }
139 // });
140
141
142 // .............................................................
143 // // Mark - y axis
144 // vc.marks.push({
145 // "type": "rect",
146 // "properties": {
147 // "enter": {
148 // "y": {"value": 0},
149 // "y2": {"field": {"group": "height"}},
150 // "fill": {"value": vc.colorForAxes},
151 // "x": {"value": 0, "scale": "x", "offset": -1},
152 // "width": {"value": 1},
153 // }
154 // }
155 // });
156
157 // .............................................................
158 // Mark - cells
159 vc.marks.push({
160 "type": "symbol",
161 "from": {"data": "points"},
162 "properties": {
163 "enter": {
164 "x": {"field": "x", "scale": "x"},
165 "y": {"field": "y", "scale": "y"},
166 "size": {"value": vc.symbolSize},
167 "fill": {"value": vc.colorForData}
168 }
169 }
170 });
171
172
173 },
174 });
175 });
176 }, Logger);