nvd3-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitmodules +3 -0
  2. data/README.md +101 -0
  3. data/lib/nvd3-rails.rb +1 -0
  4. data/lib/nvd3/rails.rb +8 -0
  5. data/lib/nvd3/rails/engine.rb +6 -0
  6. data/lib/nvd3/rails/version.rb +5 -0
  7. data/nvd3-rails.gemspec +21 -0
  8. data/vendor/assets/javascripts/nvd3-rails.js +7 -0
  9. data/vendor/assets/javascripts/nvd3/.git.sample/HEAD +1 -0
  10. data/vendor/assets/javascripts/nvd3/.git.sample/config +13 -0
  11. data/vendor/assets/javascripts/nvd3/.git.sample/description +1 -0
  12. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/applypatch-msg.sample +15 -0
  13. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/commit-msg.sample +24 -0
  14. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/post-update.sample +8 -0
  15. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-applypatch.sample +14 -0
  16. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-commit.sample +50 -0
  17. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-push.sample +53 -0
  18. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-rebase.sample +169 -0
  19. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/prepare-commit-msg.sample +36 -0
  20. data/vendor/assets/javascripts/nvd3/.git.sample/hooks/update.sample +128 -0
  21. data/vendor/assets/javascripts/nvd3/.git.sample/index +0 -0
  22. data/vendor/assets/javascripts/nvd3/.git.sample/info/exclude +6 -0
  23. data/vendor/assets/javascripts/nvd3/.git.sample/logs/HEAD +1 -0
  24. data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/heads/master +1 -0
  25. data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/remotes/origin/HEAD +1 -0
  26. data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.idx +0 -0
  27. data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.pack +0 -0
  28. data/vendor/assets/javascripts/nvd3/.git.sample/packed-refs +5 -0
  29. data/vendor/assets/javascripts/nvd3/.git.sample/refs/heads/master +1 -0
  30. data/vendor/assets/javascripts/nvd3/.git.sample/refs/remotes/origin/HEAD +1 -0
  31. data/vendor/assets/javascripts/nvd3/.gitignore +24 -0
  32. data/vendor/assets/javascripts/nvd3/LICENSE.md +49 -0
  33. data/vendor/assets/javascripts/nvd3/Makefile +56 -0
  34. data/vendor/assets/javascripts/nvd3/README.md +43 -0
  35. data/vendor/assets/javascripts/nvd3/build.bat +6 -0
  36. data/vendor/assets/javascripts/nvd3/deprecated/bar.html +198 -0
  37. data/vendor/assets/javascripts/nvd3/deprecated/bar.js +250 -0
  38. data/vendor/assets/javascripts/nvd3/deprecated/charts/cumulativeLineChart.js +174 -0
  39. data/vendor/assets/javascripts/nvd3/deprecated/charts/discreteBarChart.js +157 -0
  40. data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChart.js +159 -0
  41. data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChartDaily.js +168 -0
  42. data/vendor/assets/javascripts/nvd3/deprecated/charts/stackedAreaChart.js +177 -0
  43. data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.html +171 -0
  44. data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.js +334 -0
  45. data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.html +129 -0
  46. data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.js +222 -0
  47. data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.html +172 -0
  48. data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.js +152 -0
  49. data/vendor/assets/javascripts/nvd3/deprecated/lineChart-old.html +83 -0
  50. data/vendor/assets/javascripts/nvd3/deprecated/lineChartDaily.html +109 -0
  51. data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.html +173 -0
  52. data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.js +250 -0
  53. data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.html +137 -0
  54. data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.js +354 -0
  55. data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.html +144 -0
  56. data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.js +218 -0
  57. data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.html +142 -0
  58. data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.js +176 -0
  59. data/vendor/assets/javascripts/nvd3/deprecated/monthendAxis.html +99 -0
  60. data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.html +258 -0
  61. data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.js +226 -0
  62. data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.html +162 -0
  63. data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.js +249 -0
  64. data/vendor/assets/javascripts/nvd3/deprecated/pie.js +263 -0
  65. data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.html +110 -0
  66. data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.js +294 -0
  67. data/vendor/assets/javascripts/nvd3/deprecated/scatterFisheyeChart.js +418 -0
  68. data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.html +167 -0
  69. data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.js +261 -0
  70. data/vendor/assets/javascripts/nvd3/deprecated/stackedArea.js +286 -0
  71. data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart.html +183 -0
  72. data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart_old.html +137 -0
  73. data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.html +222 -0
  74. data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.js +297 -0
  75. data/vendor/assets/javascripts/nvd3/examples/bullet.html +96 -0
  76. data/vendor/assets/javascripts/nvd3/examples/bulletChart.html +94 -0
  77. data/vendor/assets/javascripts/nvd3/examples/crossfilter.html +167 -0
  78. data/vendor/assets/javascripts/nvd3/examples/crossfilterWithDimentions.html +180 -0
  79. data/vendor/assets/javascripts/nvd3/examples/crossfilterWithTables.html +288 -0
  80. data/vendor/assets/javascripts/nvd3/examples/cumulativeLineChart.html +155 -0
  81. data/vendor/assets/javascripts/nvd3/examples/discreteBarChart.html +116 -0
  82. data/vendor/assets/javascripts/nvd3/examples/dynamicTimeSeries.html +148 -0
  83. data/vendor/assets/javascripts/nvd3/examples/historicalBar.html +157 -0
  84. data/vendor/assets/javascripts/nvd3/examples/horizon.html +163 -0
  85. data/vendor/assets/javascripts/nvd3/examples/images/grey-minus.png +0 -0
  86. data/vendor/assets/javascripts/nvd3/examples/images/grey-plus.png +0 -0
  87. data/vendor/assets/javascripts/nvd3/examples/indentedtree.html +126 -0
  88. data/vendor/assets/javascripts/nvd3/examples/legend.html +75 -0
  89. data/vendor/assets/javascripts/nvd3/examples/line.html +95 -0
  90. data/vendor/assets/javascripts/nvd3/examples/lineChart.html +112 -0
  91. data/vendor/assets/javascripts/nvd3/examples/lineChartSVGResize.html +151 -0
  92. data/vendor/assets/javascripts/nvd3/examples/linePlusBarChart.html +114 -0
  93. data/vendor/assets/javascripts/nvd3/examples/linePlusBarWithFocusChart.html +128 -0
  94. data/vendor/assets/javascripts/nvd3/examples/lineTimeSeries.html +142 -0
  95. data/vendor/assets/javascripts/nvd3/examples/lineWithFisheyeChart.html +101 -0
  96. data/vendor/assets/javascripts/nvd3/examples/lineWithFocusChart.html +87 -0
  97. data/vendor/assets/javascripts/nvd3/examples/multiBar.html +92 -0
  98. data/vendor/assets/javascripts/nvd3/examples/multiBarChart.html +93 -0
  99. data/vendor/assets/javascripts/nvd3/examples/multiBarHorizontalChart.html +388 -0
  100. data/vendor/assets/javascripts/nvd3/examples/multiChart.html +93 -0
  101. data/vendor/assets/javascripts/nvd3/examples/nations.json +1 -0
  102. data/vendor/assets/javascripts/nvd3/examples/pie.html +93 -0
  103. data/vendor/assets/javascripts/nvd3/examples/pieChart.html +114 -0
  104. data/vendor/assets/javascripts/nvd3/examples/scatter.html +95 -0
  105. data/vendor/assets/javascripts/nvd3/examples/scatterChart.html +115 -0
  106. data/vendor/assets/javascripts/nvd3/examples/scatterPlusLineChart.html +116 -0
  107. data/vendor/assets/javascripts/nvd3/examples/sparkline.html +62 -0
  108. data/vendor/assets/javascripts/nvd3/examples/sparklinePlus.html +67 -0
  109. data/vendor/assets/javascripts/nvd3/examples/stackedArea.html +155 -0
  110. data/vendor/assets/javascripts/nvd3/examples/stackedAreaChart.html +245 -0
  111. data/vendor/assets/javascripts/nvd3/examples/stream_layers.js +35 -0
  112. data/vendor/assets/javascripts/nvd3/lib/cie.js +155 -0
  113. data/vendor/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
  114. data/vendor/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
  115. data/vendor/assets/javascripts/nvd3/lib/d3.v2.js +7033 -0
  116. data/vendor/assets/javascripts/nvd3/lib/d3.v2.min.js +4 -0
  117. data/vendor/assets/javascripts/nvd3/lib/fisheye.js +86 -0
  118. data/vendor/assets/javascripts/nvd3/lib/hive.js +80 -0
  119. data/vendor/assets/javascripts/nvd3/lib/horizon.js +192 -0
  120. data/vendor/assets/javascripts/nvd3/lib/sankey.js +292 -0
  121. data/vendor/assets/javascripts/nvd3/nv.d3.js +11762 -0
  122. data/vendor/assets/javascripts/nvd3/src/core.js +117 -0
  123. data/vendor/assets/javascripts/nvd3/src/models/axis.js +398 -0
  124. data/vendor/assets/javascripts/nvd3/src/models/backup/bullet.js +250 -0
  125. data/vendor/assets/javascripts/nvd3/src/models/backup/bulletChart.js +349 -0
  126. data/vendor/assets/javascripts/nvd3/src/models/bullet.js +377 -0
  127. data/vendor/assets/javascripts/nvd3/src/models/bulletChart.js +341 -0
  128. data/vendor/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +609 -0
  129. data/vendor/assets/javascripts/nvd3/src/models/discreteBar.js +327 -0
  130. data/vendor/assets/javascripts/nvd3/src/models/discreteBarChart.js +290 -0
  131. data/vendor/assets/javascripts/nvd3/src/models/distribution.js +146 -0
  132. data/vendor/assets/javascripts/nvd3/src/models/historicalBar.js +289 -0
  133. data/vendor/assets/javascripts/nvd3/src/models/indentedTree.js +306 -0
  134. data/vendor/assets/javascripts/nvd3/src/models/legend.js +203 -0
  135. data/vendor/assets/javascripts/nvd3/src/models/line.js +286 -0
  136. data/vendor/assets/javascripts/nvd3/src/models/lineChart.js +359 -0
  137. data/vendor/assets/javascripts/nvd3/src/models/lineDynTimeSeriesChart.js +434 -0
  138. data/vendor/assets/javascripts/nvd3/src/models/linePlusBarChart.js +422 -0
  139. data/vendor/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +657 -0
  140. data/vendor/assets/javascripts/nvd3/src/models/lineTimeSeriesChart.js +340 -0
  141. data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheye.js +197 -0
  142. data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +324 -0
  143. data/vendor/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +565 -0
  144. data/vendor/assets/javascripts/nvd3/src/models/multiAxisLineChart.js +312 -0
  145. data/vendor/assets/javascripts/nvd3/src/models/multiBar.js +416 -0
  146. data/vendor/assets/javascripts/nvd3/src/models/multiBarChart.js +445 -0
  147. data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +420 -0
  148. data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +415 -0
  149. data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +371 -0
  150. data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +403 -0
  151. data/vendor/assets/javascripts/nvd3/src/models/multiChart.js +444 -0
  152. data/vendor/assets/javascripts/nvd3/src/models/ohlcBar.js +365 -0
  153. data/vendor/assets/javascripts/nvd3/src/models/pie.js +358 -0
  154. data/vendor/assets/javascripts/nvd3/src/models/pieChart.js +281 -0
  155. data/vendor/assets/javascripts/nvd3/src/models/scatter.js +622 -0
  156. data/vendor/assets/javascripts/nvd3/src/models/scatterChart.js +576 -0
  157. data/vendor/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +577 -0
  158. data/vendor/assets/javascripts/nvd3/src/models/sparkline.js +179 -0
  159. data/vendor/assets/javascripts/nvd3/src/models/sparklinePlus.js +291 -0
  160. data/vendor/assets/javascripts/nvd3/src/models/stackedArea.js +336 -0
  161. data/vendor/assets/javascripts/nvd3/src/models/stackedAreaChart.js +453 -0
  162. data/vendor/assets/javascripts/nvd3/src/nv.d3.css +671 -0
  163. data/vendor/assets/javascripts/nvd3/src/tooltip.js +129 -0
  164. data/vendor/assets/javascripts/nvd3/src/utils.js +105 -0
  165. data/vendor/assets/javascripts/set-nvd3-env.js.erb +5 -0
  166. data/vendor/assets/stylesheets/nvd3-rails.css +3 -0
  167. metadata +233 -0
@@ -0,0 +1,146 @@
1
+
2
+ nv.models.distribution = function() {
3
+
4
+ //============================================================
5
+ // Public Variables with Default Settings
6
+ //------------------------------------------------------------
7
+
8
+ var margin = {top: 0, right: 0, bottom: 0, left: 0}
9
+ , width = 400 //technically width or height depending on x or y....
10
+ , size = 8
11
+ , axis = 'x' // 'x' or 'y'... horizontal or vertical
12
+ , getData = function(d) { return d[axis] } // defaults d.x or d.y
13
+ , color = nv.utils.defaultColor()
14
+ , scale = d3.scale.linear()
15
+ , domain
16
+ ;
17
+
18
+ //============================================================
19
+
20
+
21
+ //============================================================
22
+ // Private Variables
23
+ //------------------------------------------------------------
24
+
25
+ var scale0;
26
+
27
+ //============================================================
28
+
29
+
30
+ function chart(selection) {
31
+ selection.each(function(data) {
32
+ var availableLength = width - (axis === 'x' ? margin.left + margin.right : margin.top + margin.bottom),
33
+ naxis = axis == 'x' ? 'y' : 'x',
34
+ container = d3.select(this);
35
+
36
+
37
+ //------------------------------------------------------------
38
+ // Setup Scales
39
+
40
+ scale0 = scale0 || scale;
41
+
42
+ //------------------------------------------------------------
43
+
44
+
45
+ //------------------------------------------------------------
46
+ // Setup containers and skeleton of chart
47
+
48
+ var wrap = container.selectAll('g.nv-distribution').data([data]);
49
+ var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-distribution');
50
+ var gEnter = wrapEnter.append('g');
51
+ var g = wrap.select('g');
52
+
53
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
54
+
55
+ //------------------------------------------------------------
56
+
57
+
58
+ var distWrap = g.selectAll('g.nv-dist')
59
+ .data(function(d) { return d }, function(d) { return d.key });
60
+
61
+ distWrap.enter().append('g');
62
+ distWrap
63
+ .attr('class', function(d,i) { return 'nv-dist nv-series-' + i })
64
+ .style('stroke', function(d,i) { return color(d, i) });
65
+
66
+ var dist = distWrap.selectAll('line.nv-dist' + axis)
67
+ .data(function(d) { return d.values })
68
+ dist.enter().append('line')
69
+ .attr(axis + '1', function(d,i) { return scale0(getData(d,i)) })
70
+ .attr(axis + '2', function(d,i) { return scale0(getData(d,i)) })
71
+ d3.transition(distWrap.exit().selectAll('line.nv-dist' + axis))
72
+ .attr(axis + '1', function(d,i) { return scale(getData(d,i)) })
73
+ .attr(axis + '2', function(d,i) { return scale(getData(d,i)) })
74
+ .style('stroke-opacity', 0)
75
+ .remove();
76
+ dist
77
+ .attr('class', function(d,i) { return 'nv-dist' + axis + ' nv-dist' + axis + '-' + i })
78
+ .attr(naxis + '1', 0)
79
+ .attr(naxis + '2', size);
80
+ d3.transition(dist)
81
+ .attr(axis + '1', function(d,i) { return scale(getData(d,i)) })
82
+ .attr(axis + '2', function(d,i) { return scale(getData(d,i)) })
83
+
84
+
85
+ scale0 = scale.copy();
86
+
87
+ });
88
+
89
+ return chart;
90
+ }
91
+
92
+
93
+ //============================================================
94
+ // Expose Public Variables
95
+ //------------------------------------------------------------
96
+
97
+ chart.margin = function(_) {
98
+ if (!arguments.length) return margin;
99
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
100
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
101
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
102
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
103
+ return chart;
104
+ };
105
+
106
+ chart.width = function(_) {
107
+ if (!arguments.length) return width;
108
+ width = _;
109
+ return chart;
110
+ };
111
+
112
+ chart.axis = function(_) {
113
+ if (!arguments.length) return axis;
114
+ axis = _;
115
+ return chart;
116
+ };
117
+
118
+ chart.size = function(_) {
119
+ if (!arguments.length) return size;
120
+ size = _;
121
+ return chart;
122
+ };
123
+
124
+ chart.getData = function(_) {
125
+ if (!arguments.length) return getData;
126
+ getData = d3.functor(_);
127
+ return chart;
128
+ };
129
+
130
+ chart.scale = function(_) {
131
+ if (!arguments.length) return scale;
132
+ scale = _;
133
+ return chart;
134
+ };
135
+
136
+ chart.color = function(_) {
137
+ if (!arguments.length) return color;
138
+ color = nv.utils.getColor(_);
139
+ return chart;
140
+ };
141
+
142
+ //============================================================
143
+
144
+
145
+ return chart;
146
+ }
@@ -0,0 +1,289 @@
1
+ //TODO: consider deprecating and using multibar with single series for this
2
+ nv.models.historicalBar = function() {
3
+
4
+ //============================================================
5
+ // Public Variables with Default Settings
6
+ //------------------------------------------------------------
7
+
8
+ var margin = {top: 0, right: 0, bottom: 0, left: 0}
9
+ , width = 960
10
+ , height = 500
11
+ , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
12
+ , x = d3.scale.linear()
13
+ , y = d3.scale.linear()
14
+ , getX = function(d) { return d.x }
15
+ , getY = function(d) { return d.y }
16
+ , forceX = []
17
+ , forceY = [0]
18
+ , padData = false
19
+ , clipEdge = true
20
+ , color = nv.utils.defaultColor()
21
+ , xDomain
22
+ , yDomain
23
+ , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
24
+ ;
25
+
26
+ //============================================================
27
+
28
+
29
+ function chart(selection) {
30
+ selection.each(function(data) {
31
+ var availableWidth = width - margin.left - margin.right,
32
+ availableHeight = height - margin.top - margin.bottom,
33
+ container = d3.select(this);
34
+
35
+
36
+ //------------------------------------------------------------
37
+ // Setup Scales
38
+
39
+ x .domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) ))
40
+
41
+ if (padData)
42
+ x.range([availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]);
43
+ else
44
+ x.range([0, availableWidth]);
45
+
46
+ y .domain(yDomain || d3.extent(data[0].values.map(getY).concat(forceY) ))
47
+ .range([availableHeight, 0]);
48
+
49
+ // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point
50
+ if (x.domain()[0] === x.domain()[1] || y.domain()[0] === y.domain()[1]) singlePoint = true;
51
+ if (x.domain()[0] === x.domain()[1])
52
+ x.domain()[0] ?
53
+ x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01])
54
+ : x.domain([-1,1]);
55
+
56
+ if (y.domain()[0] === y.domain()[1])
57
+ y.domain()[0] ?
58
+ y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01])
59
+ : y.domain([-1,1]);
60
+
61
+ //------------------------------------------------------------
62
+
63
+
64
+ //------------------------------------------------------------
65
+ // Setup containers and skeleton of chart
66
+
67
+ var wrap = container.selectAll('g.nv-wrap.nv-bar').data([data[0].values]);
68
+ var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-bar');
69
+ var defsEnter = wrapEnter.append('defs');
70
+ var gEnter = wrapEnter.append('g');
71
+ var g = wrap.select('g');
72
+
73
+ gEnter.append('g').attr('class', 'nv-bars');
74
+
75
+ wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
76
+
77
+ //------------------------------------------------------------
78
+
79
+
80
+ container
81
+ .on('click', function(d,i) {
82
+ dispatch.chartClick({
83
+ data: d,
84
+ index: i,
85
+ pos: d3.event,
86
+ id: id
87
+ });
88
+ });
89
+
90
+
91
+ defsEnter.append('clipPath')
92
+ .attr('id', 'nv-chart-clip-path-' + id)
93
+ .append('rect');
94
+
95
+ wrap.select('#nv-chart-clip-path-' + id + ' rect')
96
+ .attr('width', availableWidth)
97
+ .attr('height', availableHeight);
98
+
99
+ g .attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : '');
100
+
101
+
102
+
103
+ var bars = wrap.select('.nv-bars').selectAll('.nv-bar')
104
+ .data(function(d) { return d });
105
+
106
+ bars.exit().remove();
107
+
108
+
109
+ var barsEnter = bars.enter().append('rect')
110
+ //.attr('class', function(d,i,j) { return (getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive') + ' nv-bar-' + j + '-' + i })
111
+ .attr('x', 0 )
112
+ .attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) })
113
+ .attr('height', function(d,i) { return Math.abs(y(getY(d,i)) - y(0)) })
114
+ .on('mouseover', function(d,i) {
115
+ d3.select(this).classed('hover', true);
116
+ dispatch.elementMouseover({
117
+ point: d,
118
+ series: data[0],
119
+ pos: [x(getX(d,i)), y(getY(d,i))], // TODO: Figure out why the value appears to be shifted
120
+ pointIndex: i,
121
+ seriesIndex: 0,
122
+ e: d3.event
123
+ });
124
+
125
+ })
126
+ .on('mouseout', function(d,i) {
127
+ d3.select(this).classed('hover', false);
128
+ dispatch.elementMouseout({
129
+ point: d,
130
+ series: data[0],
131
+ pointIndex: i,
132
+ seriesIndex: 0,
133
+ e: d3.event
134
+ });
135
+ })
136
+ .on('click', function(d,i) {
137
+ dispatch.elementClick({
138
+ //label: d[label],
139
+ value: getY(d,i),
140
+ data: d,
141
+ index: i,
142
+ pos: [x(getX(d,i)), y(getY(d,i))],
143
+ e: d3.event,
144
+ id: id
145
+ });
146
+ d3.event.stopPropagation();
147
+ })
148
+ .on('dblclick', function(d,i) {
149
+ dispatch.elementDblClick({
150
+ //label: d[label],
151
+ value: getY(d,i),
152
+ data: d,
153
+ index: i,
154
+ pos: [x(getX(d,i)), y(getY(d,i))],
155
+ e: d3.event,
156
+ id: id
157
+ });
158
+ d3.event.stopPropagation();
159
+ });
160
+
161
+ bars
162
+ .attr('fill', function(d,i) { return color(d, i); })
163
+ .attr('class', function(d,i,j) { return (getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive') + ' nv-bar-' + j + '-' + i })
164
+ .attr('transform', function(d,i) { return 'translate(' + (x(getX(d,i)) - availableWidth / data[0].values.length * .45) + ',0)'; }) //TODO: better width calculations that don't assume always uniform data spacing;w
165
+ .attr('width', (availableWidth / data[0].values.length) * .9 )
166
+
167
+
168
+ d3.transition(bars)
169
+ //.attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) })
170
+ .attr('y', function(d,i) {
171
+ return getY(d,i) < 0 ?
172
+ y(0) :
173
+ y(0) - y(getY(d,i)) < 1 ?
174
+ y(0) - 1 :
175
+ y(getY(d,i))
176
+ })
177
+ .attr('height', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) });
178
+ //.order(); // not sure if this makes any sense for this model
179
+
180
+ });
181
+
182
+ return chart;
183
+ }
184
+
185
+
186
+ //============================================================
187
+ // Expose Public Variables
188
+ //------------------------------------------------------------
189
+
190
+ chart.dispatch = dispatch;
191
+
192
+ chart.x = function(_) {
193
+ if (!arguments.length) return getX;
194
+ getX = _;
195
+ return chart;
196
+ };
197
+
198
+ chart.y = function(_) {
199
+ if (!arguments.length) return getY;
200
+ getY = _;
201
+ return chart;
202
+ };
203
+
204
+ chart.margin = function(_) {
205
+ if (!arguments.length) return margin;
206
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
207
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
208
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
209
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
210
+ return chart;
211
+ };
212
+
213
+ chart.width = function(_) {
214
+ if (!arguments.length) return width;
215
+ width = _;
216
+ return chart;
217
+ };
218
+
219
+ chart.height = function(_) {
220
+ if (!arguments.length) return height;
221
+ height = _;
222
+ return chart;
223
+ };
224
+
225
+ chart.xScale = function(_) {
226
+ if (!arguments.length) return x;
227
+ x = _;
228
+ return chart;
229
+ };
230
+
231
+ chart.yScale = function(_) {
232
+ if (!arguments.length) return y;
233
+ y = _;
234
+ return chart;
235
+ };
236
+
237
+ chart.xDomain = function(_) {
238
+ if (!arguments.length) return xDomain;
239
+ xDomain = _;
240
+ return chart;
241
+ };
242
+
243
+ chart.yDomain = function(_) {
244
+ if (!arguments.length) return yDomain;
245
+ yDomain = _;
246
+ return chart;
247
+ };
248
+
249
+ chart.forceX = function(_) {
250
+ if (!arguments.length) return forceX;
251
+ forceX = _;
252
+ return chart;
253
+ };
254
+
255
+ chart.forceY = function(_) {
256
+ if (!arguments.length) return forceY;
257
+ forceY = _;
258
+ return chart;
259
+ };
260
+
261
+ chart.padData = function(_) {
262
+ if (!arguments.length) return padData;
263
+ padData = _;
264
+ return chart;
265
+ };
266
+
267
+ chart.clipEdge = function(_) {
268
+ if (!arguments.length) return clipEdge;
269
+ clipEdge = _;
270
+ return chart;
271
+ };
272
+
273
+ chart.color = function(_) {
274
+ if (!arguments.length) return color;
275
+ color = nv.utils.getColor(_);
276
+ return chart;
277
+ };
278
+
279
+ chart.id = function(_) {
280
+ if (!arguments.length) return id;
281
+ id = _;
282
+ return chart;
283
+ };
284
+
285
+ //============================================================
286
+
287
+
288
+ return chart;
289
+ }
@@ -0,0 +1,306 @@
1
+
2
+ nv.models.indentedTree = function() {
3
+
4
+ //============================================================
5
+ // Public Variables with Default Settings
6
+ //------------------------------------------------------------
7
+
8
+ var margin = {top: 0, right: 0, bottom: 0, left: 0} //TODO: implement, maybe as margin on the containing div
9
+ , width = 960
10
+ , height = 500
11
+ , color = nv.utils.defaultColor()
12
+ , id = Math.floor(Math.random() * 10000)
13
+ , header = true
14
+ , noData = "No Data Available."
15
+ , childIndent = 20
16
+ , columns = [{key:'key', label: 'Name', type:'text'}] //TODO: consider functions like chart.addColumn, chart.removeColumn, instead of a block like this
17
+ , tableClass = null
18
+ , iconOpen = 'images/grey-plus.png' //TODO: consider removing this and replacing with a '+' or '-' unless user defines images
19
+ , iconClose = 'images/grey-minus.png'
20
+ , dispatch = d3.dispatch('elementClick', 'elementDblclick', 'elementMouseover', 'elementMouseout')
21
+ ;
22
+
23
+ //============================================================
24
+
25
+
26
+ function chart(selection) {
27
+ selection.each(function(data) {
28
+ var i = 0,
29
+ depth = 1;
30
+
31
+ var tree = d3.layout.tree()
32
+ .children(function(d) { return d.values })
33
+ .size([height, childIndent]); //Not sure if this is needed now that the result is HTML
34
+
35
+ chart.update = function() { selection.transition().call(chart) };
36
+ chart.container = this;
37
+
38
+
39
+ //------------------------------------------------------------
40
+ // Display No Data message if there's nothing to show.
41
+ if (!data[0]) data[0] = {key: noData};
42
+
43
+ //------------------------------------------------------------
44
+
45
+
46
+ var nodes = tree.nodes(data[0]);
47
+
48
+
49
+ //------------------------------------------------------------
50
+ // Setup containers and skeleton of chart
51
+
52
+ var wrap = d3.select(this).selectAll('div').data([[nodes]]);
53
+ var wrapEnter = wrap.enter().append('div').attr('class', 'nvd3 nv-wrap nv-indentedtree');
54
+ var tableEnter = wrapEnter.append('table');
55
+ var table = wrap.select('table').attr('width', '100%').attr('class', tableClass);
56
+
57
+ //------------------------------------------------------------
58
+
59
+
60
+ if (header) {
61
+ var thead = tableEnter.append('thead');
62
+
63
+ var theadRow1 = thead.append('tr');
64
+
65
+ columns.forEach(function(column) {
66
+ theadRow1
67
+ .append('th')
68
+ .attr('width', column.width ? column.width : '10%')
69
+ .style('text-align', column.type == 'numeric' ? 'right' : 'left')
70
+ .append('span')
71
+ .text(column.label);
72
+ });
73
+ }
74
+
75
+
76
+ var tbody = table.selectAll('tbody')
77
+ .data(function(d) {return d });
78
+ tbody.enter().append('tbody');
79
+
80
+
81
+
82
+ //compute max generations
83
+ depth = d3.max(nodes, function(node) { return node.depth });
84
+ tree.size([height, depth * childIndent]); //TODO: see if this is necessary at all
85
+
86
+
87
+ // Update the nodes…
88
+ var node = tbody.selectAll('tr')
89
+ .data(function(d) { return d }, function(d) { return d.id || (d.id == ++i)});
90
+ //.style('display', 'table-row'); //TODO: see if this does anything
91
+
92
+ node.exit().remove();
93
+
94
+
95
+ node.select('img.nv-treeicon')
96
+ .attr('src', icon)
97
+ .classed('folded', folded);
98
+
99
+ var nodeEnter = node.enter().append('tr');
100
+
101
+
102
+ columns.forEach(function(column, index) {
103
+
104
+ var nodeName = nodeEnter.append('td')
105
+ .style('padding-left', function(d) { return (index ? 0 : d.depth * childIndent + 12 + (icon(d) ? 0 : 16)) + 'px' }, 'important') //TODO: check why I did the ternary here
106
+ .style('text-align', column.type == 'numeric' ? 'right' : 'left');
107
+
108
+
109
+ if (index == 0) {
110
+ nodeName.append('img')
111
+ .classed('nv-treeicon', true)
112
+ .classed('nv-folded', folded)
113
+ .attr('src', icon)
114
+ .style('width', '14px')
115
+ .style('height', '14px')
116
+ .style('padding', '0 1px')
117
+ .style('display', function(d) { return icon(d) ? 'inline-block' : 'none'; })
118
+ .on('click', click);
119
+ }
120
+
121
+
122
+ nodeName.append('span')
123
+ .attr('class', d3.functor(column.classes) )
124
+ .text(function(d) { return column.format ? column.format(d) :
125
+ (d[column.key] || '-') });
126
+
127
+ if (column.showCount)
128
+ nodeName.append('span')
129
+ .attr('class', 'nv-childrenCount')
130
+ .text(function(d) {
131
+ return ((d.values && d.values.length) || (d._values && d._values.length)) ?
132
+ '(' + ((d.values && d.values.length) || (d._values && d._values.length)) + ')'
133
+ : ''
134
+ });
135
+
136
+
137
+ if (column.click)
138
+ nodeName.select('span').on('click', column.click);
139
+
140
+ });
141
+
142
+
143
+ node
144
+ .order()
145
+ .on('click', function(d) {
146
+ dispatch.elementClick({
147
+ row: this, //TODO: decide whether or not this should be consistent with scatter/line events or should be an html link (a href)
148
+ data: d,
149
+ pos: [d.x, d.y]
150
+ });
151
+ })
152
+ .on('dblclick', function(d) {
153
+ dispatch.elementDblclick({
154
+ row: this,
155
+ data: d,
156
+ pos: [d.x, d.y]
157
+ });
158
+ })
159
+ .on('mouseover', function(d) {
160
+ dispatch.elementMouseover({
161
+ row: this,
162
+ data: d,
163
+ pos: [d.x, d.y]
164
+ });
165
+ })
166
+ .on('mouseout', function(d) {
167
+ dispatch.elementMouseout({
168
+ row: this,
169
+ data: d,
170
+ pos: [d.x, d.y]
171
+ });
172
+ });
173
+
174
+
175
+
176
+
177
+ // Toggle children on click.
178
+ function click(d, _, unshift) {
179
+ d3.event.stopPropagation();
180
+
181
+ if(d3.event.shiftKey && !unshift) {
182
+ //If you shift-click, it'll toggle fold all the children, instead of itself
183
+ d3.event.shiftKey = false;
184
+ d.values && d.values.forEach(function(node){
185
+ if (node.values || node._values) {
186
+ click(node, 0, true);
187
+ }
188
+ });
189
+ return true;
190
+ }
191
+ if(!hasChildren(d)) {
192
+ //download file
193
+ //window.location.href = d.url;
194
+ return true;
195
+ }
196
+ if (d.values) {
197
+ d._values = d.values;
198
+ d.values = null;
199
+ } else {
200
+ d.values = d._values;
201
+ d._values = null;
202
+ }
203
+ chart.update();
204
+ }
205
+
206
+
207
+ function icon(d) {
208
+ return (d._values && d._values.length) ? iconOpen : (d.values && d.values.length) ? iconClose : '';
209
+ }
210
+
211
+ function folded(d) {
212
+ return (d._values && d._values.length);
213
+ }
214
+
215
+ function hasChildren(d) {
216
+ var values = d.values || d._values;
217
+
218
+ return (values && values.length);
219
+ }
220
+
221
+
222
+ });
223
+
224
+ return chart;
225
+ }
226
+
227
+
228
+ //============================================================
229
+ // Expose Public Variables
230
+ //------------------------------------------------------------
231
+
232
+ chart.margin = function(_) {
233
+ if (!arguments.length) return margin;
234
+ margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
235
+ margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
236
+ margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
237
+ margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
238
+ return chart;
239
+ };
240
+
241
+ chart.width = function(_) {
242
+ if (!arguments.length) return width;
243
+ width = _;
244
+ return chart;
245
+ };
246
+
247
+ chart.height = function(_) {
248
+ if (!arguments.length) return height;
249
+ height = _;
250
+ return chart;
251
+ };
252
+
253
+ chart.color = function(_) {
254
+ if (!arguments.length) return color;
255
+ color = nv.utils.getColor(_);
256
+ scatter.color(color);
257
+ return chart;
258
+ };
259
+
260
+ chart.id = function(_) {
261
+ if (!arguments.length) return id;
262
+ id = _;
263
+ return chart;
264
+ };
265
+
266
+ chart.header = function(_) {
267
+ if (!arguments.length) return header;
268
+ header = _;
269
+ return chart;
270
+ };
271
+
272
+ chart.noData = function(_) {
273
+ if (!arguments.length) return noData;
274
+ noData = _;
275
+ return chart;
276
+ };
277
+
278
+ chart.columns = function(_) {
279
+ if (!arguments.length) return columns;
280
+ columns = _;
281
+ return chart;
282
+ };
283
+
284
+ chart.tableClass = function(_) {
285
+ if (!arguments.length) return tableClass;
286
+ tableClass = _;
287
+ return chart;
288
+ };
289
+
290
+ chart.iconOpen = function(_){
291
+ if (!arguments.length) return iconOpen;
292
+ iconOpen = _;
293
+ return chart;
294
+ }
295
+
296
+ chart.iconClose = function(_){
297
+ if (!arguments.length) return iconClose;
298
+ iconClose = _;
299
+ return chart;
300
+ }
301
+
302
+ //============================================================
303
+
304
+
305
+ return chart;
306
+ }