material_raingular-d3 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2227d8f78026d1958580858a9a76063132362a2
4
- data.tar.gz: fd3300c5b2d837cd305b3eddbda1f744f19f15f0
3
+ metadata.gz: a4d591e5ddc3b5ce40657d769db5dd414cc94614
4
+ data.tar.gz: 7ff1d5cb8e6102c46c17508441c75e5b8ce73ddc
5
5
  SHA512:
6
- metadata.gz: bfc86fb047b62bb95cd212ad1f47ff38b8ff861ed7bfe9018d03def048b120262d6f71af532ac13ec76a66021fc3607bcd7a60462c1e406f8d336c5562124333
7
- data.tar.gz: 237915a229448df597d651c960091ca0c9e005880e55dbc62a3cc976e9704ca6c87b2a16578b63dc396209e6cabcc585d075dc1eb209d923047a53ea4d5c380e
6
+ metadata.gz: 0ad9ab358094a62c455344ca3057e7fb90aaed576e14e2f2bbb42e3b4b1902b48d45d9fba21ce8d51d8ea0be5de1c053bc5d33e12e2adcdd4caffb4fb08cd174
7
+ data.tar.gz: e4c91e62dc89717dc1f60bb7425bc69a434d87fd7223773c1659dc7bbfa223d79675c49f9f952e8b5696ca10259ae9bc6924e58fbe6b3d7b5d95e7b23aca0e7f
@@ -21,6 +21,11 @@ class MaterialRaingular.d3.Directives.PieChartModel extends AngularDirectiveMode
21
21
  addSlice: (slice) ->
22
22
  @slices.push(slice) unless @slices.includes(slice)
23
23
  return @slices.index(slice)
24
+ removeSlice: (slice) ->
25
+ index = @slices.index(slice)
26
+ @slices.splice(index,1)
27
+ @values.splice(index,1)
28
+ @drawChart()
24
29
  changeData: (slice,value) ->
25
30
  @slices.push(slice) unless @slices.includes(slice)
26
31
  index = @slices.indexOf(slice)
@@ -4,7 +4,7 @@ class PieSliceModel extends AngularLinkModel
4
4
  @options = @$parse(@$attrs.mrD3Options || '{}')
5
5
  @slice = d3.select(@$element[0])
6
6
  @index = @$controller.addSlice(@)
7
- @path = @slice.append('path').attr('id', 'arc-' + @index)
7
+ @path = @slice.append('path').attr("id", 'arc-' + @index).attr('stroke', '#FFF')
8
8
  @transition = d3.transition().duration(300).ease(d3.easeLinear)
9
9
  @labelFn = @$parse @$attrs.mrD3Label
10
10
  @valueFn = @$parse @$attrs.mrD3Value
@@ -13,10 +13,10 @@ class PieSliceModel extends AngularLinkModel
13
13
  @$scope.$watch @valueFn.bind(@), @changeValue.bind(@)
14
14
  @$scope.$watch @labelFn.bind(@), @adjustText.bind(@)
15
15
  @$scope.$watch @options.bind(@), @changeOptions.bind(@), true
16
+ @$scope.$on '$destroy', @removeSlice.bind(@)
16
17
  changeOptions: (newVal) ->
17
18
  return unless newVal
18
19
  @path.attr 'fill', newVal.fill || d3.interpolateCool Math.random(@index)
19
-
20
20
  changeValue: (newVal,oldVal) ->
21
21
  return unless newVal
22
22
  @index = @$controller.changeData(@,newVal)
@@ -40,17 +40,36 @@ class PieSliceModel extends AngularLinkModel
40
40
  y = centroid[1]
41
41
  @text.attr 'transform', "translate(#{x},#{y})"
42
42
  .text @labelFn(@$scope)
43
+ bbox = @text.node().getBBox()
44
+ topLeft =
45
+ x : x + bbox.x,
46
+ y : y + bbox.y
47
+ topRight =
48
+ x : topLeft.x + bbox.width,
49
+ y : topLeft.y
50
+ bottomLeft =
51
+ x : topLeft.x,
52
+ y : topLeft.y + bbox.height
53
+ bottomRight =
54
+ x : topLeft.x + bbox.width,
55
+ y : topLeft.y + bbox.height
56
+ visible = _pointIsInArc(topLeft, @$controller, @index) &&
57
+ _pointIsInArc(topRight, @$controller, @index) &&
58
+ _pointIsInArc(bottomLeft, @$controller, @index) &&
59
+ _pointIsInArc(bottomRight, @$controller, @index)
60
+ @text.attr('display', 'none') unless visible
61
+ removeSlice: -> @$controller.removeSlice(@)
43
62
  afterDraw: ->
44
63
  @adjustText()
45
64
  _mouseOver: ->
46
65
  d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}")
47
66
  .classed('hidden', false)
48
- .style('left', d3.event.pageX + 'px')
49
- .style('top', ((d3.event.pageY - 80 ) / 2) + 'px')
67
+ .style('left',(d3.event.pageX + 10) + 'px')
68
+ .style('top', (d3.event.pageY + 10) + 'px')
50
69
  _mouseMove: (d, i) ->
51
70
  d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}")
52
- .style('left', d3.event.pageX + 'px')
53
- .style('top', ((d3.event.pageY - 80 ) / 2) + 'px')
71
+ .style('left',(d3.event.pageX + 10) + 'px')
72
+ .style('top', (d3.event.pageY + 10) + 'px')
54
73
  _mouseOut: (d, i) ->
55
74
  d3.select("#tip-#{@index}#{@valueFn(@$scope).toFixed()}").classed('hidden', true)
56
75
  _click: ->
@@ -63,5 +82,14 @@ class PieSliceModel extends AngularLinkModel
63
82
  x = 10 * Math.cos (Math.PI / 2) - theta
64
83
  y = -10 * Math.sin (Math.PI / 2) - theta
65
84
  @path.transition(@transition).attr('transform',"translate(#{x},#{y}) scale(1.25,1.25)")
85
+ _pointIsInArc = (pt, controller, index) ->
86
+ r1 = 0
87
+ r2 = controller.chartHeight / 2
88
+ theta1 = controller.arcs[index].startAngle
89
+ theta2 = controller.arcs[index].endAngle
90
+ dist = pt.x * pt.x + pt.y * pt.y
91
+ angle = Math.atan2(pt.x, -pt.y)
92
+ angle = if angle < 0 then angle + Math.PI * 2 else angle
93
+ r1 * r1 <= dist && dist <= r2 * r2 && theta1 <= angle && angle <= theta2
66
94
 
67
95
  @register(MaterialRaingular.d3.Directives.MrD3PieSlice)
@@ -6,12 +6,16 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
6
6
  @parent ?= @$element.parent().controller('mrD3HorizontalBarChart')
7
7
  @bar = d3.select(@$element[0])
8
8
  @label = @$parse @$element.attr('mr-d3-label')
9
+ @texts = []
9
10
  @$scope.$watch @label.bind(@), @adjustBars.bind(@)
10
11
  @$scope.$watch @size.bind(@), @adjustBars.bind(@)
12
+ @$scope.$on '$destroy', @removeText.bind(@)
11
13
  @adjustBars()
12
14
  bars: -> @bar.selectAll('rect')
13
15
  size: -> if @direction == 'vertical' then @bar.attr('height') else @bar.attr('width')
14
16
  rawSize: -> (@bars().nodes().map (rect) => d3.select(rect).attr('raw-size')).sum()
17
+ removeText: ->
18
+ text.remove() for text in @texts
15
19
  adjustBars: ->
16
20
  @bar.attr('raw-size',@rawSize() || 0)
17
21
  @bar.attr('label', @label(@$scope))
@@ -31,10 +35,16 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
31
35
  bar.attr('class',"#{i} bar")
32
36
  fill = fill || bar.attr('fill')?.match(fillRegex)?[1] || '0,0,0'
33
37
  bar.attr('fill',"rgba(#{fill},#{1 - i/length})")
38
+ parentLabel = rect.parentNode.attributes['label'].value.slice(-2)
39
+ bar.on('mouseover', @_mouseOver.bind(null,rect,i,parentLabel))
40
+ .on('mouseout', @_mouseOut.bind(null,rect,i,parentLabel))
41
+ .on('mousemove', @_mouseMove.bind(null,rect,i,parentLabel))
34
42
  text = @parent.holder.append('text')
35
43
  .style("text-anchor","middle")
44
+ .style("fill", "#FFF")
36
45
  .attr('class',"#{i} bar text #{key}")
37
46
  .text(bar.attr('label'))
47
+ @texts.push(text)
38
48
  if @direction == 'vertical'
39
49
  ratio = height / @bar.attr('raw-size')
40
50
  barHeight = ratio * bar.attr('raw-size')
@@ -46,6 +56,7 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
46
56
  text.attr('x', -parseFloat(bar.attr('y')) - parseFloat(bar.attr('height'))/2)
47
57
  .attr('y',parseFloat(bar.attr('x')) + parseFloat(bar.attr('width')))
48
58
  .attr('transform','rotate(-90)')
59
+ .style('pointer-events', 'none')
49
60
  else
50
61
  ratio = width / @bar.attr('raw-size')
51
62
  barWidth = ratio * bar.attr('raw-size')
@@ -55,4 +66,22 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
55
66
  bar.attr('width',barWidth)
56
67
  usedSpace += barWidth
57
68
  text.attr('x', parseFloat(bar.attr('width'))/2 + parseFloat(bar.attr('x')))
58
- .attr('y',parseFloat(bar.attr('y')) + parseFloat(bar.attr('height')))
69
+ .attr('y',parseFloat(bar.attr('y')) + parseFloat(bar.attr('height'))/2 + 5)
70
+ if text.node().getBBox().width > barWidth
71
+ text.attr('display', 'none')
72
+ else
73
+ text.style('pointer-events', 'none')
74
+ _mouseOver: (d,i,parentLabel) ->
75
+ d3.select("#tip-table-" + parentLabel)
76
+ .classed('hidden', false)
77
+ .style('left', (d3.event.pageX + 10) + 'px')
78
+ .style('top', (d3.event.pageY + 10) + 'px')
79
+ .select("#tip-" + i).classed('hidden', false)
80
+ _mouseMove: (d,i,parentLabel) ->
81
+ d3.select("#tip-table-" + parentLabel)
82
+ .style('left', (d3.event.pageX + 10) + 'px')
83
+ .style('top', (d3.event.pageY + 10) + 'px')
84
+ _mouseOut: (d,i,parentLabel) ->
85
+ d3.select("#tip-table-" + parentLabel)
86
+ .classed('hidden', true)
87
+ .select("#tip-" + i).classed('hidden', true)
@@ -1,5 +1,5 @@
1
1
  module MaterialRaingular
2
2
  module D3
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
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.1
4
+ version: 0.2.0
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-30 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler