nvd3-rails 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/README.md +7 -71
- data/lib/nvd3/rails/version.rb +1 -1
- data/nvd3-rails.gemspec +3 -3
- metadata +8 -111
- data/vendor/assets/javascripts/nvd3/.git.sample/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/config +0 -13
- data/vendor/assets/javascripts/nvd3/.git.sample/description +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/applypatch-msg.sample +0 -15
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/commit-msg.sample +0 -24
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/post-update.sample +0 -8
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-applypatch.sample +0 -14
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-commit.sample +0 -50
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-push.sample +0 -53
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/pre-rebase.sample +0 -169
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/prepare-commit-msg.sample +0 -36
- data/vendor/assets/javascripts/nvd3/.git.sample/hooks/update.sample +0 -128
- data/vendor/assets/javascripts/nvd3/.git.sample/index +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/info/exclude +0 -6
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/heads/master +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/logs/refs/remotes/origin/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.idx +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/objects/pack/pack-babbb312d58dd7f03870b530a1b9a84c80918be3.pack +0 -0
- data/vendor/assets/javascripts/nvd3/.git.sample/packed-refs +0 -5
- data/vendor/assets/javascripts/nvd3/.git.sample/refs/heads/master +0 -1
- data/vendor/assets/javascripts/nvd3/.git.sample/refs/remotes/origin/HEAD +0 -1
- data/vendor/assets/javascripts/nvd3/build.bat +0 -6
- data/vendor/assets/javascripts/nvd3/deprecated/bar.html +0 -198
- data/vendor/assets/javascripts/nvd3/deprecated/bar.js +0 -250
- data/vendor/assets/javascripts/nvd3/deprecated/charts/cumulativeLineChart.js +0 -174
- data/vendor/assets/javascripts/nvd3/deprecated/charts/discreteBarChart.js +0 -157
- data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChart.js +0 -159
- data/vendor/assets/javascripts/nvd3/deprecated/charts/lineChartDaily.js +0 -168
- data/vendor/assets/javascripts/nvd3/deprecated/charts/stackedAreaChart.js +0 -177
- data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.html +0 -171
- data/vendor/assets/javascripts/nvd3/deprecated/cumulativeLine.js +0 -334
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.html +0 -129
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarChartWithEnabledTooltip.js +0 -222
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.html +0 -172
- data/vendor/assets/javascripts/nvd3/deprecated/discreteBarWithAxes.js +0 -152
- data/vendor/assets/javascripts/nvd3/deprecated/lineChart-old.html +0 -83
- data/vendor/assets/javascripts/nvd3/deprecated/lineChartDaily.html +0 -109
- data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.html +0 -173
- data/vendor/assets/javascripts/nvd3/deprecated/linePlusBar.js +0 -250
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.html +0 -137
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFocus.js +0 -354
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.html +0 -144
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithFourAxes.js +0 -218
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.html +0 -142
- data/vendor/assets/javascripts/nvd3/deprecated/lineWithLegend.js +0 -176
- data/vendor/assets/javascripts/nvd3/deprecated/monthendAxis.html +0 -99
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.html +0 -258
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarHorizontalWithLegend.js +0 -226
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.html +0 -162
- data/vendor/assets/javascripts/nvd3/deprecated/multiBarWithLegend.js +0 -249
- data/vendor/assets/javascripts/nvd3/deprecated/pie.js +0 -263
- data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.html +0 -110
- data/vendor/assets/javascripts/nvd3/deprecated/scatterChart.js +0 -294
- data/vendor/assets/javascripts/nvd3/deprecated/scatterFisheyeChart.js +0 -418
- data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.html +0 -167
- data/vendor/assets/javascripts/nvd3/deprecated/scatterWithLegend.js +0 -261
- data/vendor/assets/javascripts/nvd3/deprecated/stackedArea.js +0 -286
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart.html +0 -183
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaChart_old.html +0 -137
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.html +0 -222
- data/vendor/assets/javascripts/nvd3/deprecated/stackedAreaWithLegend.js +0 -297
- data/vendor/assets/javascripts/nvd3/examples/bullet.html +0 -96
- data/vendor/assets/javascripts/nvd3/examples/bulletChart.html +0 -94
- data/vendor/assets/javascripts/nvd3/examples/crossfilter.html +0 -167
- data/vendor/assets/javascripts/nvd3/examples/crossfilterWithDimentions.html +0 -180
- data/vendor/assets/javascripts/nvd3/examples/crossfilterWithTables.html +0 -288
- data/vendor/assets/javascripts/nvd3/examples/cumulativeLineChart.html +0 -155
- data/vendor/assets/javascripts/nvd3/examples/discreteBarChart.html +0 -116
- data/vendor/assets/javascripts/nvd3/examples/dynamicTimeSeries.html +0 -148
- data/vendor/assets/javascripts/nvd3/examples/historicalBar.html +0 -157
- data/vendor/assets/javascripts/nvd3/examples/horizon.html +0 -163
- data/vendor/assets/javascripts/nvd3/examples/images/grey-minus.png +0 -0
- data/vendor/assets/javascripts/nvd3/examples/images/grey-plus.png +0 -0
- data/vendor/assets/javascripts/nvd3/examples/indentedtree.html +0 -126
- data/vendor/assets/javascripts/nvd3/examples/legend.html +0 -75
- data/vendor/assets/javascripts/nvd3/examples/line.html +0 -95
- data/vendor/assets/javascripts/nvd3/examples/lineChart.html +0 -112
- data/vendor/assets/javascripts/nvd3/examples/lineChartSVGResize.html +0 -151
- data/vendor/assets/javascripts/nvd3/examples/linePlusBarChart.html +0 -114
- data/vendor/assets/javascripts/nvd3/examples/linePlusBarWithFocusChart.html +0 -128
- data/vendor/assets/javascripts/nvd3/examples/lineTimeSeries.html +0 -142
- data/vendor/assets/javascripts/nvd3/examples/lineWithFisheyeChart.html +0 -101
- data/vendor/assets/javascripts/nvd3/examples/lineWithFocusChart.html +0 -87
- data/vendor/assets/javascripts/nvd3/examples/multiBar.html +0 -92
- data/vendor/assets/javascripts/nvd3/examples/multiBarChart.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/multiBarHorizontalChart.html +0 -388
- data/vendor/assets/javascripts/nvd3/examples/multiChart.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/nations.json +0 -1
- data/vendor/assets/javascripts/nvd3/examples/pie.html +0 -93
- data/vendor/assets/javascripts/nvd3/examples/pieChart.html +0 -114
- data/vendor/assets/javascripts/nvd3/examples/scatter.html +0 -95
- data/vendor/assets/javascripts/nvd3/examples/scatterChart.html +0 -115
- data/vendor/assets/javascripts/nvd3/examples/scatterPlusLineChart.html +0 -116
- data/vendor/assets/javascripts/nvd3/examples/sparkline.html +0 -62
- data/vendor/assets/javascripts/nvd3/examples/sparklinePlus.html +0 -67
- data/vendor/assets/javascripts/nvd3/examples/stackedArea.html +0 -155
- data/vendor/assets/javascripts/nvd3/examples/stackedAreaChart.html +0 -245
- data/vendor/assets/javascripts/nvd3/examples/stream_layers.js +0 -35
- data/vendor/assets/javascripts/nvd3/src/models/backup/bullet.js +0 -250
- data/vendor/assets/javascripts/nvd3/src/models/backup/bulletChart.js +0 -349
@@ -1,226 +0,0 @@
|
|
1
|
-
|
2
|
-
nv.models.multiBarHorizontalWithLegend = function() {
|
3
|
-
var margin = {top: 30, right: 20, bottom: 50, left: 60},
|
4
|
-
width = function() { return 960 },
|
5
|
-
height = function() { return 500 },
|
6
|
-
color = d3.scale.category20().range(),
|
7
|
-
showControls = true;
|
8
|
-
|
9
|
-
//var x = d3.scale.linear(),
|
10
|
-
var x = d3.scale.ordinal(),
|
11
|
-
y = d3.scale.linear(),
|
12
|
-
xAxis = nv.models.axis().scale(x).orient('left').highlightZero(false),
|
13
|
-
yAxis = nv.models.axis().scale(y).orient('bottom'),
|
14
|
-
legend = nv.models.legend().height(30),
|
15
|
-
controls = nv.models.legend().height(30),
|
16
|
-
multibar = nv.models.multiBarHorizontal().stacked(false),
|
17
|
-
dispatch = d3.dispatch('tooltipShow', 'tooltipHide');
|
18
|
-
|
19
|
-
//TODO: let user select default
|
20
|
-
var controlsData = [
|
21
|
-
{ key: 'Grouped' },
|
22
|
-
{ key: 'Stacked', disabled: true },
|
23
|
-
];
|
24
|
-
|
25
|
-
function chart(selection) {
|
26
|
-
selection.each(function(data) {
|
27
|
-
var availableWidth = width() - margin.left - margin.right,
|
28
|
-
availableHeight = height() - margin.top - margin.bottom,
|
29
|
-
seriesData;
|
30
|
-
|
31
|
-
if (multibar.stacked()) {
|
32
|
-
seriesData = data.filter(function(d) { return !d.disabled })
|
33
|
-
.reduce(function(prev, curr, index) { //sum up all the y's
|
34
|
-
curr.values.forEach(function(d,i) {
|
35
|
-
if (!index) prev[i] = {x: multibar.x()(d,i), y:0};
|
36
|
-
prev[i].y += multibar.y()(d,i);
|
37
|
-
});
|
38
|
-
return prev;
|
39
|
-
}, []);
|
40
|
-
} else {
|
41
|
-
seriesData = data.filter(function(d) { return !d.disabled })
|
42
|
-
.map(function(d) {
|
43
|
-
return d.values.map(function(d,i) {
|
44
|
-
return { x: multibar.x()(d,i), y: multibar.y()(d,i) }
|
45
|
-
})
|
46
|
-
});
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
x .domain(d3.merge(seriesData).map(function(d) { return d.x }))
|
51
|
-
.rangeBands([0, availableHeight], .1);
|
52
|
-
|
53
|
-
y .domain(d3.extent(d3.merge(seriesData).map(function(d) { return d.y }).concat(multibar.forceY) ))
|
54
|
-
.range([0, availableWidth]);
|
55
|
-
|
56
|
-
multibar
|
57
|
-
.width(availableWidth)
|
58
|
-
.height(availableHeight)
|
59
|
-
.color(data.map(function(d,i) {
|
60
|
-
return d.color || color[i % 10];
|
61
|
-
}).filter(function(d,i) { return !data[i].disabled }))
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
var wrap = d3.select(this).selectAll('g.wrap').data([data]);
|
66
|
-
var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 multiBarHorizontalWithLegend').append('g');
|
67
|
-
|
68
|
-
gEnter.append('g').attr('class', 'x axis');
|
69
|
-
gEnter.append('g').attr('class', 'y axis');
|
70
|
-
gEnter.append('g').attr('class', 'linesWrap');
|
71
|
-
gEnter.append('g').attr('class', 'legendWrap');
|
72
|
-
gEnter.append('g').attr('class', 'controlsWrap');
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
//TODO: margins should be adjusted based on what components are used: axes, axis labels, legend
|
77
|
-
margin.top = legend.height();
|
78
|
-
|
79
|
-
var g = wrap.select('g')
|
80
|
-
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
81
|
-
|
82
|
-
|
83
|
-
legend.width(availableWidth / 2);
|
84
|
-
|
85
|
-
g.select('.legendWrap')
|
86
|
-
.datum(data)
|
87
|
-
.attr('transform', 'translate(' + (availableWidth / 2) + ',' + (-margin.top) +')')
|
88
|
-
.call(legend);
|
89
|
-
|
90
|
-
if (showControls) {
|
91
|
-
controls.width(180).color(['#444', '#444', '#444']);
|
92
|
-
g.select('.controlsWrap')
|
93
|
-
.datum(controlsData)
|
94
|
-
.attr('transform', 'translate(0,' + (-margin.top) +')')
|
95
|
-
.call(controls);
|
96
|
-
}
|
97
|
-
|
98
|
-
|
99
|
-
var linesWrap = g.select('.linesWrap')
|
100
|
-
.datum(data.filter(function(d) { return !d.disabled }))
|
101
|
-
|
102
|
-
|
103
|
-
d3.transition(linesWrap).call(multibar);
|
104
|
-
|
105
|
-
|
106
|
-
xAxis
|
107
|
-
.scale(x)
|
108
|
-
.ticks( availableHeight / 24 )
|
109
|
-
.tickSize(-availableWidth, 0);
|
110
|
-
|
111
|
-
//g.select('.x.axis')
|
112
|
-
//.attr('transform', 'translate(0,' + y.range()[0] + ')');
|
113
|
-
d3.transition(g.select('.x.axis'))
|
114
|
-
.call(xAxis);
|
115
|
-
|
116
|
-
var xTicks = g.select('.x.axis').selectAll('g');
|
117
|
-
|
118
|
-
xTicks
|
119
|
-
.selectAll('line, text')
|
120
|
-
.style('opacity', 1)
|
121
|
-
|
122
|
-
xTicks.filter(function(d,i) {
|
123
|
-
return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
|
124
|
-
})
|
125
|
-
.selectAll('line, text')
|
126
|
-
.style('opacity', 0)
|
127
|
-
|
128
|
-
yAxis
|
129
|
-
.domain(y.domain())
|
130
|
-
.range(y.range())
|
131
|
-
.ticks( availableWidth / 100 )
|
132
|
-
.tickSize( -availableHeight, 0);
|
133
|
-
|
134
|
-
g.select('.y.axis')
|
135
|
-
.attr('transform', 'translate(0,' + availableHeight + ')');
|
136
|
-
d3.transition(g.select('.y.axis'))
|
137
|
-
.call(yAxis);
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
legend.dispatch.on('legendClick', function(d,i) {
|
143
|
-
d.disabled = !d.disabled;
|
144
|
-
|
145
|
-
if (!data.filter(function(d) { return !d.disabled }).length) {
|
146
|
-
data.map(function(d) {
|
147
|
-
d.disabled = false;
|
148
|
-
wrap.selectAll('.series').classed('disabled', false);
|
149
|
-
return d;
|
150
|
-
});
|
151
|
-
}
|
152
|
-
|
153
|
-
selection.transition().call(chart);
|
154
|
-
});
|
155
|
-
|
156
|
-
controls.dispatch.on('legendClick', function(d,i) {
|
157
|
-
if (!d.disabled) return;
|
158
|
-
controlsData = controlsData.map(function(s) {
|
159
|
-
s.disabled = true;
|
160
|
-
return s;
|
161
|
-
});
|
162
|
-
d.disabled = false;
|
163
|
-
|
164
|
-
switch (d.key) {
|
165
|
-
case 'Grouped':
|
166
|
-
multibar.stacked(false);
|
167
|
-
break;
|
168
|
-
case 'Stacked':
|
169
|
-
multibar.stacked(true);
|
170
|
-
break;
|
171
|
-
}
|
172
|
-
|
173
|
-
selection.transition().call(chart);
|
174
|
-
});
|
175
|
-
|
176
|
-
|
177
|
-
multibar.dispatch.on('elementMouseover.tooltip', function(e) {
|
178
|
-
e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
|
179
|
-
dispatch.tooltipShow(e);
|
180
|
-
});
|
181
|
-
|
182
|
-
multibar.dispatch.on('elementMouseout.tooltip', function(e) {
|
183
|
-
dispatch.tooltipHide(e);
|
184
|
-
});
|
185
|
-
|
186
|
-
});
|
187
|
-
|
188
|
-
return chart;
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
chart.dispatch = dispatch;
|
193
|
-
chart.legend = legend;
|
194
|
-
chart.xAxis = xAxis;
|
195
|
-
chart.yAxis = yAxis;
|
196
|
-
|
197
|
-
d3.rebind(chart, multibar, 'x', 'y', 'xDomain', 'yDomain', 'forceX', 'forceY', 'clipEdge', 'id');
|
198
|
-
|
199
|
-
|
200
|
-
chart.margin = function(_) {
|
201
|
-
if (!arguments.length) return margin;
|
202
|
-
margin = _;
|
203
|
-
return chart;
|
204
|
-
};
|
205
|
-
|
206
|
-
chart.width = function(_) {
|
207
|
-
if (!arguments.length) return width;
|
208
|
-
width = d3.functor(_);
|
209
|
-
return chart;
|
210
|
-
};
|
211
|
-
|
212
|
-
chart.height = function(_) {
|
213
|
-
if (!arguments.length) return height;
|
214
|
-
height = d3.functor(_);
|
215
|
-
return chart;
|
216
|
-
};
|
217
|
-
|
218
|
-
chart.showControls = function(_) {
|
219
|
-
if (!arguments.length) return showControls;
|
220
|
-
showControls = _;
|
221
|
-
return chart;
|
222
|
-
};
|
223
|
-
|
224
|
-
|
225
|
-
return chart;
|
226
|
-
}
|
@@ -1,162 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<meta charset="utf-8">
|
3
|
-
|
4
|
-
<link href="../src/d3.css" rel="stylesheet" type="text/css">
|
5
|
-
|
6
|
-
<style>
|
7
|
-
|
8
|
-
body {
|
9
|
-
overflow-y:scroll;
|
10
|
-
}
|
11
|
-
|
12
|
-
text {
|
13
|
-
font: 12px sans-serif;
|
14
|
-
}
|
15
|
-
|
16
|
-
#chart1 {
|
17
|
-
height: 500px;
|
18
|
-
margin: 10px;
|
19
|
-
min-width: 100px;
|
20
|
-
min-height: 100px;
|
21
|
-
/*
|
22
|
-
Minimum height and width is a good idea to prevent negative SVG dimensions...
|
23
|
-
For example width should be =< margin.left + margin.right + 1,
|
24
|
-
of course 1 pixel for the entire chart would not be very useful, BUT should not have errors
|
25
|
-
*/
|
26
|
-
}
|
27
|
-
|
28
|
-
</style>
|
29
|
-
<body>
|
30
|
-
|
31
|
-
<div id="chart1">
|
32
|
-
</div>
|
33
|
-
|
34
|
-
<script src="../lib/d3.v2.js"></script>
|
35
|
-
<script src="../nv.d3.js"></script>
|
36
|
-
<script src="../src/tooltip.js"></script>
|
37
|
-
<script src="../src/models/legend.js"></script>
|
38
|
-
<script src="../src/models/axis.js"></script>
|
39
|
-
<script src="../src/models/multiBar.js"></script>
|
40
|
-
<script src="../src/models/multiBarWithLegend.js"></script>
|
41
|
-
<script src="stream_layers.js"></script>
|
42
|
-
<script>
|
43
|
-
|
44
|
-
var test_data = stream_layers(3,Math.random()*200,.1).map(function(data, i) {
|
45
|
-
return {
|
46
|
-
key: 'Stream' + i,
|
47
|
-
values: data
|
48
|
-
};
|
49
|
-
});
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
var selector = '#chart1',
|
59
|
-
chart = nv.models.multiBarWithLegend(),
|
60
|
-
//.x(function(d) { return d.label })
|
61
|
-
//.y(function(d) { return d.value })
|
62
|
-
data = test_data,
|
63
|
-
xTickFormat = d3.format(',f'),
|
64
|
-
yTickFormat = d3.format(',.2f'),
|
65
|
-
xAxisLabel = null,
|
66
|
-
yAxisLabel = null,
|
67
|
-
duration = 500;
|
68
|
-
|
69
|
-
nv.addGraph({
|
70
|
-
generate: function() {
|
71
|
-
var container = d3.select(selector),
|
72
|
-
width = function() { return parseInt(container.style('width')) },
|
73
|
-
height = function() { return parseInt(container.style('height')) },
|
74
|
-
svg = container.append('svg');
|
75
|
-
|
76
|
-
chart
|
77
|
-
.width(width)
|
78
|
-
.height(height);
|
79
|
-
|
80
|
-
chart.xAxis
|
81
|
-
.tickFormat(xTickFormat);
|
82
|
-
|
83
|
-
chart.yAxis
|
84
|
-
.tickFormat(yTickFormat)
|
85
|
-
.axisLabel(yAxisLabel);
|
86
|
-
|
87
|
-
svg
|
88
|
-
.attr('width', width())
|
89
|
-
.attr('height', height())
|
90
|
-
.datum(data)
|
91
|
-
.transition().duration(duration).call(chart);
|
92
|
-
|
93
|
-
return chart;
|
94
|
-
},
|
95
|
-
callback: function(chart) {
|
96
|
-
var showTooltip = function(e) {
|
97
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
98
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
99
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
100
|
-
formatY = chart.yAxis.tickFormat(), //Assumes using same format as axis, can customize to show higher precision, etc.
|
101
|
-
formatX = chart.xAxis.tickFormat();
|
102
|
-
|
103
|
-
// uses the chart's getX and getY, you may customize if x position is not the same as the value you want
|
104
|
-
// ex. daily data without weekends, x is the index, while you want the date
|
105
|
-
var content = '<h3>' + e.series.key + '</h3>' +
|
106
|
-
'<p>' +
|
107
|
-
formatY(chart.y()(e.point)) + ' at ' + formatX(chart.x()(e.point)) +
|
108
|
-
'</p>';
|
109
|
-
|
110
|
-
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's');
|
111
|
-
};
|
112
|
-
|
113
|
-
chart.dispatch.on('tooltipShow', showTooltip);
|
114
|
-
chart.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
115
|
-
|
116
|
-
|
117
|
-
window.onresize= function() {
|
118
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
119
|
-
|
120
|
-
d3.select('#chart1 svg')
|
121
|
-
.attr('width', chart.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
122
|
-
.attr('height', chart.height()())
|
123
|
-
.transition().duration(duration)
|
124
|
-
.call(chart);
|
125
|
-
|
126
|
-
/*
|
127
|
-
d3.select('#chart1 svg')
|
128
|
-
.attr('width', chart.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
129
|
-
.attr('height', chart.height()())
|
130
|
-
.call(chart);
|
131
|
-
*/
|
132
|
-
};
|
133
|
-
}
|
134
|
-
});
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
function sinAndCos() {
|
139
|
-
var sin = [],
|
140
|
-
cos = [];
|
141
|
-
|
142
|
-
for (var i = 0; i < 100; i++) {
|
143
|
-
sin.push({x: i, y: Math.sin(i/10)});
|
144
|
-
cos.push({x: i, y: .5 * Math.cos(i/10)});
|
145
|
-
}
|
146
|
-
|
147
|
-
return [
|
148
|
-
{
|
149
|
-
values: sin,
|
150
|
-
key: "Sine Wave",
|
151
|
-
color: "#ff7f0e"
|
152
|
-
},
|
153
|
-
{
|
154
|
-
values: cos,
|
155
|
-
key: "Cosine Wave",
|
156
|
-
color: "#2ca02c"
|
157
|
-
}
|
158
|
-
];
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
</script>
|
@@ -1,249 +0,0 @@
|
|
1
|
-
|
2
|
-
nv.models.multiBarWithLegend = function() {
|
3
|
-
var margin = {top: 30, right: 20, bottom: 50, left: 60},
|
4
|
-
width = function() { return 960 },
|
5
|
-
height = function() { return 500 },
|
6
|
-
color = d3.scale.category20().range(),
|
7
|
-
showControls = true,
|
8
|
-
showLegend = true;
|
9
|
-
|
10
|
-
//var x = d3.scale.linear(),
|
11
|
-
var x = d3.scale.ordinal(),
|
12
|
-
y = d3.scale.linear(),
|
13
|
-
xAxis = nv.models.axis().scale(x).orient('bottom').highlightZero(false),
|
14
|
-
yAxis = nv.models.axis().scale(y).orient('left'),
|
15
|
-
legend = nv.models.legend().height(30),
|
16
|
-
controls = nv.models.legend().height(30),
|
17
|
-
multibar = nv.models.multiBar().stacked(false),
|
18
|
-
dispatch = d3.dispatch('tooltipShow', 'tooltipHide');
|
19
|
-
|
20
|
-
//TODO: let user select default
|
21
|
-
var controlsData = [
|
22
|
-
{ key: 'Grouped' },
|
23
|
-
{ key: 'Stacked', disabled: true }
|
24
|
-
];
|
25
|
-
|
26
|
-
function chart(selection) {
|
27
|
-
selection.each(function(data) {
|
28
|
-
var availableWidth = width() - margin.left - margin.right,
|
29
|
-
availableHeight = height() - margin.top - margin.bottom,
|
30
|
-
seriesData;
|
31
|
-
|
32
|
-
if (multibar.stacked()) {
|
33
|
-
seriesData = data.filter(function(d) { return !d.disabled })
|
34
|
-
.reduce(function(prev, curr, index) { //sum up all the y's
|
35
|
-
curr.values.forEach(function(d,i) {
|
36
|
-
if (!index) prev[i] = {x: multibar.x()(d,i), y:0};
|
37
|
-
prev[i].y += multibar.y()(d,i);
|
38
|
-
});
|
39
|
-
return prev;
|
40
|
-
}, []);
|
41
|
-
} else {
|
42
|
-
seriesData = data.filter(function(d) { return !d.disabled })
|
43
|
-
.map(function(d) {
|
44
|
-
return d.values.map(function(d,i) {
|
45
|
-
return { x: multibar.x()(d,i), y: multibar.y()(d,i) }
|
46
|
-
})
|
47
|
-
});
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
//x .domain(d3.extent(d3.merge(seriesData).map(function(d) { return d.x }).concat(multibar.forceX) ))
|
52
|
-
//.range([0, availableWidth]);
|
53
|
-
|
54
|
-
x .domain(d3.merge(seriesData).map(function(d) { return d.x }))
|
55
|
-
.rangeBands([0, availableWidth], .1);
|
56
|
-
//.rangeRoundBands([0, availableWidth], .1);
|
57
|
-
|
58
|
-
y .domain(d3.extent(d3.merge(seriesData).map(function(d) { return d.y }).concat(multibar.forceY) ))
|
59
|
-
.range([availableHeight, 0]);
|
60
|
-
|
61
|
-
multibar
|
62
|
-
.width(availableWidth)
|
63
|
-
.height(availableHeight)
|
64
|
-
//.xDomain(x.domain())
|
65
|
-
//.yDomain(y.domain())
|
66
|
-
.color(data.map(function(d,i) {
|
67
|
-
return d.color || color[i % 20];
|
68
|
-
}).filter(function(d,i) { return !data[i].disabled }))
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
var wrap = d3.select(this).selectAll('g.wrap.multiBarWithLegend').data([data]);
|
73
|
-
var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 multiBarWithLegend').append('g');
|
74
|
-
|
75
|
-
gEnter.append('g').attr('class', 'x axis');
|
76
|
-
gEnter.append('g').attr('class', 'y axis');
|
77
|
-
gEnter.append('g').attr('class', 'linesWrap');
|
78
|
-
gEnter.append('g').attr('class', 'legendWrap');
|
79
|
-
gEnter.append('g').attr('class', 'controlsWrap');
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
var g = wrap.select('g');
|
84
|
-
|
85
|
-
|
86
|
-
if (showLegend) {
|
87
|
-
//TODO: margins should be adjusted based on what components are used: axes, axis labels, legend
|
88
|
-
margin.top = legend.height();
|
89
|
-
|
90
|
-
legend.width(availableWidth / 2);
|
91
|
-
|
92
|
-
g.select('.legendWrap')
|
93
|
-
.datum(data)
|
94
|
-
.attr('transform', 'translate(' + (availableWidth / 2) + ',' + (-margin.top) +')')
|
95
|
-
.call(legend);
|
96
|
-
}
|
97
|
-
|
98
|
-
if (showControls) {
|
99
|
-
controls.width(180).color(['#444', '#444', '#444']);
|
100
|
-
g.select('.controlsWrap')
|
101
|
-
.datum(controlsData)
|
102
|
-
.attr('transform', 'translate(0,' + (-margin.top) +')')
|
103
|
-
.call(controls);
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
108
|
-
|
109
|
-
var linesWrap = g.select('.linesWrap')
|
110
|
-
.datum(data.filter(function(d) { return !d.disabled }))
|
111
|
-
|
112
|
-
|
113
|
-
d3.transition(linesWrap).call(multibar);
|
114
|
-
|
115
|
-
|
116
|
-
xAxis
|
117
|
-
.scale(x)
|
118
|
-
//.domain(x.domain())
|
119
|
-
//.range(x.range())
|
120
|
-
.ticks( availableWidth / 100 )
|
121
|
-
.tickSize(-availableHeight, 0);
|
122
|
-
|
123
|
-
g.select('.x.axis')
|
124
|
-
.attr('transform', 'translate(0,' + y.range()[0] + ')');
|
125
|
-
d3.transition(g.select('.x.axis'))
|
126
|
-
.call(xAxis);
|
127
|
-
|
128
|
-
var xTicks = g.select('.x.axis').selectAll('g');
|
129
|
-
|
130
|
-
xTicks
|
131
|
-
.selectAll('line, text')
|
132
|
-
.style('opacity', 1)
|
133
|
-
|
134
|
-
xTicks.filter(function(d,i) {
|
135
|
-
return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
|
136
|
-
})
|
137
|
-
.selectAll('line, text')
|
138
|
-
.style('opacity', 0)
|
139
|
-
|
140
|
-
yAxis
|
141
|
-
.domain(y.domain())
|
142
|
-
.range(y.range())
|
143
|
-
.ticks( availableHeight / 36 )
|
144
|
-
.tickSize( -availableWidth, 0);
|
145
|
-
|
146
|
-
d3.transition(g.select('.y.axis'))
|
147
|
-
.call(yAxis);
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
legend.dispatch.on('legendClick', function(d,i) {
|
153
|
-
d.disabled = !d.disabled;
|
154
|
-
|
155
|
-
if (!data.filter(function(d) { return !d.disabled }).length) {
|
156
|
-
data.map(function(d) {
|
157
|
-
d.disabled = false;
|
158
|
-
wrap.selectAll('.series').classed('disabled', false);
|
159
|
-
return d;
|
160
|
-
});
|
161
|
-
}
|
162
|
-
|
163
|
-
selection.transition().call(chart);
|
164
|
-
});
|
165
|
-
|
166
|
-
controls.dispatch.on('legendClick', function(d,i) {
|
167
|
-
if (!d.disabled) return;
|
168
|
-
controlsData = controlsData.map(function(s) {
|
169
|
-
s.disabled = true;
|
170
|
-
return s;
|
171
|
-
});
|
172
|
-
d.disabled = false;
|
173
|
-
|
174
|
-
switch (d.key) {
|
175
|
-
case 'Grouped':
|
176
|
-
multibar.stacked(false);
|
177
|
-
break;
|
178
|
-
case 'Stacked':
|
179
|
-
multibar.stacked(true);
|
180
|
-
break;
|
181
|
-
}
|
182
|
-
|
183
|
-
selection.transition().call(chart);
|
184
|
-
});
|
185
|
-
|
186
|
-
|
187
|
-
multibar.dispatch.on('elementMouseover.tooltip', function(e) {
|
188
|
-
e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
|
189
|
-
dispatch.tooltipShow(e);
|
190
|
-
});
|
191
|
-
|
192
|
-
multibar.dispatch.on('elementMouseout.tooltip', function(e) {
|
193
|
-
dispatch.tooltipHide(e);
|
194
|
-
});
|
195
|
-
|
196
|
-
});
|
197
|
-
|
198
|
-
return chart;
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
chart.dispatch = dispatch;
|
203
|
-
chart.legend = legend;
|
204
|
-
chart.xAxis = xAxis;
|
205
|
-
chart.yAxis = yAxis;
|
206
|
-
|
207
|
-
d3.rebind(chart, multibar, 'x', 'y', 'xDomain', 'yDomain', 'forceX', 'forceY', 'clipEdge', 'id', 'stacked');
|
208
|
-
|
209
|
-
|
210
|
-
chart.margin = function(_) {
|
211
|
-
if (!arguments.length) return margin;
|
212
|
-
margin = _;
|
213
|
-
return chart;
|
214
|
-
};
|
215
|
-
|
216
|
-
chart.width = function(_) {
|
217
|
-
if (!arguments.length) return width;
|
218
|
-
width = d3.functor(_);
|
219
|
-
return chart;
|
220
|
-
};
|
221
|
-
|
222
|
-
chart.height = function(_) {
|
223
|
-
if (!arguments.length) return height;
|
224
|
-
height = d3.functor(_);
|
225
|
-
return chart;
|
226
|
-
};
|
227
|
-
|
228
|
-
chart.color = function(_) {
|
229
|
-
if (!arguments.length) return color;
|
230
|
-
color = _;
|
231
|
-
legend.color(_);
|
232
|
-
return chart;
|
233
|
-
};
|
234
|
-
|
235
|
-
chart.showControls = function(_) {
|
236
|
-
if (!arguments.length) return showControls;
|
237
|
-
showControls = _;
|
238
|
-
return chart;
|
239
|
-
};
|
240
|
-
|
241
|
-
chart.showLegend = function(_) {
|
242
|
-
if (!arguments.length) return showLegend;
|
243
|
-
showLegend = _;
|
244
|
-
return chart;
|
245
|
-
};
|
246
|
-
|
247
|
-
|
248
|
-
return chart;
|
249
|
-
}
|