-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpx-chart-series-bar.html
329 lines (292 loc) · 7.75 KB
/
px-chart-series-bar.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
<link rel="import" href="../polymer/polymer.html"/>
<!--
Element defining a chart series that is displayed as a bar.
### Usage
<px-chart-series-bar data="{{...}}" id="hpt-acc-position-cruise">
</px-chart-series-bar>
For full details on usage, see px-chart-series-line.html. All examples should work for displaying the series as a bar chart
(replacing px-chart-series-line for px-chart-series-bar in all examples).
@demo demo.html
-->
<dom-module id="px-chart-series-bar">
</dom-module>
<script>
Polymer({
is: 'px-chart-series-bar',
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
/**
* The data associated with the series, an Array of Arrays with the first value of each inner Array being a unix
* timestamp and the second value being the value.
*
* Fires a "data-changed" event via the "notify" flag when the data changes, the assumption is that the chart will
* listen for this event.
*
* @type {Array}
*/
data: {
type: Array,
notify: true
},
/**
* Events associated with the series, an Array of Objects with the keys:
*
* * "time" {Number}, a unix timestamp of the event time
* * "id" {String}, unique id of the event
* * "label" {String}, the text label associated with the event
*
* Fires a "dataEvents-changed" event via the "notify" flag when the events changes, the assumption is that the chart will
* listen for this event.
*
* @type {Array}
*/
dataEvents: {
type: Array,
notify: true
},
/**
* Unique id of this series
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
*/
id: {
type: String
},
/**
* Display name of the series, defaults to id
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
*/
name: {
type: String
},
/**
* Units of measure of the series, no default
*
* Currently, Can only be statically configured (not data-bindable).
*
* @type {String}
*/
units: {
type: String
},
/**
* The width of the line for this series
*
* Can only be statically configured (not data-bindable).
*
* @type {Number}
* @default 1
*/
lineWidth : {
type: Number,
value: 1
},
/**
* Config for each plotted point on the line
*
* <px-chart-series marker='{"enabled": false, "radius": 15}'
*
* Can only be statically configured (not data-bindable).
*
* @type {Object}
*/
marker : {
type: Object,
value: {
enabled : false,
radius : 2
}
},
/**
* Config for the tooltip for each point
*
* <px-chart-series id="my-series" tooltip='{"valueDecimals": 3}' ...
*
* Can only be statically configured (not data-bindable).
*
* @type {Object}
*/
tooltip: {
type: Object,
value: {
valueDecimals: 2
}
},
/**
* Optional object that contains members that map to #name and #data via the seriesObjDataKey and seriesObjNameKey,
*
* e.g. seriesObj[seriesObjDataKey] and seriesObj[seriesObjNameKey]
*
* @type {Object}
*/
seriesObj: {
type: Object,
observer: 'seriesObjObserver'
},
/**
* Key in the optional seriesObj to be used for #data
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
* @default "series"
*/
seriesObjDataKey: {
type: String,
value: 'series'
},
/**
* Key in the optional seriesObj to be used for #name
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
* @default "name"
*/
seriesObjNameKey: {
type: String,
value: 'name'
},
/**
* Key in the optional seriesObj to be used for #events
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
* @default "events"
*/
seriesObjDataEventsKey: {
type: String,
value: 'events'
},
/**
* Optional declaration of which y axis id this series should be plotted against, if more than one.
*
* Can only be statically configured (not data-bindable).
*
* @type {String}
*/
axisId: {
type: String
},
/**
* Optional. Upper value beyond which the data should be shown as "above threshold".
*
* Can only be statically configured (not data-bindable).
*
* @type {Number}
*/
upperThreshold: {
type: Number
},
/**
* Optional. Lower value beyond which the data should be shown as "above threshold".
*
* Can only be statically configured (not data-bindable).
*
* @type {Number}
*/
lowerThreshold: {
type: Number
}
/**
* Whether to show this series in the navigator. Default behavior if this property is not set is that the first
* series of the chart is shown unless this flag is set to override.
*
* @type {Boolean}
TODO: implement...but confused by how series are added to the navigator...
showInNavigator: {
type: Boolean
}
*/
},
/**
* Lifecycle callback to look for and register iron-ajax elements configured inside the series. Note that doing so is
* only one way to populate the series with data. You can always set the 'data' or 'series-obj' attributes/properties
* directly from outside this component.
*/
ready: function() {
this.fire("series-ready");
this.seriesReady = true;
//Fire ajax requests, if configured...TODO: make this more declarative, but don't know how to get 'on-response' event declaration of handler to call a function on this parent comp.
var ironAjaxEl = Polymer.dom(this.root).querySelector("iron-ajax");
if (ironAjaxEl) {
this.fireAjax(ironAjaxEl);
}
},
/**
* @private
*/
fireAjax: function(ironAjaxEl) {
var _this = this;
var fireFn = function(ironAjaxEl) {
if (ironAjaxEl.generateRequest && ironAjaxEl.activeRequests) {
ironAjaxEl.addEventListener("response", function(evt) {
_this.seriesObj = evt.detail.response;
});
ironAjaxEl.generateRequest();
}
else {
setTimeout(function() {fireFn(ironAjaxEl)}, 100);
}
};
fireFn(ironAjaxEl);
},
/**
* Observer on the 'seriesObj' property. When called will look at new seriesObj and set the 'data' and 'name'
* values via the configured 'seriesObjDataKey' and 'seriesObjNameKey'
*
* @param newObj
* @param oldObj
*
* @private
*/
seriesObjObserver: function(newObj, oldObj) {
if (!newObj) {
this.data = null;
}
else {
if (newObj[this.seriesObjNameKey]) {
this.name = newObj[this.seriesObjNameKey];
}
this.data = newObj[this.seriesObjDataKey];
if (newObj[this.seriesObjDataEventsKey]) {
this.dataEvents = newObj[this.seriesObjDataEventsKey];
}
}
},
/**
* Builds a returns an object to be passed into highcharts for this series
*
* @return {Object}
*
* @private
*/
buildConfig: function() {
var config = {};
var props = this.properties;
var _this = this;
Object.keys(props).forEach(function(key) {
if (props.hasOwnProperty(key) && key !== "seriesObj" && typeof _this[key] !== "undefined") {
config[key] = _this[key];
}
});
//backfill a few things highcharts expects
if (typeof config.name === "undefined") {
config.name = config.id;
}
config.type = 'column';
return config;
}
});
</script>