| 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362 |
1
1
1
30
30
30
30
13
4
29
11
11
11
11
11
18
1
1
22
22
22
2
44
44
43
32
104
11
43
1
9
11
5
5
1
1
1
1
4
1
1
5
14
14
14
1
1
1
| /*global require, define, console, setTimeout */
/*jslint nomen: true, debug: true */
/**
* @module chartView
*/
define([
"backbone",
"framework",
"highcharts",
"underscore"
],
function (Backbone, $, Highcharts, _) {
"use strict";
/**
* @name module:chartView
* @description Highcharts-extended Backbone.View
* @class Backbone.View
* @requires Backbone
* @requires framework
* @requires Highcharts
* @constructor
* @returns {Function} Backbone.View constructor
*/
var FONTCOLOR = "#000",
BGCOLOR = "#FFF",
LEGENDBORDERCOLOR = "#FFF",
AXISCOLOR = "#777",
GRIDLINECOLOR = "#EEE",
ENW_WIDGET_CLASS = ".enw__widget";
return Backbone.View.extend({
/**
* @name module:chartView#type
* @description Chart type identifier
* @type {string}
*/
type: "spline",
/**
* @name module:chartView#redraw
* @description Delayed chart redraw
* @function
* @param delay {number} delay in ms
* @returns {Object} widget view
*/
redraw: function (delay) {
/* istanbul ignore else */
Eif (this.chart) {
var view = this;
setTimeout(function () {
view.chart.redraw();
}, parseInt(delay, 10) || 50);
}
},
initialize: function () {
this.self = this;
},
/**
* @name module:chartView#getWidget
* @description Returns widget view link
* @function
* @returns {Object} widget view
*/
getWidget: function () {
return this.widget;
},
/**
* @name module:chartView#create
* @description Creates a new highcharts instance
* @param [node] {String|jQuery|DOM_Element} Node selector or this.$el if undefined
* @param [type] {String} Chart type or "spline" if undefined
* @param [options] {Object} Additional options
* @function
* @returns {Object} Highcharts instance
*/
create: function (node, type, options) {
if (!this.chart) {
node = $(node || this.$el);
/* istanbul ignore else */
Eif (node) {
options = $.extend(
true,
{
getWidget: $.proxy(this.getWidget, this),
chart: {
renderTo: node.get(0),
width: node.closest(ENW_WIDGET_CLASS).width()
}
},
this.chartOptions.defaults,
this.chartOptions[type || this.type],
this.options,
options
);
this.chart = new Highcharts.Chart(options);
return this.chart;
}
}
return null;
},
/**
* @name module:chartView#flush
* @description Destroys this.chart instance. View instance is still available
* @function
* @returns {null} null
*/
flush: function () {
this.chart = null;
return null;
},
/**
* @name module:chartView#render
* @description Render template and append to DOM.
* .render() also triggers this.update()
* @function
* @returns view {object} current view instance
*/
render: function (data) {
this.create();
this.update.apply(this, arguments);
return this;
},
/**
* @name module:chartView#update
* @description Updates chart state by new data
* @function
* @returns {boolean} true
*/
update: function () {
return true;
},
/**
* @name module:chartView#updateSeries
* @description Sets data to chart.series specified by index
* @param data {Array}
* @param index {Number}
* @function
* @returns series {Object|Null} updated series or null
*/
updateSeries: function (data, index) {
var k,
series = this.chart.series[index || 0];
if (series) {
if (series.data && series.data.length) {
for (k = 0; k < data.length; k += 1) {
series.data[k].update(data[k], false);
}
} else {
series.update({data: data});
}
return series;
}
return null;
},
/**
* @name module:chartView#updateCol
* @description Updates column type chart
* @param arg {*} Data arguments
* @function
* @returns series {Object|Null} updated series or null
*/
updateCol: function () {
return _.map(arguments, $.proxy(this.updateSeries, this));
},
/**
* @name module:chartView#updatePie
* @description Updates pie type chart
* @param arg {*} Data arguments
* @function
* @returns series {Object|Null} updated series or null
*/
updatePie: function () {
return _.map(arguments, $.proxy(this.updateSeries, this));
},
/**
* @name module:chartView#updateSpline
* @description Updates spline type chart
* @param arg {*} Data arguments
* @function
* @returns series {Object|Null} updated series or null
*/
updateSpline: function () {
var view = this,
l = arguments.length,
i = l,
c = this.chart.series.length;
if (c > l) {
i = c;
while (l < i) {
this.chart.series[i - 1].remove(false);
i -= 1;
}
} else {
while (c < i) {
i -= 1;
this.chart.addSeries({}, false);
}
}
return _.map(arguments, function (i, j) {
var series = view.chart.series[j];
series.update(i.data ? i : {data: i}, false);
return series;
});
},
/**
* @name module:chartView#chartOptions
* @description Chart options extensions
* @property
* @type {object}
*/
chartOptions: {
defaults: {
chart: {
backgroundColor: BGCOLOR
},
credits: { enabled: false },
legend: {
borderColor: LEGENDBORDERCOLOR,
itemStyle: {
fontWeight: "normal"
}
},
title: {
text: '',
style: {
color: FONTCOLOR,
fontSize: 'normal'
}
}
},
column: {
colors: ['#0d233a', '#d4d8e7'], //d4d7e9
chart: {
type: 'column',
height: 300
},
credits: { enabled: false },
legend: { borderColor: '#FFF' },
title: {
text: "",
style: {
color: '#000'
}
},
yAxis: {
title: {
text: 'Показатель, %',
style: {
color: '#777',
fontWeight: 'normal'
}
},
gridLineColor: '#EEE'
},
xAxis: {
title: {
text: 'Параллель',
style: {
color: '#777',
fontWeight: 'normal'
}
}
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
animation: true
}
},
tooltip: {
enabled: true,
formatter: function () {
return '<b>' + this.series.chart.options.series[this.series._i].name +
('-' + this.x).toLowerCase() + '</b><br/>' +
this.y.toPrecision(3) + '%';
}
}
},
spline: {
chart: {
type: 'spline'
},
xAxis: {
type: 'linear',
categories: []
},
yAxis: {
title: {
text: '%',
style: {
color: AXISCOLOR,
fontWeight: 'normal'
}
},
gridLineColor: GRIDLINECOLOR
},
tooltip: {
//enabled: false,
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
this.x + ': ' + this.y.toPrecision(3);
}
},
plotOptions: {
spline: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
},
series: {
cursor: 'pointer',
marker: {
lineWidth: 1
}
}
}
},
pie: {
chart: {
type: 'pie',
height: 280
},
yAxis: {
title: {
text: 'Проценты',
style: {
color: '#777',
fontWeight: 'normal'
}
}
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
tooltip: {
//enabled: false,
formatter: function () {
return '<b>' + this.point.name + '</b><br/>' +
this.y.toPrecision(3) + '%';
}
}
}
}
});
}); |