material_raingular-d3 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0075ac4a54d06c4290a26475164d8a97c976db50
4
- data.tar.gz: 20bf12b579c0ab844fdaadd5459f0fafc5f4b1e5
3
+ metadata.gz: e2227d8f78026d1958580858a9a76063132362a2
4
+ data.tar.gz: fd3300c5b2d837cd305b3eddbda1f744f19f15f0
5
5
  SHA512:
6
- metadata.gz: ed78e9a1dedae5d716490c6ef9d92efaf905aabf5859cc26986f4ddbd29820c7369eb276878bfb9a5b8da0fa77a1aaa8253395fea97af5b0234fa3d58bcb8607
7
- data.tar.gz: 568a7533f494b9d79a8cf4b5f52448c6fccf05aebceb05d6d3464f441f49d5a007c1a3a8fe2a17fb254b28533525a07e8aa0ddfc8c0e63021441cc96f2873b8c
6
+ metadata.gz: bfc86fb047b62bb95cd212ad1f47ff38b8ff861ed7bfe9018d03def048b120262d6f71af532ac13ec76a66021fc3607bcd7a60462c1e406f8d336c5562124333
7
+ data.tar.gz: 237915a229448df597d651c960091ca0c9e005880e55dbc62a3cc976e9704ca6c87b2a16578b63dc396209e6cabcc585d075dc1eb209d923047a53ea4d5c380e
@@ -1,15 +1,21 @@
1
1
  class BarModel extends AngularLinkModel
2
2
  @inject('$parse')
3
3
  initialize: ->
4
- @parent = @$controller.compact()[0]
5
- @bar = d3.select(@$element[0])
6
- @label = @$parse @$attrs.mrD3Label
7
- @size = @$parse @$attrs.mrD3Value
4
+ @parent = @$controller.compact()[0]
5
+ @bar = d3.select(@$element[0])
6
+ @label = @$parse @$attrs.mrD3Label
7
+ @size = @$parse @$attrs.mrD3Value
8
+ @options = @$parse(@$attrs.mrD3Options || '{}')
8
9
  @$scope.$watch @size.bind(@), @changeBar.bind(@)
9
10
  @$scope.$watch @label.bind(@), @changeBar.bind(@)
11
+ @$scope.$watch @options.bind(@), @changeOptions.bind(@), true
10
12
  @changeBar()
13
+ changeOptions: (newVal) ->
14
+ return unless newVal
15
+ @bar.attr 'fill', newVal.fill || d3.interpolateCool Math.random(@index)
16
+ @parent.adjustBars()
11
17
  changeBar: ->
12
18
  @bar.attr('raw-size',@size(@$scope))
13
19
  @bar.attr('label', @label(@$scope))
14
- @parent.adjustBars()
20
+ @changeOptions(@options(@$scope))
15
21
  @register(MaterialRaingular.d3.Directives.MrD3Bar)
@@ -1,13 +1,23 @@
1
1
  class MaterialRaingular.d3.Directives.MrD3BarChartModel extends AngularDirectiveModel
2
2
  @inject('$timeout','$element','$attrs')
3
3
  initialize: ->
4
- @options = @$scope.$eval(@$attrs.d3Options || '{}')
4
+ @options = @$scope.$eval(@$attrs.mrD3Options || '{}')
5
5
  @options.margins = Object.merge({top: 20,right: 20, left: 70, bottom: 50},@options.margins || {})
6
+ @options.minSize ?= 100
6
7
  @svg = d3.select(@$element[0])
7
8
  @holder = @svg.select('g')
8
9
  @holder.attr('transform',"translate(#{@options.margins.left},#{@options.margins.right})")
10
+ @$scope.$watch @height.bind(@), @setAxis.bind(@)
11
+ @$scope.$watch @width.bind(@), @setAxis.bind(@)
12
+ @setAxis()
13
+ setAxis: ->
9
14
  @xAxis = d3.scaleBand().rangeRound([0,@width()]).padding(0.1)
10
15
  @yAxis = d3.scaleLinear().range([0,@height()])
16
+ if @_xAxis || @_yAxis
17
+ @_xAxis?.adjustAxis(true)
18
+ @_yAxis?.adjustAxis(true)
19
+ else
20
+ @adjustBars()
11
21
  indexOf: (bar) ->
12
22
  @bars().nodes().indexOf(bar)
13
23
  bars: ->
@@ -25,9 +35,9 @@ class MaterialRaingular.d3.Directives.MrD3BarChartModel extends AngularDirective
25
35
  for rect in @bars().nodes()
26
36
  d3.select(rect).attr('width',@xAxis.bandwidth())
27
37
  d3.select(rect).attr('x',@xAxis(@xDomain[@indexOf(rect)]))
28
- @_xAxis?.call(d3.axisBottom(@xAxis))
29
- height: -> @$element[0].clientHeight - @options.margins.top - @options.margins.bottom
30
- width: -> @$element[0].clientWidth - @options.margins.left - @options.margins.right
38
+ @_xAxis?.axis.call(d3.axisBottom(@xAxis))
39
+ height: -> [@$element[0].parentElement.clientHeight, @options.minSize].max() - @options.margins.top - @options.margins.bottom
40
+ width: -> [@$element[0].parentElement.clientWidth, @options.minSize].max() - @options.margins.left - @options.margins.right
31
41
  maxValue: ->
32
42
  val = @yAxis?.domain().max()
33
43
  val ||= (@bars().nodes().map (rect) -> d3.select(rect).attr('raw-size')).max()
@@ -5,7 +5,7 @@ class MrD3BarChart extends AngularDirective
5
5
  controller: MaterialRaingular.d3.Directives.MrD3BarChartModel
6
6
  transclude: true
7
7
  replace: true
8
- template: "<svg height='100%' width: 100%><g ng-transclude></g></svg>"
8
+ template: "<svg height='100%' width='100%'><g ng-transclude></g></svg>"
9
9
  ###
10
10
  Usage Slim syntax
11
11
  mr-d3-bar-chart.test ng-init="dataSet = [{l: 'a',v: 23},{l: 'b',v: 13},{l: 'c',v: 21},{l: 'd',v: 14},{l: 'e',v: 37},{l: 'f',v: 15},{l: 'g',v: 18},{l: 'h',v: 34},{l: 'i',v: 30}]"
@@ -1,13 +1,23 @@
1
1
  class MaterialRaingular.d3.Directives.MrD3HorizontalBarChartModel extends AngularDirectiveModel
2
2
  @inject('$timeout','$element','$attrs')
3
3
  initialize: ->
4
- @options = @$scope.$eval(@$attrs.d3Options || '{}')
4
+ @options = @$scope.$eval(@$attrs.mrD3Options || '{}')
5
5
  @options.margins = Object.merge({top: 20,right: 20, left: 70, bottom: 50},@options.margins || {})
6
+ @options.minSize ?= 100
6
7
  @svg = d3.select(@$element[0])
7
8
  @holder = @svg.select('g')
8
9
  @holder.attr('transform',"translate(#{@options.margins.left},#{@options.margins.right})")
10
+ @$scope.$watch @height.bind(@), @setAxis.bind(@)
11
+ @$scope.$watch @width.bind(@), @setAxis.bind(@)
12
+ @setAxis()
13
+ setAxis: ->
9
14
  @yAxis = d3.scaleBand().rangeRound([0,@height()]).padding(0.1)
10
15
  @xAxis = d3.scaleLinear().range([0,@width()])
16
+ if @_xAxis || @_yAxis
17
+ @_xAxis?.adjustAxis(true)
18
+ @_yAxis?.adjustAxis(true)
19
+ else
20
+ @adjustBars()
11
21
  indexOf: (bar) ->
12
22
  @bars().nodes().indexOf(bar)
13
23
  bars: ->
@@ -24,9 +34,9 @@ class MaterialRaingular.d3.Directives.MrD3HorizontalBarChartModel extends Angula
24
34
  for rect in @bars().nodes()
25
35
  d3.select(rect).attr('height',@yAxis.bandwidth())
26
36
  d3.select(rect).attr('y',@yAxis(@yDomain[@indexOf(rect)]))
27
- @_yAxis?.call(d3.axisLeft(@yAxis))
28
- height: -> @$element[0].clientHeight - @options.margins.top - @options.margins.bottom
29
- width: -> @$element[0].clientWidth - @options.margins.left - @options.margins.right
37
+ @_yAxis?.axis.call(d3.axisLeft(@yAxis))
38
+ height: -> [@$element[0].parentElement.clientHeight, @options.minSize].max() - @options.margins.top - @options.margins.bottom
39
+ width: -> [@$element[0].parentElement.clientWidth, @options.minSize].max() - @options.margins.left - @options.margins.right
30
40
  maxValue: ->
31
41
  val = @xAxis?.domain().max()
32
42
  val ||= (@bars().nodes().map (rect) -> d3.select(rect).attr('raw-size')).max()
@@ -5,7 +5,7 @@ class MrD3HorizontalBarChart extends AngularDirective
5
5
  controller: MaterialRaingular.d3.Directives.MrD3HorizontalBarChartModel
6
6
  transclude: true
7
7
  replace: true
8
- template: "<svg height='100%' width: 100%><g ng-transclude></g></svg>"
8
+ template: "<svg height='100%' width='100%'><g ng-transclude></g></svg>"
9
9
  ###
10
10
  Usage Slim Syntax
11
11
  mr-d3-horizontal-bar-chart.test ng-init="dataSet = [{l: 'a',v: 23},{l: 'b',v: 13},{l: 'c',v: 21},{l: 'd',v: 14},{l: 'e',v: 37},{l: 'f',v: 15},{l: 'g',v: 18},{l: 'h',v: 34},{l: 'i',v: 30}]"
@@ -0,0 +1,37 @@
1
+ class MaterialRaingular.d3.Directives.PieChartModel extends AngularDirectiveModel
2
+ @inject('$timeout','$element','$attrs')
3
+ initialize: ->
4
+ @svg = d3.select(@$element[0])
5
+ @chartLayer = @svg.select('g.chartLayer')
6
+ @setSize()
7
+ @arc = d3.arc().outerRadius(@chartHeight / 2).innerRadius(0)
8
+ @slices = []
9
+ @values = []
10
+ setSize: () ->
11
+ @options = @$scope.$eval(@$attrs.mrD3Options) || {}
12
+ @width = @options.width || 960
13
+ @height = @options.height || 500
14
+ @color = @options.color || '6b486b'
15
+ @margin = @options.margin || {top: 40,left: 0,bottom: 40,right: 0}
16
+ @chartWidth = @width - (@margin.left + @margin.right)
17
+ @chartHeight = @height - (@margin.top + @margin.bottom)
18
+ @svg.attr('width', @width).attr 'height', @height
19
+ @chartLayer.attr('width', @chartWidth).attr('height', @chartHeight).attr 'transform', "translate(#{[@margin.left,@margin.top]})"
20
+
21
+ addSlice: (slice) ->
22
+ @slices.push(slice) unless @slices.includes(slice)
23
+ return @slices.index(slice)
24
+ changeData: (slice,value) ->
25
+ @slices.push(slice) unless @slices.includes(slice)
26
+ index = @slices.indexOf(slice)
27
+ @values[index] = value
28
+ @arcs = d3.pie().sort(null).value((d) -> d)(@values)
29
+ @$timeout.cancel(@drawTimeout)
30
+ @drawTimeout = @$timeout(@drawChart.bind(@),10)
31
+ return index
32
+ drawChart: () ->
33
+ for slice,i in @slices
34
+ continue unless @arcs[i]
35
+ slice.path
36
+ .attr('d', @arc(@arcs[i]))
37
+ slice.afterDraw?()
@@ -1,6 +1,11 @@
1
- class MaterialRaingular.d3.Directives.MrD3PieChart extends AngularDirective
1
+ # //= require material_raingular/d3/pie_chart/controller
2
+ class MrD3PieChart extends AngularDirective
2
3
  restrict: "E"
3
4
  @register(MaterialRaingular.d3.app)
5
+ controller: MaterialRaingular.d3.Directives.PieChartModel
6
+ transclude: true
7
+ replace: true
8
+ template: "<svg height='100%' width='100%'><g class='chartLayer' ng-transclude></g></svg>"
4
9
  ###
5
10
  Usage Slim Syntax
6
11
  mr-d3-pie-chart d3-data="{bio: 10, planning: 30, cr: 12}"
@@ -0,0 +1,11 @@
1
+ class MaterialRaingular.d3.Directives.MrD3PieSlice extends AngularDirective
2
+ restrict: "E"
3
+ @register(MaterialRaingular.d3.app)
4
+ controller: MaterialRaingular.d3.Directives.PieChartModel
5
+ replace: true
6
+ require: '^mrD3PieChart'
7
+ template: "<g class='arc'></g>"
8
+ ###
9
+ Usage Slim Syntax
10
+ mr-d3-pie-chart d3-data="{bio: 10, planning: 30, cr: 12}"
11
+ ###
@@ -0,0 +1,67 @@
1
+ class PieSliceModel extends AngularLinkModel
2
+ @inject('$parse')
3
+ initialize: ->
4
+ @options = @$parse(@$attrs.mrD3Options || '{}')
5
+ @slice = d3.select(@$element[0])
6
+ @index = @$controller.addSlice(@)
7
+ @path = @slice.append('path').attr('id', 'arc-' + @index)
8
+ @transition = d3.transition().duration(300).ease(d3.easeLinear)
9
+ @labelFn = @$parse @$attrs.mrD3Label
10
+ @valueFn = @$parse @$attrs.mrD3Value
11
+ @adjustSlice()
12
+ @addText()
13
+ @$scope.$watch @valueFn.bind(@), @changeValue.bind(@)
14
+ @$scope.$watch @labelFn.bind(@), @adjustText.bind(@)
15
+ @$scope.$watch @options.bind(@), @changeOptions.bind(@), true
16
+ changeOptions: (newVal) ->
17
+ return unless newVal
18
+ @path.attr 'fill', newVal.fill || d3.interpolateCool Math.random(@index)
19
+
20
+ changeValue: (newVal,oldVal) ->
21
+ return unless newVal
22
+ @index = @$controller.changeData(@,newVal)
23
+ adjustSlice: ->
24
+ @slice.attr('transform', "translate(#{[@$controller.chartWidth / 2,@$controller.chartHeight / 2]})")
25
+ .on('mouseover', @_mouseOver.bind(@))
26
+ .on('mouseout', @_mouseOut.bind(@))
27
+ .on('mousemove', @_mouseMove.bind(@))
28
+ .on('click', @_click.bind(@))
29
+ addText: ->
30
+ @text = @slice.append('text')
31
+ .style('text-anchor', 'middle')
32
+ .style('pointer-events', 'none')
33
+ .style('fill', '#fff')
34
+ .attr('dy', '.35em')
35
+ adjustText: ->
36
+ return unless @$controller.arcs && @index != undefined
37
+ data = @$controller.arcs[@index]
38
+ centroid = @$controller.arc.centroid(data)
39
+ x = centroid[0]
40
+ y = centroid[1]
41
+ @text.attr 'transform', "translate(#{x},#{y})"
42
+ .text @labelFn(@$scope)
43
+ afterDraw: ->
44
+ @adjustText()
45
+ _mouseOver: ->
46
+ d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}")
47
+ .classed('hidden', false)
48
+ .style('left', d3.event.pageX + 'px')
49
+ .style('top', ((d3.event.pageY - 80 ) / 2) + 'px')
50
+ _mouseMove: (d, i) ->
51
+ d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}")
52
+ .style('left', d3.event.pageX + 'px')
53
+ .style('top', ((d3.event.pageY - 80 ) / 2) + 'px')
54
+ _mouseOut: (d, i) ->
55
+ d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}").classed('hidden', true)
56
+ _click: ->
57
+ paths = @$controller.chartLayer.selectAll('path')
58
+ paths.selectAll('animateTransform').remove()
59
+ reduce = !@path.attr('transform') || (@path.attr('transform').strip() == "translate(0,0)scale(1,1)")
60
+ paths.transition(@transition).attr('transform',"translate(0,0) scale(1,1)")
61
+ return unless reduce
62
+ theta = (@$controller.arcs[@index].endAngle + @$controller.arcs[@index].startAngle)/2
63
+ x = 10 * Math.cos (Math.PI / 2) - theta
64
+ y = -10 * Math.sin (Math.PI / 2) - theta
65
+ @path.transition(@transition).attr('transform',"translate(#{x},#{y}) scale(1.25,1.25)")
66
+
67
+ @register(MaterialRaingular.d3.Directives.MrD3PieSlice)
@@ -22,11 +22,15 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
22
22
  y = @bar.attr('y')
23
23
  usedSpace = 0
24
24
  key = @bar.node().$$hashKey?.replace(':','_') #TODO: Not Dependable
25
+ fill = null
26
+ fillRegex = /.*\(([0-9]+\, [0-9]+\, [0-9]+).*\)/
25
27
  @parent.holder.selectAll("text.bar.#{key}").remove()
28
+ length = @bars().nodes().length
26
29
  for rect,i in @bars().nodes()
27
30
  bar = d3.select(rect)
28
31
  bar.attr('class',"#{i} bar")
29
- bar.attr('fill',"rgba(1,1,1,#{1 - (0.1 * i)})")
32
+ fill = fill || bar.attr('fill')?.match(fillRegex)?[1] || '0,0,0'
33
+ bar.attr('fill',"rgba(#{fill},#{1 - i/length})")
30
34
  text = @parent.holder.append('text')
31
35
  .style("text-anchor","middle")
32
36
  .attr('class',"#{i} bar text #{key}")
@@ -3,8 +3,8 @@ class XAxisModel extends AngularLinkModel
3
3
  initialize: ->
4
4
  @parent = @$controller.compact()[0]
5
5
  @options = @parent.options
6
- @parent._xAxis = @axis = d3.select(@$element[0])
7
- @axis.attr('transform',"translate(0,#{@parent.height()})")
6
+ @parent._xAxis = @
7
+ @axis = d3.select(@$element[0])
8
8
  @label = @$parse @$attrs.mrD3Label
9
9
  @domain = @$parse @$attrs.mrD3Domain
10
10
  @$scope.$watchCollection @domain, @adjustAxis.bind(@)
@@ -13,13 +13,17 @@ class XAxisModel extends AngularLinkModel
13
13
  @adjustAxis(true)
14
14
  adjustAxis: (newVal,oldVal) ->
15
15
  return if newVal == oldVal
16
+ @axis.attr('transform',"translate(0,#{@parent.height()})")
16
17
  @parent.xAxis.domain(@domain(@$scope)) if @domain(@$scope)
17
18
  @axis.call(d3.axisBottom(@parent.xAxis))
18
- @labelEl.text(@label(@$scope)) if @label(@$scope)
19
19
  @parent.adjustBars()
20
+ @adjustLabel()
20
21
  appendLabel: ->
21
22
  @labelEl = @parent.holder.append('text')
22
- .attr('x', @parent.width()/2)
23
- .attr('y', @parent.height() + (@options.margins.bottom + 30) / 2)
24
23
  .style("text-anchor","middle")
24
+ @adjustLabel()
25
+ adjustLabel: ->
26
+ @labelEl.attr('x', @parent.width()/2)
27
+ .attr('y', @parent.height() + (@options.margins.bottom + 30) / 2)
28
+ .text(@label(@$scope)) if @label(@$scope)
25
29
  @register(MaterialRaingular.d3.Directives.MrD3XAxis)
@@ -3,7 +3,8 @@ class YAxisModel extends AngularLinkModel
3
3
  initialize: ->
4
4
  @parent = @$controller.compact()[0]
5
5
  @options = @parent.options
6
- @parent._yAxis = @axis = d3.select(@$element[0])
6
+ @parent._yAxis = @
7
+ @axis = d3.select(@$element[0])
7
8
  @label = @$parse @$attrs.mrD3Label
8
9
  @domain = @$parse @$attrs.mrD3Domain
9
10
  @$scope.$watchCollection @domain, @adjustAxis.bind(@)
@@ -16,11 +17,14 @@ class YAxisModel extends AngularLinkModel
16
17
  @axis.call(d3.axisLeft(@parent.yAxis))
17
18
  @labelEl.text(@label(@$scope)) if @label(@$scope)
18
19
  @parent.adjustBars()
20
+ @adjustLabel()
19
21
  appendLabel: ->
20
22
  @labelEl = @parent.holder.append('text')
21
23
  .attr("transform", "rotate(-90)")
22
- .attr("y", - (@options.margins.left + 30)/2)
23
- .attr("x",0 - (@parent.height() / 2))
24
24
  .attr("dy", "1em")
25
25
  .style("text-anchor", "middle")
26
+ @adjustLabel()
27
+ adjustLabel: ->
28
+ @labelEl.attr("y", - (@options.margins.left + 30)/2)
29
+ .attr("x",0 - (@parent.height() / 2))
26
30
  @register(MaterialRaingular.d3.Directives.MrD3YAxis)
@@ -1,5 +1,5 @@
1
1
  module MaterialRaingular
2
2
  module D3
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material_raingular-d3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moody
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,8 +76,10 @@ files:
76
76
  - lib/assets/javascripts/material_raingular/d3/extensions.coffee
77
77
  - lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/controller.coffee
78
78
  - lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/directive.coffee
79
+ - lib/assets/javascripts/material_raingular/d3/pie_chart/controller.coffee
79
80
  - lib/assets/javascripts/material_raingular/d3/pie_chart/directive.coffee
80
- - lib/assets/javascripts/material_raingular/d3/pie_chart/linkmodel.coffee
81
+ - lib/assets/javascripts/material_raingular/d3/pie_slice/directive.coffee
82
+ - lib/assets/javascripts/material_raingular/d3/pie_slice/linkmodel.coffee
81
83
  - lib/assets/javascripts/material_raingular/d3/ring_chart/directive.coffee
82
84
  - lib/assets/javascripts/material_raingular/d3/ring_chart/linkmodel.coffee
83
85
  - lib/assets/javascripts/material_raingular/d3/ring_chart/widget_controller.coffee
@@ -1,39 +0,0 @@
1
- class PieChartModel extends AngularLinkModel
2
- @inject('$timeout')
3
- initialize: ->
4
- @svg = d3.select(@$element[0]).append('svg')
5
- @chartLayer = @svg.append('g').classed('chartLayer', true)
6
- data = Object.map(@$scope.$eval(@$attrs.d3Data))(@cast.bind(@))
7
- @setSize(data)
8
- @drawChart(data)
9
- @$scope.$watchCollection @$attrs.d3Data, @redrawChart.bind(@)
10
- cast: (key,val) -> {name: key.titleize(), value: val}
11
- redrawChart: (obj) ->
12
- data = Object.map(@$scope.$eval(@$attrs.d3Data))(@cast.bind(@))
13
- @drawChart(data)
14
-
15
- setSize: (data) ->
16
- @options = @$scope.$eval(@$attrs.d3Options) || {}
17
- @width = @options.width || 960
18
- @height = @options.height || 500
19
- @color = @options.color || '6b486b'
20
- @margin = @options.margin || {top: 40,left: 0,bottom: 40,right: 0}
21
- @chartWidth = @width - (@margin.left + @margin.right)
22
- @chartHeight = @height - (@margin.top + @margin.bottom)
23
- @svg.attr('width', @width).attr 'height', @height
24
- @chartLayer.attr('width', @chartWidth).attr('height', @chartHeight).attr 'transform', "translate(#{[@margin.left,@margin.top]})"
25
-
26
- drawChart: (data) ->
27
- @chartLayer.selectAll('g').remove()
28
- arcs = d3.pie().sort(null).value((d) -> d.value)(data)
29
- arc = d3.arc().outerRadius(@chartHeight / 2).innerRadius(@chartHeight / 4).padAngle(0.03).cornerRadius(8) #/ <- I hate atom right now
30
- pieG = @chartLayer.selectAll('g').data([ data ]).enter().append('g').attr('transform', "translate(#{[@chartWidth / 2,@chartHeight / 2]})")
31
- block = pieG.selectAll('.arc').data(arcs)
32
- newBlock = block.enter().append('g').classed('arc', true)
33
- newBlock.append('path').attr('d', arc).attr('id', (d, i) -> 'arc-' + i)
34
- .attr('stroke', 'gray').attr 'fill', (d, i) -> d3.interpolateCool Math.random()
35
- newBlock.append('text').attr('dx', 55).attr('dy', -5).append('textPath').attr('xlink:href', (d, i) ->'#arc-' + i)
36
- .text (d) -> d.data.name
37
- return
38
-
39
- @register(MaterialRaingular.d3.Directives.MrD3PieChart)