-
Notifications
You must be signed in to change notification settings - Fork 2
/
epiviz-scatter-plot.html
348 lines (297 loc) · 15.8 KB
/
epiviz-scatter-plot.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!-- Polymer dependency -->
<link rel="import" href="bower_components/polymer/polymer-element.html">
<!-- Epiviz imports dependency -->
<!-- <link rel="import" href="bower_components/epiviz-imports/epiviz-common-js.html"> -->
<!-- Epiviz Polymer Behaviors dependency -->
<link rel="import" href="chart-behavior.html">
<link rel="import" href="chart-settings.html">
<link rel="import" href="chart-colors.html">
<link rel="import" href="chart-remove.html">
<link rel="import" href="chart-grid-behavior.html">
<!-- Epiviz Shared css -->
<link rel="import" type="css" href="chart-shared-css.html">
<!--
<h2> Chart Component </h2>
epiviz-chart components are a collection of reusable and extensible visualization components for
genomic data.
An epiviz-chart component requires two attributes to render a visualization on the page
<ul>
<li>data attribute, </li>
<li>dimensions (or columns) from the data attribute to visualize.</li>
</ul>
`<epiviz-scatter-plot>` creates a scatter plot with `dim-s` as x and y axis.
Element attributes are defined in <a href="#epiviz.ChartBehavior">`<epiviz.ChartBehavior>`</a> element.
To create a scatter plot on a HTML page, add
<epiviz-scatter-plot></epiviz-scatter-plot>
@demo demo/index-scatter.html Example page showing a scatter plot
-->
<dom-module id="epiviz-scatter-plot">
<!--<link rel="import" href="bower_components/epiviz-imports/epiviz-common-css.html">-->
<template>
<style include="shared-settings"></style>
<style include="chart-shared-css"></style>
<style>
:host {
width: 100%;
height: 100%;
border: 1px solid black;
border-radius: 5px;
display: inline-block;
transition: width 0.01s, height 0.01s;
resize: vertical;
overflow: auto;
position: relative;
}
</style>
<!-- local DOM goes here -->
<paper-spinner-lite active class="green"></paper-spinner-lite>
<div id="chart" on-mouseover="hostHovered" on-mouseout="hostUnhovered">
<slot name="dragHandle"></slot>
<div id="{{plotId}}"></div>
</div>
</template>
<script>
// Extend Polymer.Element base class
class EpivizScatterPlot extends EpivizChartGridBehavior(EpivizChartRemoveBehavior(EpivizChartColorsBehavior(EpivizChartSettingsBehavior(EpivizChartBehavior(Polymer.Element))))) {
static get is() { return 'epiviz-scatter-plot'; }
static get properties() {
return {
/**
* Default chart properties for scatter plot.
*
* @type {Object}
*/
configSrc: {
type: Object,
notify: true,
value: function () {
epiviz.Config.SETTINGS = {
dataProviders: [
["epiviz.data.WebServerDataProvider", "umd", "https://epiviz-dev.cbcb.umd.edu/api/"]
],
workspacesDataProvider: sprintf('epiviz.data.EmptyResponseDataProvider', 'empty', ''),
useCache: true,
chartSettings: {
default: {
colors: 'd3-category10',
decorations: [
'epiviz.ui.charts.decoration.RemoveChartButton',
'epiviz.ui.charts.decoration.SaveChartButton',
'epiviz.ui.charts.decoration.CustomSettingsButton',
'epiviz.ui.charts.decoration.EditCodeButton',
'epiviz.ui.charts.decoration.ChartColorsButton',
'epiviz.ui.charts.decoration.ChartLoaderAnimation',
'epiviz.ui.charts.decoration.ChartResize'
]
},
plot: {
width: 400,
height: 400,
margins: new epiviz.ui.charts.Margins(15, 30, 30, 15),
decorations: [
'epiviz.ui.charts.decoration.ToggleTooltipButton',
'epiviz.ui.charts.decoration.ChartTooltip',
'epiviz.ui.charts.decoration.ChartFilterCodeButton'
]
},
track: {
width: '100%',
height: 90,
margins: new epiviz.ui.charts.Margins(25, 40, 23, 10),
decorations: [
'epiviz.ui.charts.decoration.ToggleTooltipButton',
'epiviz.ui.charts.decoration.ChartTooltip',
'epiviz.ui.charts.decoration.ChartFilterCodeButton'
]
},
'epiviz.plugins.charts.ScatterPlot': {
margins: new epiviz.ui.charts.Margins(15, 50, 50, 15),
decorations: [
'epiviz.ui.charts.decoration.ChartColorByRowCodeButton'
]
}
},
chartCustomSettings: {
'epiviz.plugins.charts.ScatterPlot': {
circleRadiusRatio: 0.01
}
},
colorPalettes: [
new epiviz.ui.charts.ColorPalette(
['#025167', '#e7003e', '#ffcd00', '#057d9f', '#970026', '#ffe373', '#ff8100'],
'Epiviz v1.0 Colors', 'epiviz-v1'),
new epiviz.ui.charts.ColorPalette(
['#1859a9', '#ed2d2e', '#008c47', '#010101', '#f37d22', '#662c91', '#a11d20', '#b33893'],
'Epiviz v2.0 Bright', 'epiviz-v2-bright'),
new epiviz.ui.charts.ColorPalette(
['#b8d2eb', '#f2aeac', '#d8e4aa', '#cccccc', '#f2d1b0', '#d4b2d3', '#ddb8a9', '#ebbfd9'],
'Epiviz v2.0 Light', 'epiviz-v2-light'),
new epiviz.ui.charts.ColorPalette(
['#599ad3', '#f1595f', '#79c36a', '#727272', '#f9a65a', '#9e66ab', '#cd7058', '#d77fb3'],
'Epiviz v2.0 Medium', 'epiviz-v2-medium'),
new epiviz.ui.charts.ColorPalette(
["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"],
'D3 Category 10', 'd3-category10'),
new epiviz.ui.charts.ColorPalette(
["#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5"],
'D3 Category 20', 'd3-category20'),
new epiviz.ui.charts.ColorPalette(
["#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6"],
'D3 Category 20b', 'd3-category20b'),
new epiviz.ui.charts.ColorPalette(
["#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9"],
'D3 Category 20c', 'd3-category20c'),
new epiviz.ui.charts.ColorPalette(
['#f9a65a', '#599ad3', '#79c36a', '#f1595f', '#727272', '#cd7058', '#d77fb3'],
'Genes Default', 'genes-default'),
new epiviz.ui.charts.ColorPalette(
['#1859a9', '#ed2d2e', '#008c47', '#010101', '#f37d22', '#662c91', '#a11d20', '#b33893'],
'Heatmap Default', 'heatmap-default')
]
};
return epiviz.Config.SETTINGS;
}
},
colorByRegions: {
type: Array,
notify: true
// observer: "_colorByRegionsChanged"
}
}
}
static get observers() {
return [
/* observer array just like 1.x */
]
}
constructor() {
super();
}
connectedCallback() {
super.connectedCallback();
var self = this;
if (self.useDefaultDataProvider) {
self.measurements = self.measurements || [{
'id': 'e027',
'name': 'Expression Colon Cancer',
'type': 'feature',
'datasourceId': 'roadmap_rnaseq',
'datasourceGroup': 'roadmap_rnaseq',
'dataprovider': 'umd',
'formula': null,
'defaultChartType': null,
'annotation': null,
'minValue': -3,
'maxValue': 20,
'metadata': ['probe']
}, {
'id': 'e066',
'name': 'Expression Colon Normal',
'type': 'feature',
'datasourceId': 'roadmap_rnaseq',
'datasourceGroup': 'roadmap_rnaseq',
'dataprovider': 'umd',
'formula': null,
'defaultChartType': null,
'annotation': null,
'minValue': -3,
'maxValue': 20,
'metadata': ['probe']
}];
self.range = self.range || new epiviz.datatypes.GenomicRange("chr11", 80000000, 3000000);
self._measurementsChanged();
var chartMeasMap = {};
chartMeasMap[self.plotId] = self.visConfigSelection.measurements;
var dataProviderFactory = new epiviz.data.DataProviderFactory(self.config);
var dataManager = new epiviz.data.DataManager(self.config, dataProviderFactory);
dataManager.getData(self.range, chartMeasMap, function (id, data) {
self.data = data;
//self._draw();
});
}
self._initializeGrid();
self._measurementsChanged();
}
disconnectedCallback() {
super.connectedCallback();
}
ready() {
super.ready();
this.plotId = self.plotId || this._generatePlotId();
// this.scopeSubtree(this.$.chart, true);
this.config = new epiviz.Config(this.configSrc);
}
/**
* Draws the chart.
*
* @param {Object<epiviz.datatypes.GenomicRange>} range genomic range.
* @param {Object<epiviz.datatypes.MapGenomicData>} data to plot
*/
_draw() {
if(this.data && this.data.measurements().length == this.measurements.length) {
if (this.canvas) {
this.chart.drawCanvas(this.range, this.data);
}
else {
this.chart.draw(this.range, this.data);
}
// if (this.colorByRegions) {
// this._colorByRegionsChanged();
// }
this.shadowRoot.querySelector("paper-spinner-lite").active = false;
}
}
/**
* Creates an instance of the scatter plot chart.
*
* @return {epiviz.plugins.charts.ScatterPlotType} ScatterPlot chart object
*/
_createChart() {
return new epiviz.plugins.charts.ScatterPlotType(new epiviz.Config(this.configSrc));
}
/**
* Color data points on scatterplot by regions
*
* @return {epiviz.plugins.charts.GenesTrackType} BlocksTrack chart object
*/
_colorByRegionsChanged() {
var self = this;
var itemsGroup = self.chart._chartContent.select('.items');
var selection = itemsGroup.selectAll('circle');
var chartRanges = self.colorByRegions;
// self.colorByRegions.forEach(function(region) {
// chartRanges.push(
// region.seqName(),
// region.start(),
// region.end() - region.start());
// });
selection
.each(
/**
* @param {epiviz.ui.charts.ChartObject} d
*/
function (d) {
var circle = d3.select(this);
var dRange = new epiviz.datatypes.GenomicRange(
d.valueItems[0][0].rowItem.seqName(),
d.valueItems[0][0].rowItem.start(),
d.valueItems[0][0].rowItem.end() - d.valueItems[0][0].rowItem.start());
var inRegion = false;
chartRanges.forEach(function (r, i) {
if (dRange.overlapsWith(r)) {
var fill = self.chart.colors().get(i + 1);
circle.style('fill', fill);
inRegion = true;
}
else if (!inRegion && i == chartRanges.length - 1) {
var fill = self.chart.colors().get(0);
circle.style('fill', fill);
inRegion = true;
}
});
});
}
};
customElements.define(EpivizScatterPlot.is, EpivizScatterPlot);
</script>
</dom-module>