This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
dist.coffee
77 lines (58 loc) · 2.3 KB
/
dist.coffee
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
define [
'../core'
'./core'
'./utils'
'tpl!templates/views/chart.html'
], (c, charts, utils, templates...) ->
templates = c._.object ['chart'], templates
class FieldChart extends charts.Chart
template: templates.chart
ui:
chart: '.chart'
heading: '.heading'
status : '.heading .status'
chartClick: (event) =>
category = event.point.category ? event.point.name
event.point.select(not event.point.selected, true)
@change()
interactive: (options) ->
if (type = options.chart?.type) is 'pie'
return true
else if type is 'column' and options.xAxis.categories?
return true
return false
getChartOptions: (resp) ->
options = utils.processResponse(resp, [@model])
if options.clustered
@ui.status.text('Clustered').show()
else
@ui.status.hide()
if @interactive(options)
@setOption('plotOptions.series.events.click', @chartClick)
$.extend true, options, @chartOptions
options.chart.renderTo = @ui.chart[0]
return options
getField: -> @model.id
getValue: (options) ->
points = @chart.getSelectedPoints()
return (point.category for point in points)
getOperator: -> 'in'
removeChart: (event) ->
super
if @node then @node.destroy()
onRender: ->
@$el.addClass 'loading'
# Explicitly set the width of the chart so Highcharts knows
# how to fill out the space. Otherwise if this element is
# not in the DOM by the time the distribution request is finished,
# the chart will default to an arbitrary size..
if @options.parentView?
@ui.chart.width(@options.parentView.$el.width())
@model.distribution (resp) =>
options = @getChartOptions(resp)
@renderChart(options)
setValue: (value) =>
if not c._.isArray(value) then value = []
points = @chart.series[0].points
point.select(point.name ? point.category in value, true) for point in points
{ FieldChart }