-
Notifications
You must be signed in to change notification settings - Fork 0
/
urth-caravel-slice.html
125 lines (105 loc) · 4.06 KB
/
urth-caravel-slice.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
<!--
# (c) Copyright Jupyter Development Team
# (c) Copyright IBM Corp. 2016
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<script src="dist/css-theme.entry.js"></script>
<script src="../jquery/dist/jquery.js"></script>
<script src="../d3/d3.js"></script>
<script src="../nvd3/build/nv.d3.js"></script>
<script src="dist/caravel.entry.js"></script>
<!--
Represents a widget that renders a data slice using the caravel library
Example:
```html
<urth-caravel-slice></urth-caravel-slice>
```
@group Urth Caravel
@element urth-caravel-slice
-->
<dom-module id="urth-caravel-slice">
<!-- <link rel="import" type="css" href="../fontawesome/css/font-awesome.min.css"> -->
<link rel="import" type="css" href="../nvd3/build/nv.d3.css" />
<link rel="import" type="css" href="http://192.168.99.100:8081/static/assets/stylesheets/caravel.css" />
<link rel="import" type="css" href="http://192.168.99.100:8081/static/assets/visualizations/nvd3_vis.css" />
<template>
<style>
#content {
display: none;
}
</style>
<link rel="stylesheet" type="text/css" href="../nvd3/build/nv.d3.css" />
<link rel="stylesheet" type="text/css" href="http://192.168.99.100:8081/static/assets/stylesheets/caravel.css" />
<link rel="stylesheet" type="text/css" href="http://192.168.99.100:8081/static/assets/visualizations/nvd3_vis.css" />
<div
id$="{{dataSlice.token}}"
class$="widget viz slice {{dataSlice.form_data.viz_type}}"
data-slice$="{{dataSlice}}"
style="height: 500px;">
<img src="http://192.168.99.100:8081/static/assets/images/loading.gif" class="loading" alt="loading">
<div id$="{{dataSlice.token}}_con" class="slice_container" style="height: 100%; width: 100%"></div>
</div>
<div id="content"><content></content></div>
</template>
<script>
(function () {
'use strict';
Polymer({
is: 'urth-caravel-slice',
properties: {
type: {
type: String
},
dataSlice: {
type: Object,
observer: '_dataSliceChanged'
}
},
behaviors: [
Polymer.IronResizableBehavior
],
listeners: {
'iron-resize': '_resize'
},
/*
observers: [
'_dataSliceDeep(dataSlice.*)'
],
_dataSliceDeep: function(change) {
if (change.path == 'dataSlice') { return; }
this.$$('#' + this.dataSlice.token).setAttribute('data-slice', JSON.stringify(this.dataSlice));
this._dataSliceChanged();
},
*/
_dataSliceChanged: function() {
if (this.slice) {
this.slice.render(false, this.root);
}
},
_resize: function() {
if (this.slice) {
this.slice.resize();
}
},
ready: function() {
var display = window.getComputedStyle(this).display;
if (display === 'none' || document.readyState !== 'complete') {
this.async(this.ready, 200);
return;
}
this.dataSlice = JSON.parse(this.innerText || "{}");
// Dynamically register this visualization
var visType = this.dataSlice.form_data.viz_type;
px.registerViz(visType);
var data = $(this.$$('.slice')).data('slice');
var slice = this.slice = px.Slice(data, undefined, this.root);
$(this.$$('.slice')).data('slice', slice);
// call vis render method, which issues ajax
slice.render(false, this.root);
this.fire('urth-viz-render');
}
});
})();
</script>
</dom-module>