/
vizwit.js
95 lines (89 loc) · 2.47 KB
/
vizwit.js
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
/*eslint no-new:0*/
var _ = require('underscore')
var Backbone = require('backbone')
var Providers = require('./config/providers')
var GeoJSON = require('./collections/geojson')
var Bar = require('./views/bar')
var Table = require('./views/table')
var DateTime = require('./views/datetime')
var Choropleth = require('./views/choropleth')
var Pie = require('./views/pie')
var Callout = require('./views/callout')
exports.init = function (container, config, opts) {
// If globals weren't passed, create them within this scope
opts = opts || {}
opts.vent = opts.vent || _.clone(Backbone.Events)
opts.fieldsCache = opts.fieldsCache || {}
// Get provider
if (!config.provider) config.provider = 'socrata' // set default for backwards compatibility
var Provider = Providers[config.provider.toLowerCase()]
if (!Provider) console.error('Unrecognized provider %s', config.provider)
// Initialize collection
var collection = new Provider(null, {
config: config,
fieldsCache: opts.fieldsCache
})
var filteredCollection = new Provider(null, {
config: config,
fieldsCache: opts.fieldsCache
})
// Initialize view
switch (config.chartType) {
case 'bar':
new Bar({
config: config,
el: container,
collection: collection,
filteredCollection: filteredCollection,
vent: opts.vent
})
break
case 'datetime':
new DateTime({
config: config,
el: container,
collection: collection,
filteredCollection: filteredCollection,
vent: opts.vent
})
break
case 'pie':
collection.setDontFilterSelf(true)
filteredCollection.setDontFilterSelf(true)
new Pie({
config: config,
el: container,
collection: collection,
filteredCollection: filteredCollection,
vent: opts.vent
})
break
case 'table':
new Table({
config: config,
el: container,
collection: collection,
vent: opts.vent
})
break
case 'choropleth':
new Choropleth({
config: config,
el: container,
collection: collection,
boundaries: new GeoJSON(null, config),
filteredCollection: filteredCollection,
vent: opts.vent
})
break
case 'callout':
new Callout({
config: config,
el: container,
collection: collection,
filteredCollection: filteredCollection,
vent: opts.vent
})
break
}
}