-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchart-negation.html
189 lines (144 loc) · 7.21 KB
/
chart-negation.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!-- External Polymer Styles/elements dependency -->
<link rel="import" href="bower_components/iron-icons/iron-icons.html">
<link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html">
<!-- Epiviz element dependency -->
<script>
/**
* `ChartRemoveBehavior` object manages the `<epiviz-chart-negation>` element for each chart.
* All charts inherit this behavior to remove itself from DOM.
*
* @polymerBehavior
**/
EpivizChartNegationBehavior = function (superClass) {
return class extends superClass {
constructor() {
super();
}
static get properties() {
return {};
}
get_invert_data(lData) {
var self = this;
var counter = 0;
var invert = 0;
var chartData = new epiviz.measurements.MeasurementHashtable();
var msDataMap = new epiviz.measurements.MeasurementHashtable();
lData.foreach(function(measurement, series, seriesIndex) {
var sumExp = new epiviz.datatypes.PartialSummarizedExperiment();
var rowData = series._container.rowData(measurement);
sumExp.addRowData(rowData);
var featureValues = series._container.values(measurement);
var valData = [];
if(featureValues._values != undefined) {
if (invert == 1) {
featureValues._values.forEach(function(val, i) {
valData[i] = -1 * val;
});
}
else {
featureValues._values.forEach(function(val, i) {
valData[i] = val;
});
}
}
else {
valData = undefined;
}
var newValueData = new epiviz.datatypes.FeatureValueArray(measurement, featureValues._boundaries, featureValues._globalStartIndex, valData);
sumExp.addValues(newValueData);
invert++;
var msData = new epiviz.datatypes.MeasurementGenomicDataWrapper(measurement, sumExp);
msDataMap.put(measurement, msData);
});
// lData.foreach(function(m) {
// // m._maxValue = m._maxValue;
// // m._minValue = -1 * m._maxValue;
// // var msData = new epiviz.datatypes.MeasurementGenomicDataWrapper(m, sumExp);
// msDataMap.put(m, sumExp);
// });
var genomicData = new epiviz.datatypes.MapGenomicData(msDataMap);
return genomicData
}
/**
* Shows the remove element
*/
_showNegationDialog() {
var self = this;
self.isNegation = !self.isNegation;
self._toggleNegationIcon();
if (!self.isNegation) {
self.chartSettings = self._originalSettings
// self.chart.setCustomSettingsValues(self._originalSettings);
self.data = self._originalData
// self.chart.setCustomSettingsValues(self._originalSettings);
// self._draw();
return;
}
if (!self._originalData) {
self._originalData = self.data
}
if (!self._originalSettings) {
self._originalSettings = JSON.parse(JSON.stringify(self.chartSettings))
}
self.chartSettings = JSON.parse(JSON.stringify(self._originalSettings));
if (self.measurements.length == 2) {
// self._negateData = jQuery.extend({}, self._originalData)
// self._negateData._map._order[1].value._container._values._order[0].value._values.forEach(function(k, i) {
// self._negateData._map._order[1].value._container._values._order[0].value._values[i] = -1 * k;
// });
self._negateData = self.get_invert_data(self._originalData);
// self.chartSettings.yMin = -1 * self.chartSettings.yMax;
self.chart.setCustomSettingsValues(self.chartSettings);
self.data = self._negateData;
self._dataChanged();
// var groupByMarker = new epiviz.ui.charts.markers.VisualizationMarker(
// "negation", "negation", "negation",
// "function(data) { return null; }",
// "function(m, data, preMarkResult) { return 'mirror'; }"
// );
// var aggregator = epiviz.ui.charts.markers.MeasurementAggregators["negate"];
// self._negateData = new epiviz.datatypes.MeasurementAggregatedGenomicData(self._originalData, groupByMarker, aggregator);
// self._negateData.ready(function() {
// if (self._negateData.isReady()) {
// // self.chart._lastData = newData;
// // self.chart.draw(self.range, _negateData);
// self.data = self._negateData
// }
// })
}
}
/**
* Initializes the `<epiviz-chart-logratio>` element
*/
_initializeNegationDialog() {
var chartSettingsContainer = this.shadowRoot.querySelector('#chartSettingsContainer');
var chartContainer = this.shadowRoot.querySelector('#' + this.plotId);
var currSettingIcon = this.shadowRoot.querySelector('#chartNegationIcon');
if (currSettingIcon == null) {
var iconElem = document.createElement('button');
iconElem.id = "chartNegationIcon";
iconElem.className = "setIcon";
iconElem.innerHTML = "Mirror Tracks |";
iconElem.title = "mirror ratio";
// iconElem.icon = "icons:announcement";
iconElem.addEventListener("click", this._showNegationDialog.bind(this));
chartSettingsContainer.appendChild(iconElem);
}
}
_toggleNegationIcon() {
var self = this;
var dis1 = this.shadowRoot.querySelector('#chartLogRatioIcon');
var dis2 = this.shadowRoot.querySelector('#chartAverageIcon');
var active = this.shadowRoot.querySelector('#chartNegationIcon');
if(self.isNegation) {
active.style.color = 'blue';
}
else {
active.style.color = 'black';
}
self.isLogRatio = self.isAverage = false;
dis1.style.color = dis2.style.color = 'black';
}
}
}
</script>