material_raingular-d3 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/material_raingular/d3/bar/linkmodel.coffee +14 -0
- data/lib/assets/javascripts/material_raingular/d3/bar_chart/controller.coffee +1 -1
- data/lib/assets/javascripts/material_raingular/d3/bar_chart/directive.coffee +6 -5
- data/lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/controller.coffee +1 -1
- data/lib/assets/javascripts/material_raingular/d3/horizontal_bar_chart/directive.coffee +6 -5
- data/lib/assets/javascripts/material_raingular/d3/pie_chart/controller.coffee +2 -0
- data/lib/assets/javascripts/material_raingular/d3/pie_slice/linkmodel.coffee +3 -1
- data/lib/assets/javascripts/material_raingular/d3/stacked_bar/controller.coffee +40 -15
- data/lib/material_raingular/d3/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d6691c0e4cac4a21e949379be35b4daa25c26c
|
4
|
+
data.tar.gz: 3292ef3d4130a85df2713d417783fd51bbe3ccb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe8a3145d09113d256bb647aa4ca33ddbea2e4c11795a0d16c317b86de2920e0b297492a969041714b860add3e0b84f3d12d6dfd0f2c7241816b626163280ebc
|
7
|
+
data.tar.gz: c55186743a52ae8aa187d12af31b9e7e7dd66fa81385cdcbeedec7ae457a98900b3423b1bdc6639eea83ae44ce300499b2abd98d63d332ea4243a48d2a8b35c0
|
@@ -18,4 +18,18 @@ class BarModel extends AngularLinkModel
|
|
18
18
|
@bar.attr('raw-size',@size(@$scope))
|
19
19
|
@bar.attr('label', @label(@$scope))
|
20
20
|
@changeOptions(@options(@$scope))
|
21
|
+
@bar.on('mouseover', @_mouseOver.bind(@))
|
22
|
+
.on('mouseout', @_mouseOut.bind(@))
|
23
|
+
.on('mousemove', @_mouseMove.bind(@))
|
24
|
+
_mouseOver: ->
|
25
|
+
d3.select("#tip-#{@parent.indexOf(@bar._groups[0][0])}#{parseFloat(@size(@$scope)).toFixed()}")
|
26
|
+
.classed('hidden', false)
|
27
|
+
.style('left',(d3.event.pageX + 10) + 'px')
|
28
|
+
.style('top', (d3.event.pageY + 10) + 'px')
|
29
|
+
_mouseMove: (d, i) ->
|
30
|
+
d3.select("#tip-#{@parent.indexOf(@bar._groups[0][0])}#{parseFloat(@size(@$scope)).toFixed()}")
|
31
|
+
.style('left',(d3.event.pageX + 10) + 'px')
|
32
|
+
.style('top', (d3.event.pageY + 10) + 'px')
|
33
|
+
_mouseOut: (d, i) ->
|
34
|
+
d3.select("#tip-#{@parent.indexOf(@bar._groups[0][0])}#{parseFloat(@size(@$scope)).toFixed()}").classed('hidden', true)
|
21
35
|
@register(MaterialRaingular.d3.Directives.MrD3Bar)
|
@@ -28,7 +28,7 @@ class MaterialRaingular.d3.Directives.MrD3BarChartModel extends AngularDirective
|
|
28
28
|
for bar in @bars().nodes()
|
29
29
|
rect = d3.select(bar)
|
30
30
|
@xDomain[@indexOf(bar)] = rect.attr('label')
|
31
|
-
height = (rect.attr('raw-size') / @maxValue()) * @
|
31
|
+
height = (rect.attr('raw-size') / @maxValue()) * @height()
|
32
32
|
rect.attr('y',@height() - height)
|
33
33
|
rect.attr('height',height)
|
34
34
|
@xAxis.domain(@xDomain)
|
@@ -7,15 +7,16 @@ class MrD3BarChart extends AngularDirective
|
|
7
7
|
replace: true
|
8
8
|
template: "<svg height='100%' width='100%'><g ng-transclude></g></svg>"
|
9
9
|
###
|
10
|
+
NOTE:: Must use track by in ng-repeat to make function properly
|
10
11
|
Usage Slim syntax
|
11
12
|
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}]"
|
12
|
-
mr-d3-bar.thingy ng-repeat="data in dataSet" mr-d3-label="data.l" mr-d3-value="data.v"
|
13
|
+
mr-d3-bar.thingy ng-repeat="data in dataSet track by $index" mr-d3-label="data.l" mr-d3-value="data.v"
|
13
14
|
mr-d3-bar mr-d3-label="'this'" mr-d3-value="'200'"
|
14
15
|
mr-d3-y-axis ng-init="domain = [37,0]" mr-d3-label="'Value'" mr-d3-domain='domain'
|
15
16
|
|
16
|
-
mr-d3-stacked-bar mr-d3-label="'CA'"
|
17
|
-
mr-d3-bar ng-repeat="data in [10,4,7]" mr-d3-label="data" mr-d3-value="data"
|
18
|
-
mr-d3-stacked-bar mr-d3-label="'AZ'"
|
19
|
-
mr-d3-bar ng-repeat="data in [10,4,7]" mr-d3-label="data" mr-d3-value="data"
|
17
|
+
mr-d3-stacked-bar mr-d3-label="'CA'" mr-d3-stacked="true"
|
18
|
+
mr-d3-bar ng-repeat="data in [10,4,7] track by $index" mr-d3-label="data" mr-d3-value="data"
|
19
|
+
mr-d3-stacked-bar mr-d3-label="'AZ'" mr-d3-stacked="true"
|
20
|
+
mr-d3-bar ng-repeat="data in [10,4,7] track by $index" mr-d3-label="data" mr-d3-value="data"
|
20
21
|
mr-d3-x-axis mr-d3-label="'Arbitrary'"
|
21
22
|
###
|
@@ -29,7 +29,7 @@ class MaterialRaingular.d3.Directives.MrD3HorizontalBarChartModel extends Angula
|
|
29
29
|
rect = d3.select(bar)
|
30
30
|
@yDomain[@indexOf(bar)] = rect.attr('label')
|
31
31
|
width = (rect.attr('raw-size') / @maxValue()) * @width()
|
32
|
-
rect.attr('width',width)
|
32
|
+
rect.attr('width',width || 0)
|
33
33
|
@yAxis.domain(angular.copy(@yDomain).reverse())
|
34
34
|
for rect in @bars().nodes()
|
35
35
|
d3.select(rect).attr('height',@yAxis.bandwidth())
|
@@ -7,15 +7,16 @@ class MrD3HorizontalBarChart extends AngularDirective
|
|
7
7
|
replace: true
|
8
8
|
template: "<svg height='100%' width='100%'><g ng-transclude></g></svg>"
|
9
9
|
###
|
10
|
+
NOTE:: Must use track by in ng-repeat to make function properly
|
10
11
|
Usage Slim Syntax
|
11
12
|
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}]"
|
12
|
-
mr-d3-bar.thingy ng-repeat="data in dataSet" mr-d3-label="data.l" mr-d3-value="data.v"
|
13
|
+
mr-d3-bar.thingy ng-repeat="data in dataSet track by $index" mr-d3-label="data.l" mr-d3-value="data.v"
|
13
14
|
mr-d3-bar mr-d3-label="'this'" mr-d3-value="'200'"
|
14
15
|
mr-d3-x-axis ng-init="domain = [0,37]" mr-d3-label="'Value'" mr-d3-domain='domain'
|
15
16
|
|
16
|
-
mr-d3-stacked-bar mr-d3-label="'CA'"
|
17
|
-
mr-d3-bar ng-repeat="data in [10,4,7]" mr-d3-label="data" mr-d3-value="data"
|
18
|
-
mr-d3-stacked-bar mr-d3-label="'AZ'"
|
19
|
-
mr-d3-bar ng-repeat="data in [10,4,7]" mr-d3-label="data" mr-d3-value="data"
|
17
|
+
mr-d3-stacked-bar mr-d3-label="'CA'" mr-d3-stacked="true"
|
18
|
+
mr-d3-bar ng-repeat="data in [10,4,7] track by $index" mr-d3-label="data" mr-d3-value="data"
|
19
|
+
mr-d3-stacked-bar mr-d3-label="'AZ'" mr-d3-stacked="true"
|
20
|
+
mr-d3-bar ng-repeat="data in [10,4,7] track by $index" mr-d3-label="data" mr-d3-value="data"
|
20
21
|
mr-d3-y-axis mr-d3-label="'Arbitrary'"
|
21
22
|
###
|
@@ -26,6 +26,8 @@ class MaterialRaingular.d3.Directives.PieChartModel extends AngularDirectiveMode
|
|
26
26
|
return unless index >= 0
|
27
27
|
@slices.splice(index,1)
|
28
28
|
@values.splice(index,1)
|
29
|
+
for slice in @slices
|
30
|
+
slice.index = @slices.indexOf(slice)
|
29
31
|
@drawChart()
|
30
32
|
changeData: (slice,value) ->
|
31
33
|
@slices.push(slice) unless @slices.includes(slice)
|
@@ -26,6 +26,7 @@ class PieSliceModel extends AngularLinkModel
|
|
26
26
|
.on('mouseout', @_mouseOut.bind(@))
|
27
27
|
.on('mousemove', @_mouseMove.bind(@))
|
28
28
|
.on('click', @_click.bind(@))
|
29
|
+
@afterDraw()
|
29
30
|
addText: ->
|
30
31
|
@text = @slice.append('text')
|
31
32
|
.style('text-anchor', 'middle')
|
@@ -39,6 +40,7 @@ class PieSliceModel extends AngularLinkModel
|
|
39
40
|
x = centroid[0]
|
40
41
|
y = centroid[1]
|
41
42
|
@text.attr 'transform', "translate(#{x},#{y})"
|
43
|
+
.style('display','block')
|
42
44
|
.text @labelFn(@$scope)
|
43
45
|
bbox = @text.node().getBBox()
|
44
46
|
topLeft =
|
@@ -57,7 +59,7 @@ class PieSliceModel extends AngularLinkModel
|
|
57
59
|
_pointIsInArc(topRight, @$controller, @index) &&
|
58
60
|
_pointIsInArc(bottomLeft, @$controller, @index) &&
|
59
61
|
_pointIsInArc(bottomRight, @$controller, @index)
|
60
|
-
@text.
|
62
|
+
@text.style('display', 'none') unless visible
|
61
63
|
removeSlice: -> @$controller.removeSlice(@)
|
62
64
|
afterDraw: ->
|
63
65
|
@adjustText()
|
@@ -6,9 +6,11 @@ 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
|
+
@stacked = @$parse @$element.attr('mr-d3-stacked')
|
9
10
|
@texts = []
|
10
11
|
@$scope.$watch @label.bind(@), @adjustBars.bind(@)
|
11
12
|
@$scope.$watch @size.bind(@), @adjustBars.bind(@)
|
13
|
+
@$scope.$watch @stacked.bind(@), @adjustBars.bind(@)
|
12
14
|
@$scope.$on '$destroy', @removeText.bind(@)
|
13
15
|
@adjustBars()
|
14
16
|
bars: -> @bar.selectAll('rect')
|
@@ -16,6 +18,7 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
|
|
16
18
|
rawSize: -> (@bars().nodes().map (rect) => d3.select(rect).attr('raw-size')).sum()
|
17
19
|
removeText: ->
|
18
20
|
text.remove() for text in @texts
|
21
|
+
@adjustBars()
|
19
22
|
adjustBars: ->
|
20
23
|
@bar.attr('raw-size',@rawSize() || 0)
|
21
24
|
@bar.attr('label', @label(@$scope))
|
@@ -30,6 +33,9 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
|
|
30
33
|
fillRegex = /.*\(([0-9]+\, [0-9]+\, [0-9]+).*\)/
|
31
34
|
@parent.holder.selectAll("text.bar.#{key}").remove()
|
32
35
|
length = @bars().nodes().length
|
36
|
+
nonzero = 0
|
37
|
+
for rect,i in @bars().nodes()
|
38
|
+
nonzero += 1 if d3.select(rect).attr('raw-size') > 0
|
33
39
|
for rect,i in @bars().nodes()
|
34
40
|
bar = d3.select(rect)
|
35
41
|
bar.attr('class',"#{i} bar")
|
@@ -48,29 +54,48 @@ class MaterialRaingular.d3.Directives.MrD3StackedBar extends AngularDirectiveMod
|
|
48
54
|
if @direction == 'vertical'
|
49
55
|
ratio = height / @bar.attr('raw-size')
|
50
56
|
barHeight = ratio * bar.attr('raw-size')
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
bar.attr('height',barHeight || 0)
|
58
|
+
if @stacked(@$scope)
|
59
|
+
usedSpace += barHeight || 0
|
60
|
+
bar.attr('x',x)
|
61
|
+
bar.attr('width',width || 0)
|
62
|
+
bar.attr('y',@parent.height() - usedSpace)
|
63
|
+
else
|
64
|
+
barWidth = width / nonzero
|
65
|
+
bar.attr('width', barWidth)
|
66
|
+
bar.attr('x', parseFloat(x) + usedSpace)
|
67
|
+
bar.attr('y', @parent.height() - barHeight)
|
68
|
+
usedSpace += barWidth if barHeight > 0
|
56
69
|
text.attr('x', -parseFloat(bar.attr('y')) - parseFloat(bar.attr('height'))/2)
|
57
|
-
.attr('y',parseFloat(bar.attr('x')) + parseFloat(bar.attr('width')))
|
70
|
+
.attr('y',parseFloat(bar.attr('x')) + parseFloat(bar.attr('width'))/2 + 5)
|
58
71
|
.attr('transform','rotate(-90)')
|
59
|
-
.
|
72
|
+
bbox = text.node().getBBox()
|
73
|
+
if (bbox.width > barHeight) || (bbox.height > width || barWidth)
|
74
|
+
text.style('display','none')
|
75
|
+
else
|
76
|
+
text.style('pointer-events', 'none').style('display', 'block')
|
60
77
|
else
|
61
78
|
ratio = width / @bar.attr('raw-size')
|
62
79
|
barWidth = ratio * bar.attr('raw-size')
|
63
|
-
bar.attr('y',y)
|
64
|
-
bar.attr('height',height)
|
65
|
-
bar.attr('x',usedSpace)
|
66
80
|
bar.attr('width',barWidth || 0)
|
67
|
-
|
68
|
-
|
81
|
+
if @stacked(@$scope)
|
82
|
+
bar.attr('y',y)
|
83
|
+
bar.attr('height',height || 0)
|
84
|
+
bar.attr('x',usedSpace)
|
85
|
+
usedSpace += barWidth || 0
|
86
|
+
else
|
87
|
+
barHeight = height / nonzero
|
88
|
+
bar.attr('y',parseFloat(y) + usedSpace)
|
89
|
+
bar.attr('height',barHeight)
|
90
|
+
bar.attr('x',0)
|
91
|
+
usedSpace += barHeight if barWidth > 0
|
92
|
+
text.attr('x', parseFloat(bar.attr('width' || 0))/2 + parseFloat(bar.attr('x')))
|
69
93
|
.attr('y',parseFloat(bar.attr('y')) + parseFloat(bar.attr('height'))/2 + 5)
|
70
|
-
|
71
|
-
|
94
|
+
bbox = text.node().getBBox()
|
95
|
+
if bbox.width > barWidth || (bbox.height > height || barHeight)
|
96
|
+
text.style('display', 'none')
|
72
97
|
else
|
73
|
-
text.style('pointer-events', 'none')
|
98
|
+
text.style('pointer-events', 'none').style('display', 'block')
|
74
99
|
_mouseOver: (d,i,parentLabel) ->
|
75
100
|
d3.select("#tip-table-" + parentLabel)
|
76
101
|
.classed('hidden', false)
|
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.
|
4
|
+
version: 0.3.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-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|