Completed
Push — master ( 684a71...5716d7 )
by Chris
01:36
created

jsondash.handlers.handleWordCloud   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 46
rs 8.9411
nc 1
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B 0 43 1
1
/** global: jsondash */
2
/** global: c3 */
3
/** global: d3 */
4
/** global: venn */
5
/** global: Plotly */
6
7
jsondash.getJSON = function(container, url, callback) {
8
    if(!url) throw new Error('Invalid URL: ' + url);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9
    d3.json(url, function(error, data){
10
        if(error) {
11
            jsondash.unload(container);
12
            throw new Error("Could not load url: " + url);
13
        }
14
        callback(error, data);
15
    });
16
};
17
18
/**
19
 * Handlers for various widget types. The method signatures are always the same,
20
 * but each handler can handle them differently.
21
 */
22
23
jsondash.handlers.handleYoutube = function(container, config) {
24
    // Clean up all previous.
25
    'use strict';
26
    container.selectAll('iframe').remove();
27
28
    function getAttr(prop, props) {
29
        // Return the propery from a list of properties for the iframe.
30
        // e.g. getAttr('width', ["width="900""]) --> "900"
31
        return props.filter(function(k, v){
0 ignored issues
show
Unused Code introduced by
The parameter v is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
32
            return k.startsWith(prop);
33
        })[0];
34
    }
35
36
    var url = config.dataSource;
0 ignored issues
show
Unused Code introduced by
The assignment to variable url seems to be never used. Consider removing it.
Loading history...
37
    var parts = config.dataSource.split(' ');
38
    var height = parseInt(getAttr('height', parts).split('=')[1].replace(/"/gi, ''), 10);
39
    var width = parseInt(getAttr('width', parts).split('=')[1].replace(/"/gi, ''), 10);
40
    var url = getAttr('src', parts).replace('src=', '').replace(/"/gi, '');
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable url already seems to be declared on line 36. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
41
42
    // In the case of YouTube, we have to override the config dimensions
43
    // as this will be wonky when the aspect ratio is calculated. We will
44
    // defer to YouTube calculations instead.
45
    container.append('iframe')
46
        .attr('width', width)
47
        .attr('height', height)
48
        .attr('src', url)
49
        .attr('allowfullscreen', true)
50
        .attr('frameborder', 0);
51
    // Look for callbacks potentially registered for third party code.
52
    jsondash.api.runCallbacks(container, config);
53
    jsondash.unload(container);
54
};
55
56
/**
57
 * [handleGraph creates graphs using the dot format
58
 * spec with d3 and dagre-d3]
59
 */
60
jsondash.handlers.handleGraph = function(container, config) {
61
    'use strict';
62
    jsondash.getJSON(container, config.dataSource, function(error, data){
63
        container.selectAll('.chart-graph').remove();
64
        var h = config.height - jsondash.config.WIDGET_MARGIN_Y;
0 ignored issues
show
Unused Code introduced by
The variable h seems to be never used. Consider removing it.
Loading history...
65
        var w = config.width - jsondash.config.WIDGET_MARGIN_X;
0 ignored issues
show
Unused Code introduced by
The variable w seems to be never used. Consider removing it.
Loading history...
66
        var svg = container.append('svg').classed({'chart-graph': true});
67
        var svg_group = svg.append('g');
68
        var g = graphlibDot.read(data.graph);
0 ignored issues
show
Bug introduced by
The variable graphlibDot seems to be never declared. If this is a global, consider adding a /** global: graphlibDot */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
69
        var bbox = null;
0 ignored issues
show
Unused Code introduced by
The assignment to bbox seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
70
        // Create the renderer
71
        var render = new dagreD3.render();
0 ignored issues
show
Bug introduced by
The variable dagreD3 seems to be never declared. If this is a global, consider adding a /** global: dagreD3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
72
        render(svg_group, g);
73
        bbox = svg.node().getBBox();
74
        svg.attr('width', bbox.width)
75
            .attr('height', bbox.height);
76
        // Look for callbacks potentially registered for third party code.
77
        jsondash.api.runCallbacks(container, config);
78
        jsondash.unload(container);
79
    });
80
};
81
82
/**
83
 * [handleWordCloud create word clouds using the d3-cloud extension.]
84
 */
85
jsondash.handlers.handleWordCloud = function(container, config) {
86
    'use strict';
87
    jsondash.getJSON(container, config.dataSource, function(error, data){
88
        container.selectAll('.wordcloud').remove();
89
        var h     = config.height - jsondash.config.WIDGET_MARGIN_Y;
90
        var w     = config.width - jsondash.config.WIDGET_MARGIN_X;
91
        var svg   = container.append('svg').classed({'wordcloud': true});
92
        var fill  = d3.scale.category20();
0 ignored issues
show
Unused Code introduced by
The variable fill seems to be never used. Consider removing it.
Loading history...
93
        var cloud = d3.layout.cloud;
94
        var words = data.map(function(d) {
95
            return {text: d.text, size: d.size};
96
        });
97
        var layout = cloud()
98
            .size([w, h])
99
            .words(words)
100
            .padding(4)
101
            .rotate(function() {return ~~(Math.random() * 1) * 90;})
102
            .font('Arial')
103
            .fontSize(function(d) {return d.size;})
104
            .on('end', draw);
105
106
        layout.start();
107
108
        function draw(words) {
109
          svg
110
              .attr('width', layout.size()[0])
111
              .attr('height', layout.size()[1])
112
            .append('g')
113
              .attr('transform', 'translate(' + layout.size()[0] / 2 + ',' + layout.size()[1] / 2 + ')')
114
            .selectAll('text').data(words)
115
            .enter().append('text')
116
              .style('font-size', function(d) { return d.size + 'px'; })
117
              .style('font-family', 'arial')
118
              .style('fill', function(d, i) { return "#000"; })
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter d is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
119
              .attr('text-anchor', 'middle')
120
              .attr('transform', function(d) {
121
                return 'translate(' + [d.x, d.y] + ')rotate(' + d.rotate + ')';
122
              })
123
              .text(function(d) { return d.text; });
124
        }
125
126
        // Look for callbacks potentially registered for third party code.
127
        jsondash.api.runCallbacks(container, config);
128
        jsondash.unload(container);
129
    });
130
};
131
132
jsondash.handlers.handleC3 = function(container, config) {
133
    'use strict';
134
    var init_config = {
135
        bindto: '[data-guid="' + config.guid + '"] .chart-container',
136
        legend: {
137
            show: true
138
        },
139
        size: {
140
            height: config.height - jsondash.config.WIDGET_MARGIN_Y,
141
            width: config.width - jsondash.config.WIDGET_MARGIN_X
142
        },
143
        data: {
144
            type: config.type,
145
            url: config.dataSource,
146
            mimeType: 'json'
147
        },
148
        onrendered: function(){
149
            // Look for callbacks potentially registered for third party code.
150
            jsondash.api.runCallbacks(container, config);
151
            jsondash.unload(container);
152
        }
153
    };
154
    if(jsondash.util.isOverride(config)) {
155
        // Just use the raw payload for this widgets' options.
156
        jsondash.getJSON(container, config.dataSource, function(error, data){
157
            // Keep existing options if not specified.
158
            config = $.extend(init_config, data);
159
            c3.generate(init_config);
160
        });
161
        return;
162
    }
163
    if(config.type === 'timeseries') {
164
        init_config.axis = {
165
            x: {type: 'timeseries'}
166
        };
167
        // Map the corresponding data key and list of dates
168
        // to the `x` property.
169
        init_config.data.x = 'dates';
170
    }
171
    c3.generate(init_config);
172
};
173
174
jsondash.handlers.handleD3 = function(container, config) {
175
    'use strict';
176
    // Clean up all D3 charts in one step.
177
    container.selectAll('svg').remove();
178
    // Handle specific types.
179
    if(config.type === 'radial-dendrogram') { return jsondash.handlers.handleRadialDendrogram(container, config); }
180
    if(config.type === 'dendrogram') { return jsondash.handlers.handleDendrogram(container, config); }
181
    if(config.type === 'voronoi') { return jsondash.handlers.handleVoronoi(container, config); }
182
    if(config.type === 'treemap') { return jsondash.handlers.handleTreemap(container, config); }
183
    if(config.type === 'circlepack') { return jsondash.handlers.handleCirclePack(container, config); }
184
    throw new Error('Unknown type: ' + config.type);
185
};
186
187
jsondash.handlers.handleCirclePack = function(container, config) {
188
    'use strict';
189
    // Adapted from https://bl.ocks.org/mbostock/4063530
190
    var margin = jsondash.config.WIDGET_MARGIN_Y;
191
    var diameter = d3.max([config.width, config.height]) - margin;
192
    var format = d3.format(',d');
193
194
    var pack = d3.layout.pack()
195
        .size([diameter, diameter])
196
        .value(function(d) { return d.size; });
197
198
    var svg = container
199
        .append('svg')
200
        .attr('width', diameter)
201
        .attr('height', diameter)
202
        .append('g');
203
204
    jsondash.getJSON(container, config.dataSource, function(error, data) {
205
        var node = svg.datum(data).selectAll('.node')
206
        .data(pack.nodes)
207
        .enter().append('g')
208
        .attr('class', function(d) { return d.children ? 'node' : 'leaf node'; })
209
        .attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')'; });
210
211
        node.append('title')
212
        .text(function(d) { return d.name + (d.children ? '' : ': ' + format(d.size)); });
213
214
        node.append('circle')
215
        .attr('r', function(d) { return d.r; });
216
217
        node.filter(function(d) { return !d.children; }).append('text')
218
        .attr('dy', '.3em')
219
        .style('text-anchor', 'middle')
220
        .text(function(d) { return d.name.substring(0, d.r / 3); });
221
        // Look for callbacks potentially registered for third party code.
222
        jsondash.api.runCallbacks(container, config);
223
        jsondash.unload(container);
224
    });
225
226
    d3.select(self.frameElement).style("height", diameter + "px");
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
227
};
228
229
jsondash.handlers.handleTreemap = function(container, config) {
230
    'use strict';
231
    // Adapted from http://bl.ocks.org/mbostock/4063582
232
    var margin = {
0 ignored issues
show
Unused Code introduced by
The variable margin seems to be never used. Consider removing it.
Loading history...
233
        top: jsondash.config.WIDGET_MARGIN_Y / 2,
234
        bottom: jsondash.config.WIDGET_MARGIN_Y / 2,
235
        left: jsondash.config.WIDGET_MARGIN_X / 2,
236
        right: jsondash.config.WIDGET_MARGIN_X / 2
237
    };
238
    var width = config.width - jsondash.config.WIDGET_MARGIN_X;
239
    var height = config.height - jsondash.config.WIDGET_MARGIN_Y;
240
    var color = d3.scale.category20c();
241
    var treemap = d3.layout.treemap()
242
        .size([width, height])
243
        .sticky(true)
244
        .value(function(d) { return d.size; });
245
    // Cleanup
246
    container.selectAll('.treemap').remove();
247
    var div = container
248
        .append('div')
249
        .classed({treemap: true, 'chart-centered': true})
250
        .style('position', 'relative')
251
        .style('width', width + 'px')
252
        .style('height', height + 'px');
253
254
    jsondash.getJSON(container, config.dataSource, function(error, root) {
255
        var node = div.datum(root).selectAll('.node')
256
            .data(treemap.nodes)
257
            .enter().append('div')
258
            .attr('class', 'node')
259
            .call(position)
260
            .style('border', '1px solid white')
261
            .style('font', '10px sans-serif')
262
            .style('line-height', '12px')
263
            .style('overflow', 'hidden')
264
            .style('position', 'absolute')
265
            .style('text-indent', '2px')
266
            .style('background', function(d) {
267
                return d.children ? color(d.name) : null;
268
            })
269
            .text(function(d) {
270
                return d.children ? null : d.name;
271
            });
272
        d3.selectAll('input').on('change', function change() {
273
            var value = this.value === 'count'
274
            ? function() { return 1; }
275
            : function(d) { return d.size;};
276
            node
277
            .data(treemap.value(value).nodes)
278
            .transition()
279
            .duration(1500)
280
            .call(position);
281
        });
282
        // Look for callbacks potentially registered for third party code.
283
        jsondash.api.runCallbacks(container, config);
284
        jsondash.unload(container);
285
    });
286
287
    function position() {
288
        this.style('left', function(d) { return d.x + 'px'; })
289
            .style('top', function(d) { return d.y + 'px'; })
290
            .style('width', function(d) { return Math.max(0, d.dx - 1) + 'px'; })
291
            .style('height', function(d) { return Math.max(0, d.dy - 1) + 'px'; });
292
    }
293
};
294
295
jsondash.handlers.handleRadialDendrogram = function(container, config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
296
    'use strict';
297
    container.selectAll('svg').remove();
298
    // Code taken (and refactored for use here) from:
299
    // https://bl.ocks.org/mbostock/4339607
300
    var padding = 50;
301
    var radius = (config.width > config.height ? config.width : config.height) - padding;
302
    var cluster = d3.layout.cluster()
303
        .size([360, radius / 2 - 150]); // reduce size relative to `radius`
304
    var diagonal = d3.svg.diagonal.radial()
305
        .projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
306
    var svg = container.append('svg')
307
        .attr('width', radius)
308
        .attr('height', radius);
309
    var g = svg.append('g');
310
    g.attr('transform', 'translate(' + radius / 2 + ',' + radius / 2 + ')');
311
312
    jsondash.getJSON(container, config.dataSource, function(error, root) {
313
        if (error) { throw error; }
314
        var nodes = cluster.nodes(root);
315
        var link = g.selectAll('path.link')
0 ignored issues
show
Unused Code introduced by
The variable link seems to be never used. Consider removing it.
Loading history...
316
            .data(cluster.links(nodes))
317
            .enter().append('path')
318
            .attr('class', 'link')
319
            .attr('d', diagonal);
320
        var node = g.selectAll('g.node')
321
            .data(nodes)
322
            .enter().append('g')
323
            .attr('class', 'node')
324
            .attr('transform', function(d) { return 'rotate(' + (d.x - 90) + ')translate(' + d.y + ')'; });
325
        node.append('circle')
326
            .attr('r', 4.5);
327
        node.append('text')
328
            .attr('dy', '.31em')
329
            .attr('text-anchor', function(d) { return d.x < 180 ? 'start' : 'end'; })
330
            .attr('transform', function(d) { return d.x < 180 ? 'translate(8)' : 'rotate(180)translate(-8)'; })
331
            .text(function(d) { return d.name; });
332
        // Look for callbacks potentially registered for third party code.
333
        jsondash.api.runCallbacks(container, config);
334
        jsondash.unload(container);
335
    });
336
    d3.select(self.frameElement).style('height', radius * 2 + 'px');
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
337
};
338
339
jsondash.handlers.handleDendrogram = function(container, config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
340
    'use strict';
341
    container.selectAll('svg').remove();
342
    // A general padding for the svg inside of the widget.
343
    // The cluster dendrogram will also need to have padding itself, so
344
    // the bounds are not clipped in the svg.
345
    var svg_pad = 20;
346
    var width = config.width - svg_pad;
347
    var height = config.height - svg_pad;
348
    var PADDING = width / 4;
349
    var cluster = d3.layout.cluster()
350
        .size([height * 0.85, width - PADDING]);
351
    var diagonal = d3.svg.diagonal()
352
        .projection(function(d) { return [d.y, d.x]; });
353
    var svg = container
354
        .append('svg')
355
        .attr('width', width)
356
        .attr('height', height);
357
    var g = svg.append('g')
358
        .attr('transform', 'translate(40, 0)');
359
360
    jsondash.getJSON(container, config.dataSource, function(error, root) {
361
        var nodes = cluster.nodes(root);
362
        var links = cluster.links(nodes);
363
        var link = g.selectAll('.link')
0 ignored issues
show
Unused Code introduced by
The variable link seems to be never used. Consider removing it.
Loading history...
364
        .data(links)
365
        .enter().append('path')
366
        .attr('class', 'link')
367
        .attr('d', diagonal);
368
369
        var node = g.selectAll('.node')
370
        .data(nodes)
371
        .enter().append('g')
372
        .attr('class', 'node')
373
        .attr('transform', function(d) { return 'translate(' + d.y + ',' + d.x + ')'; });
374
375
        node.append('circle').attr('r', 4.5);
376
        node.append('text')
377
        .attr('dx', function(d) { return d.children ? -8 : 8; })
378
        .attr('dy', 3)
379
        .style('text-anchor', function(d) { return d.children ? 'end' : 'start'; })
380
        .text(function(d) { return d.name; });
381
382
        // Look for callbacks potentially registered for third party code.
383
        jsondash.api.runCallbacks(container, config);
384
        jsondash.unload(container);
385
    });
386
};
387
388
jsondash.handlers.handleVoronoi = function(container, config) {
389
    'use strict';
390
    jsondash.getJSON(container, config.dataSource, function(error, data){
391
        var width = config.width - jsondash.config.WIDGET_MARGIN_X;
392
        var height = config.height - jsondash.config.WIDGET_MARGIN_Y;
393
        var vertices = data;
394
        var voronoi = d3.geom.voronoi().clipExtent([[0, 0], [width, height]]);
395
        // Cleanup
396
        var svg = container
397
        .append('svg')
398
        .attr('width', width)
399
        .attr('height', height);
400
        var path = svg.append('g').selectAll('path');
401
        svg.selectAll('circle')
402
        .data(vertices.slice(1))
403
        .enter().append('circle')
404
        .attr('transform', function(d) { return 'translate(' + d + ')'; })
405
        .attr('r', 1.5);
406
        redraw();
407
408
        function redraw() {
409
            path = path.data(voronoi(vertices), jsondash.util.polygon);
410
            path.exit().remove();
411
            path.enter().append('path')
412
            .attr('class', function(d, i) { return 'q' + (i % 9) + '-9'; })
413
            .attr('d', jsondash.util.polygon);
414
            path.order();
415
        }
416
        // Look for callbacks potentially registered for third party code.
417
        jsondash.api.runCallbacks(container, config);
418
        jsondash.unload(container);
419
    });
420
};
421
422
jsondash.handlers.handleSparkline = function(container, config) {
423
    'use strict';
424
    // Clean up old canvas elements
425
    container.selectAll('.sparkline-container').remove();
426
    var sparkline_type = config.type.split('-')[1];
427
    var spark = container
428
        .append('div')
429
        .classed({
430
            'sparkline-container': true,
431
            'text-center': true
432
        });
433
    spark = $(spark[0]);
434
    jsondash.getJSON(container, config.dataSource, function(data){
435
        var opts = {
436
            type: sparkline_type,
437
            width: config.width - jsondash.config.WIDGET_MARGIN_X,
438
            height: config.height - jsondash.config.WIDGET_MARGIN_Y
439
        };
440
        spark.sparkline(data, opts);
441
        // Look for callbacks potentially registered for third party code.
442
        jsondash.api.runCallbacks(container, config);
443
        jsondash.unload(container);
444
    });
445
};
446
447
jsondash.handlers.handleDataTable = function(container, config) {
448
    'use strict';
449
    // Clean up old tables if they exist, during reloading.
450
    container.selectAll('.dataTables_wrapper').remove();
451
    jsondash.getJSON(container, config.dataSource, function(error, res) {
452
        var keys = d3.keys(res[0]).map(function(d){
453
            return {data: d, title: d};
454
        });
455
        container
456
            .append('table')
457
            .classed({
458
                table: true,
459
                'table-striped': true,
460
                'table-bordered': true,
461
                'table-condensed': true
462
            });
463
        var opts = config.override ? res : {data: res, columns: keys};
464
        $(container.select('table')[0]).dataTable(opts).css({width: 'auto'});
465
        // Look for callbacks potentially registered for third party code.
466
        jsondash.api.runCallbacks(container, config);
467
        jsondash.unload(container);
468
    });
469
};
470
471
jsondash.handlers.handleSingleNum = function(container, config) {
472
    'use strict';
473
    container.selectAll('.singlenum').remove();
474
    jsondash.getJSON(container, config.dataSource, function(resp){
475
        var data = resp.data.data ? resp.data.data : resp.data;
476
        var num = container.select('.chart-container').append('div')
477
            .classed({singlenum: true})
478
            .text(data);
479
        data = String(data);
480
        // Add red or green, depending on if the number appears to be pos/neg.
481
        if(!resp.noformat) {
482
            num.classed({
483
                'text-danger': data.startsWith('-'),
484
                'text-success': !data.startsWith('-')
485
            });
486
        }
487
        // Allow custom colors.
488
        if(resp.color && resp.noformat) {
489
            num.style('color', resp.color);
490
        }
491
        // Get title height to offset box.
492
        var title_h = container
0 ignored issues
show
Unused Code introduced by
The variable title_h seems to be never used. Consider removing it.
Loading history...
493
            .select('.widget-title')
494
            .node()
495
            .getBoundingClientRect()
496
            .height;
497
        var h = config.height - jsondash.config.WIDGET_MARGIN_Y;
498
        num.style({
499
            'line-height': h + 'px',
500
            height: h + 'px',
501
            width: config.width - jsondash.config.WIDGET_MARGIN_X
502
        });
503
        var digits = String(data).length;
504
        var size = jsondash.util.getDigitSize()(digits);
505
        num.style('font-size', size + 'px');
506
        // Look for callbacks potentially registered for third party code.
507
        jsondash.api.runCallbacks(container, config);
508
        jsondash.unload(container);
509
    });
510
};
511
512
jsondash.handlers.handleTimeline = function(container, config) {
513
    'use strict';
514
    jsondash.getJSON(container, config.dataSource, function(data){
515
        container.append('div').attr('id', 'widget-' + config.guid);
516
        var timeline = new TL.Timeline('widget-' + config.guid, data);
0 ignored issues
show
Bug introduced by
The variable TL seems to be never declared. If this is a global, consider adding a /** global: TL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The variable timeline seems to be never used. Consider removing it.
Loading history...
517
        // Look for callbacks potentially registered for third party code.
518
        jsondash.api.runCallbacks(container, config);
519
        jsondash.unload(container);
520
    });
521
};
522
523
jsondash.handlers.handleIframe = function(container, config) {
524
    'use strict';
525
    container.selectAll('iframe').remove();
526
    var iframe = container.append('iframe');
527
    iframe.attr({
528
        border: 0,
529
        src: config.dataSource,
530
        height: config.height - jsondash.config.WIDGET_MARGIN_Y,
531
        width: config.width - jsondash.config.WIDGET_MARGIN_X
532
    });
533
    // Look for callbacks potentially registered for third party code.
534
    jsondash.api.runCallbacks(container, config);
535
    jsondash.unload(container);
536
};
537
538
jsondash.handlers.handleCustom = function(container, config) {
539
    'use strict';
540
    container.selectAll('.custom-container').remove();
541
    $.get(config.dataSource, function(html){
542
        container.append('div').classed({'custom-container': true}).html(html);
543
        // Look for callbacks potentially registered for third party code.
544
        jsondash.api.runCallbacks(container, config);
545
        jsondash.unload(container);
546
    });
547
};
548
549
jsondash.handlers.handleVenn = function(container, config) {
550
    'use strict';
551
    container.selectAll('.venn').remove();
552
    jsondash.getJSON(container, config.dataSource, function(error, data){
553
        var chart = venn.VennDiagram();
554
        var cont = container
555
            .append('div')
556
            .classed({venn: true});
557
        cont.datum(data).call(chart);
558
        cont.select('svg')
559
            .attr('width', config.width - jsondash.config.WIDGET_MARGIN_X)
560
            .attr('height', config.height - jsondash.config.WIDGET_MARGIN_Y);
561
        // Look for callbacks potentially registered for third party code.
562
        jsondash.api.runCallbacks(container, config);
563
        jsondash.unload(container);
564
    });
565
};
566
567
jsondash.handlers.handlePlotly = function(container, config) {
568
    'use strict';
569
    var id = 'plotly-' + config.guid;
570
    container.selectAll('.plotly-container').remove();
571
    container.append('div')
572
        .classed({'plotly-container': true})
573
        .attr('id', id);
574
    jsondash.getJSON(container, config.dataSource, function(error, data){
575
        if(config.override) {
576
            if(data.layout && data.layout.margin) {
577
                // Remove margins, they mess up the
578
                // layout and are already accounted for.
579
                delete data.layout['margin'];
580
            }
581
            Plotly.plot(id, data.data, data.layout || {}, data.options || {});
582
        } else {
583
            Plotly.plot(id, data);
584
        }
585
        d3.select('#' + id).select('.svg-container').style({'margin': '0 auto'})
586
        // Look for callbacks potentially registered for third party code.
587
        jsondash.api.runCallbacks(container, config);
588
        jsondash.unload(container);
589
    });
590
};
591