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,250 +0,0 @@
|
|
1
|
-
|
2
|
-
nv.models.bar = function() {
|
3
|
-
var margin = {top: 20, right: 10, bottom: 80, left: 60},
|
4
|
-
width = 960,
|
5
|
-
height = 500,
|
6
|
-
animate = 500,
|
7
|
-
label ='label',
|
8
|
-
rotatedLabel = true,
|
9
|
-
showLabels = true,
|
10
|
-
id = Math.floor(Math.random() * 10000), //Create semi-unique ID in case user doesn't select one
|
11
|
-
color = d3.scale.category20(),
|
12
|
-
field ='y',
|
13
|
-
title = '';
|
14
|
-
|
15
|
-
var x = d3.scale.ordinal(),
|
16
|
-
y = d3.scale.linear(),
|
17
|
-
xAxis = d3.svg.axis().scale(x).orient('bottom'),
|
18
|
-
yAxis = d3.svg.axis().scale(y).orient('left'),
|
19
|
-
dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'tooltipShow', 'tooltipHide');
|
20
|
-
|
21
|
-
|
22
|
-
function chart(selection) {
|
23
|
-
selection.each(function(data) {
|
24
|
-
x .domain(data.map(function(d,i) { return d[label]; }))
|
25
|
-
.rangeRoundBands([0, width - margin.left - margin.right], .1);
|
26
|
-
|
27
|
-
|
28
|
-
var min = d3.min(data, function(d) { return d[field] });
|
29
|
-
var max = d3.max(data, function(d) { return d[field] });
|
30
|
-
var x0 = Math.max(-min, max);
|
31
|
-
var x1 = -x0;
|
32
|
-
|
33
|
-
// If we have no negative values, then lets stack this with just positive bars
|
34
|
-
if (min >= 0) x1 = 0;
|
35
|
-
|
36
|
-
y .domain([x1, x0])
|
37
|
-
.range([height - margin.top - margin.bottom, 0])
|
38
|
-
.nice();
|
39
|
-
|
40
|
-
xAxis.ticks( width / 100 );
|
41
|
-
yAxis.ticks( height / 36 ).tickSize(-(width - margin.right - margin.left), 0);
|
42
|
-
|
43
|
-
var parent = d3.select(this)
|
44
|
-
.on("click", function(d,i) {
|
45
|
-
dispatch.chartClick({
|
46
|
-
data: d,
|
47
|
-
index: i,
|
48
|
-
pos: d3.event,
|
49
|
-
id: id
|
50
|
-
});
|
51
|
-
});
|
52
|
-
|
53
|
-
|
54
|
-
var wrap = parent.selectAll('g.wrap').data([data]);
|
55
|
-
var gEnter = wrap.enter();
|
56
|
-
gEnter.append("text")
|
57
|
-
.attr("class", "title")
|
58
|
-
.attr("dy", ".91em")
|
59
|
-
.attr("text-anchor", "start")
|
60
|
-
.text(title);
|
61
|
-
gEnter = gEnter.append('g').attr('class', 'nvd3 wrap').attr('id','wrap-'+id).append('g');
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
gEnter.append('g').attr('class', 'x axis');
|
66
|
-
gEnter.append('g').attr('class', 'y axis');
|
67
|
-
gEnter.append('g').attr('class', 'bars');
|
68
|
-
|
69
|
-
|
70
|
-
wrap.attr('width', width)
|
71
|
-
.attr('height', height);
|
72
|
-
|
73
|
-
var g = wrap.select('g')
|
74
|
-
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
75
|
-
|
76
|
-
|
77
|
-
var bars = wrap.select('.bars').selectAll('.bar')
|
78
|
-
.data(function(d) { return d; });
|
79
|
-
|
80
|
-
bars.exit().remove();
|
81
|
-
|
82
|
-
|
83
|
-
var barsEnter = bars.enter().append('svg:rect')
|
84
|
-
.attr('class', function(d) { return d[field] < 0 ? "bar negative" : "bar positive"})
|
85
|
-
.attr("fill", function(d, i) { return color(i); })
|
86
|
-
.attr('x', 0 )
|
87
|
-
.on('mouseover', function(d,i){
|
88
|
-
d3.select(this).classed('hover', true);
|
89
|
-
dispatch.tooltipShow({
|
90
|
-
label: d[label],
|
91
|
-
value: d[field],
|
92
|
-
data: d,
|
93
|
-
index: i,
|
94
|
-
// TODO: Calculate the center to the bar
|
95
|
-
pos: [d3.event.pageX, d3.event.pageY],
|
96
|
-
id: id
|
97
|
-
});
|
98
|
-
|
99
|
-
})
|
100
|
-
.on('mouseout', function(d,i){
|
101
|
-
d3.select(this).classed('hover', false);
|
102
|
-
dispatch.tooltipHide({
|
103
|
-
label: d[label],
|
104
|
-
value: d[field],
|
105
|
-
data: d,
|
106
|
-
index: i,
|
107
|
-
id: id
|
108
|
-
});
|
109
|
-
})
|
110
|
-
.on('click', function(d,i) {
|
111
|
-
dispatch.elementClick({
|
112
|
-
label: d[label],
|
113
|
-
value: d[field],
|
114
|
-
data: d,
|
115
|
-
index: i,
|
116
|
-
pos: d3.event,
|
117
|
-
id: id
|
118
|
-
});
|
119
|
-
d3.event.stopPropagation();
|
120
|
-
})
|
121
|
-
.on('dblclick', function(d,i) {
|
122
|
-
dispatch.elementDblClick({
|
123
|
-
label: d[label],
|
124
|
-
value: d[field],
|
125
|
-
data: d,
|
126
|
-
index: i,
|
127
|
-
pos: d3.event,
|
128
|
-
id: id
|
129
|
-
});
|
130
|
-
d3.event.stopPropagation();
|
131
|
-
});
|
132
|
-
|
133
|
-
|
134
|
-
bars
|
135
|
-
.attr('class', function(d) { return d[field] < 0 ? "bar negative" : "bar positive"})
|
136
|
-
.attr('transform', function(d,i) { return 'translate(' + x(d[label]) + ',0)'; })
|
137
|
-
.attr('width', x.rangeBand )
|
138
|
-
.order()
|
139
|
-
.transition()
|
140
|
-
.duration(animate)
|
141
|
-
.attr('y', function(d) { return y(Math.max(0, d[field])); })
|
142
|
-
.attr('height', function(d) { return Math.abs(y(d[field]) - y(0)); });
|
143
|
-
|
144
|
-
|
145
|
-
g.select('.x.axis')
|
146
|
-
.attr('transform', 'translate(0,' + y.range()[0] + ')')
|
147
|
-
.call(xAxis);
|
148
|
-
|
149
|
-
|
150
|
-
if (rotatedLabel) {
|
151
|
-
g.select('.x.axis').selectAll('text').attr('text-anchor','start').attr("transform", function(d) {
|
152
|
-
return "rotate(35)translate(" + this.getBBox().height/2 + "," + '0' + ")";
|
153
|
-
});
|
154
|
-
}
|
155
|
-
if (!showLabels) {
|
156
|
-
g.select('.x.axis').selectAll('text').attr('fill', 'rgba(0,0,0,0)');
|
157
|
-
g.select('.x.axis').selectAll('line').attr('style', 'opacity: 0');
|
158
|
-
}
|
159
|
-
/*else {
|
160
|
-
g.select('.x.axis').selectAll('text').attr('fill', 'rgba(0,0,0,1)');
|
161
|
-
g.select('.x.axis').selectAll('line').attr('style', 'opacity: 1');
|
162
|
-
}*/
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
g.select('.y.axis')
|
167
|
-
.call(yAxis);
|
168
|
-
});
|
169
|
-
|
170
|
-
return chart;
|
171
|
-
}
|
172
|
-
|
173
|
-
chart.margin = function(_) {
|
174
|
-
if (!arguments.length) return margin;
|
175
|
-
margin = _;
|
176
|
-
return chart;
|
177
|
-
};
|
178
|
-
|
179
|
-
chart.width = function(_) {
|
180
|
-
if (!arguments.length) return width;
|
181
|
-
if (margin.left + margin.right + 20 > _)
|
182
|
-
width = margin.left + margin.right + 20; // Min width
|
183
|
-
else
|
184
|
-
width = _;
|
185
|
-
return chart;
|
186
|
-
};
|
187
|
-
|
188
|
-
chart.height = function(_) {
|
189
|
-
if (!arguments.length) return height;
|
190
|
-
if (margin.top + margin.bottom + 20 > _)
|
191
|
-
height = margin.top + margin.bottom + 20; // Min height
|
192
|
-
else
|
193
|
-
height = _;
|
194
|
-
return chart;
|
195
|
-
};
|
196
|
-
|
197
|
-
chart.animate = function(_) {
|
198
|
-
if (!arguments.length) return animate;
|
199
|
-
animate = _;
|
200
|
-
return chart;
|
201
|
-
};
|
202
|
-
|
203
|
-
chart.labelField = function(_) {
|
204
|
-
if (!arguments.length) return (label);
|
205
|
-
label = _;
|
206
|
-
return chart;
|
207
|
-
};
|
208
|
-
|
209
|
-
chart.dataField = function(_) {
|
210
|
-
if (!arguments.length) return (field);
|
211
|
-
field = _;
|
212
|
-
return chart;
|
213
|
-
};
|
214
|
-
|
215
|
-
chart.id = function(_) {
|
216
|
-
if (!arguments.length) return id;
|
217
|
-
id = _;
|
218
|
-
return chart;
|
219
|
-
};
|
220
|
-
|
221
|
-
chart.rotatedLabel = function(_) {
|
222
|
-
if (!arguments.length) return rotatedLabel;
|
223
|
-
rotatedLabel = _;
|
224
|
-
return chart;
|
225
|
-
};
|
226
|
-
|
227
|
-
chart.showLabels = function(_) {
|
228
|
-
if (!arguments.length) return (showLabels);
|
229
|
-
showLabels = _;
|
230
|
-
return chart;
|
231
|
-
};
|
232
|
-
|
233
|
-
chart.title = function(_) {
|
234
|
-
if (!arguments.length) return (title);
|
235
|
-
title = _;
|
236
|
-
return chart;
|
237
|
-
};
|
238
|
-
|
239
|
-
chart.xaxis = {};
|
240
|
-
// Expose the x-axis' tickFormat method.
|
241
|
-
d3.rebind(chart.xaxis, xAxis, 'tickFormat');
|
242
|
-
|
243
|
-
chart.yaxis = {};
|
244
|
-
// Expose the y-axis' tickFormat method.
|
245
|
-
d3.rebind(chart.yaxis, yAxis, 'tickFormat');
|
246
|
-
|
247
|
-
chart.dispatch = dispatch;
|
248
|
-
|
249
|
-
return chart;
|
250
|
-
}
|
@@ -1,174 +0,0 @@
|
|
1
|
-
|
2
|
-
// This technique works AS IS for month end data points
|
3
|
-
// In fact, this works for any series where each value is evenly spaced,
|
4
|
-
// and every series starts at the same value and is 1 to 1
|
5
|
-
// In other words, values at the same index, need to have the same x value
|
6
|
-
// for all series
|
7
|
-
//
|
8
|
-
// TODO: now that tooltips don't use jquery, could likely get rid of the charts
|
9
|
-
// collection by simply adding some optional functionality to the model
|
10
|
-
nv.charts.cumulativeLineChartDaily = function() {
|
11
|
-
var selector = null,
|
12
|
-
data = [],
|
13
|
-
duration = 500,
|
14
|
-
tooltip = function(key, x, y, e, graph) {
|
15
|
-
return '<h3>' + key + '</h3>' +
|
16
|
-
'<p>' + y + ' at ' + x + '</p>'
|
17
|
-
};
|
18
|
-
|
19
|
-
|
20
|
-
var graph = nv.models.cumulativeLine()
|
21
|
-
.x(function(d,i) { return i })
|
22
|
-
.color(d3.scale.category10().range()),
|
23
|
-
showTooltip = function(e) {
|
24
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
25
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
26
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
27
|
-
formatX = graph.xAxis.tickFormat(),
|
28
|
-
formatY = graph.yAxis.tickFormat(),
|
29
|
-
x = formatX(graph.x()(e, e.pointIndex)),
|
30
|
-
//x = formatX(graph.x()(e.point)),
|
31
|
-
y = formatY(graph.y()(e.point)),
|
32
|
-
content = tooltip(e.series.key, x, y, e, graph);
|
33
|
-
|
34
|
-
nv.tooltip.show([left, top], content);
|
35
|
-
};
|
36
|
-
|
37
|
-
//setting component defaults
|
38
|
-
//graph.xAxis.tickFormat(d3.format(',r'));
|
39
|
-
graph.xAxis.tickFormat(function(d) {
|
40
|
-
//return d3.time.format('%x')(new Date(d))
|
41
|
-
return d3.time.format('%x')(new Date(data[0].values[d].x))
|
42
|
-
});
|
43
|
-
|
44
|
-
//graph.yAxis.tickFormat(d3.format(',.2f'));
|
45
|
-
graph.yAxis.tickFormat(d3.format(',.2%'));
|
46
|
-
|
47
|
-
|
48
|
-
//TODO: consider a method more similar to how the models are built
|
49
|
-
function chart() {
|
50
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
51
|
-
|
52
|
-
d3.select(selector).select('svg')
|
53
|
-
.datum(data)
|
54
|
-
.transition().duration(duration).call(graph); //consider using transition chaining like in the models
|
55
|
-
|
56
|
-
return chart;
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
// This should always only be called once, then update should be used after,
|
61
|
-
// in which case should consider the 'd3 way' and merge this with update,
|
62
|
-
// but simply do this on enter... will try another example the d3 way
|
63
|
-
chart.build = function() {
|
64
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
65
|
-
|
66
|
-
nv.addGraph({
|
67
|
-
generate: function() {
|
68
|
-
var container = d3.select(selector),
|
69
|
-
width = function() { return parseInt(container.style('width')) },
|
70
|
-
height = function() { return parseInt(container.style('height')) },
|
71
|
-
svg = container.append('svg');
|
72
|
-
|
73
|
-
graph
|
74
|
-
.width(width)
|
75
|
-
.height(height);
|
76
|
-
|
77
|
-
svg
|
78
|
-
.attr('width', width())
|
79
|
-
.attr('height', height())
|
80
|
-
.datum(data)
|
81
|
-
.transition().duration(duration).call(graph);
|
82
|
-
|
83
|
-
return graph;
|
84
|
-
},
|
85
|
-
callback: function(graph) {
|
86
|
-
graph.dispatch.on('tooltipShow', showTooltip);
|
87
|
-
graph.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
88
|
-
|
89
|
-
//TODO: fix issue of multiple graphs failing on resize
|
90
|
-
//TODO: create resize queue and have nv core handle resize instead of binding all to window resize
|
91
|
-
window.onresize =
|
92
|
-
function() {
|
93
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
94
|
-
d3.select(selector + ' svg')
|
95
|
-
.attr('width', graph.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
96
|
-
.attr('height', graph.height()())
|
97
|
-
.call(graph);
|
98
|
-
};
|
99
|
-
}
|
100
|
-
});
|
101
|
-
|
102
|
-
return chart;
|
103
|
-
};
|
104
|
-
|
105
|
-
|
106
|
-
/*
|
107
|
-
// moved to chart()
|
108
|
-
chart.update = function() {
|
109
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
110
|
-
|
111
|
-
d3.select(selector).select('svg')
|
112
|
-
.datum(data)
|
113
|
-
.transition().duration(duration).call(graph);
|
114
|
-
|
115
|
-
return chart;
|
116
|
-
};
|
117
|
-
*/
|
118
|
-
|
119
|
-
chart.data = function(_) {
|
120
|
-
if (!arguments.length) return data;
|
121
|
-
data = _;
|
122
|
-
return chart;
|
123
|
-
};
|
124
|
-
|
125
|
-
chart.selector = function(_) {
|
126
|
-
if (!arguments.length) return selector;
|
127
|
-
selector = _;
|
128
|
-
return chart;
|
129
|
-
};
|
130
|
-
|
131
|
-
chart.duration = function(_) {
|
132
|
-
if (!arguments.length) return duration;
|
133
|
-
duration = _;
|
134
|
-
return chart;
|
135
|
-
};
|
136
|
-
|
137
|
-
chart.tooltip = function(_) {
|
138
|
-
if (!arguments.length) return tooltip;
|
139
|
-
tooltip = _;
|
140
|
-
return chart;
|
141
|
-
};
|
142
|
-
|
143
|
-
chart.xTickFormat = function(_) {
|
144
|
-
if (!arguments.length) return graph.xAxis.tickFormat();
|
145
|
-
graph.xAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
146
|
-
return chart;
|
147
|
-
};
|
148
|
-
|
149
|
-
chart.yTickFormat = function(_) {
|
150
|
-
if (!arguments.length) return graph.yAxis.tickFormat();
|
151
|
-
graph.yAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
152
|
-
return chart;
|
153
|
-
};
|
154
|
-
|
155
|
-
chart.xAxisLabel = function(_) {
|
156
|
-
if (!arguments.length) return graph.xAxis.axisLabel();
|
157
|
-
graph.xAxis.axisLabel(_);
|
158
|
-
return chart;
|
159
|
-
};
|
160
|
-
|
161
|
-
chart.yAxisLabel = function(_) {
|
162
|
-
if (!arguments.length) return graph.yAxis.axisLabel();
|
163
|
-
graph.yAxis.axisLabel(_);
|
164
|
-
return chart;
|
165
|
-
};
|
166
|
-
|
167
|
-
d3.rebind(chart, graph, 'x', 'y');
|
168
|
-
|
169
|
-
chart.graph = graph; // Give direct access for getter/setters, and dispatchers
|
170
|
-
|
171
|
-
return chart;
|
172
|
-
};
|
173
|
-
|
174
|
-
|
@@ -1,157 +0,0 @@
|
|
1
|
-
|
2
|
-
nv.charts.discreteBar = function() {
|
3
|
-
var selector = null,
|
4
|
-
data = [],
|
5
|
-
duration = 500,
|
6
|
-
tooltip = function(key, x, y, e, graph) {
|
7
|
-
return '<h3>' + x + '</h3>' +
|
8
|
-
'<p>' + y + '</p>'
|
9
|
-
};
|
10
|
-
|
11
|
-
|
12
|
-
var graph = nv.models.discreteBarWithAxes(),
|
13
|
-
showTooltip = function(e) {
|
14
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
15
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
16
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
17
|
-
formatY = graph.yAxis.tickFormat(), //Assumes using same format as axis, can customize to show higher precision, etc.
|
18
|
-
formatX = graph.xAxis.tickFormat(),
|
19
|
-
x = formatX(graph.x()(e.point)),
|
20
|
-
y = formatY(graph.y()(e.point)),
|
21
|
-
content = tooltip(e.series.key, x, y, e, graph);
|
22
|
-
|
23
|
-
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's');
|
24
|
-
};
|
25
|
-
|
26
|
-
//setting component defaults
|
27
|
-
graph.xAxis.tickFormat(function(d) { return d });
|
28
|
-
graph.yAxis.tickFormat(d3.format(',.f'));
|
29
|
-
|
30
|
-
|
31
|
-
//TODO: consider a method more similar to how the models are built
|
32
|
-
function chart() {
|
33
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
34
|
-
|
35
|
-
d3.select(selector).select('svg')
|
36
|
-
.datum(data)
|
37
|
-
.transition().duration(duration).call(graph); //consider using transition chaining like in the models
|
38
|
-
|
39
|
-
return chart;
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
// This should always only be called once, then update should be used after,
|
44
|
-
// in which case should consider the 'd3 way' and merge this with update,
|
45
|
-
// but simply do this on enter... should try anoter example that way
|
46
|
-
chart.build = function() {
|
47
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
48
|
-
|
49
|
-
nv.addGraph({
|
50
|
-
generate: function() {
|
51
|
-
var container = d3.select(selector),
|
52
|
-
width = function() { return parseInt(container.style('width')) },
|
53
|
-
height = function() { return parseInt(container.style('height')) },
|
54
|
-
svg = container.append('svg');
|
55
|
-
|
56
|
-
graph
|
57
|
-
.width(width)
|
58
|
-
.height(height);
|
59
|
-
|
60
|
-
svg
|
61
|
-
.attr('width', width())
|
62
|
-
.attr('height', height())
|
63
|
-
.datum(data)
|
64
|
-
.transition().duration(duration).call(graph);
|
65
|
-
|
66
|
-
return graph;
|
67
|
-
},
|
68
|
-
callback: function(graph) {
|
69
|
-
graph.dispatch.on('tooltipShow', showTooltip);
|
70
|
-
graph.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
71
|
-
|
72
|
-
//TODO: create resize queue and have nv core handle resize instead of binding all to window resize
|
73
|
-
nv.utils.windowResize(
|
74
|
-
function() {
|
75
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
76
|
-
d3.select(selector + ' svg')
|
77
|
-
.attr('width', graph.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
78
|
-
.attr('height', graph.height()())
|
79
|
-
.transition().duration(duration).call(graph);
|
80
|
-
//.call(graph);
|
81
|
-
}
|
82
|
-
);
|
83
|
-
}
|
84
|
-
});
|
85
|
-
|
86
|
-
return chart;
|
87
|
-
};
|
88
|
-
|
89
|
-
|
90
|
-
/*
|
91
|
-
// moved to chart()
|
92
|
-
chart.update = function() {
|
93
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
94
|
-
|
95
|
-
d3.select(selector).select('svg')
|
96
|
-
.datum(data)
|
97
|
-
.transition().duration(duration).call(graph);
|
98
|
-
|
99
|
-
return chart;
|
100
|
-
};
|
101
|
-
*/
|
102
|
-
|
103
|
-
chart.data = function(_) {
|
104
|
-
if (!arguments.length) return data;
|
105
|
-
data = _;
|
106
|
-
return chart;
|
107
|
-
};
|
108
|
-
|
109
|
-
chart.selector = function(_) {
|
110
|
-
if (!arguments.length) return selector;
|
111
|
-
selector = _;
|
112
|
-
return chart;
|
113
|
-
};
|
114
|
-
|
115
|
-
chart.duration = function(_) {
|
116
|
-
if (!arguments.length) return duration;
|
117
|
-
duration = _;
|
118
|
-
return chart;
|
119
|
-
};
|
120
|
-
|
121
|
-
chart.tooltip = function(_) {
|
122
|
-
if (!arguments.length) return tooltip;
|
123
|
-
tooltip = _;
|
124
|
-
return chart;
|
125
|
-
};
|
126
|
-
|
127
|
-
chart.xTickFormat = function(_) {
|
128
|
-
if (!arguments.length) return graph.xAxis.tickFormat();
|
129
|
-
graph.xAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
130
|
-
return chart;
|
131
|
-
};
|
132
|
-
|
133
|
-
chart.yTickFormat = function(_) {
|
134
|
-
if (!arguments.length) return graph.yAxis.tickFormat();
|
135
|
-
graph.yAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
136
|
-
return chart;
|
137
|
-
};
|
138
|
-
|
139
|
-
chart.xAxisLabel = function(_) {
|
140
|
-
if (!arguments.length) return graph.xAxis.axisLabel();
|
141
|
-
graph.xAxis.axisLabel(_);
|
142
|
-
return chart;
|
143
|
-
};
|
144
|
-
|
145
|
-
chart.yAxisLabel = function(_) {
|
146
|
-
if (!arguments.length) return graph.yAxis.axisLabel();
|
147
|
-
graph.yAxis.axisLabel(_);
|
148
|
-
return chart;
|
149
|
-
};
|
150
|
-
|
151
|
-
d3.rebind(chart, graph, 'x', 'y', 'staggerLabels');
|
152
|
-
|
153
|
-
chart.graph = graph; // Give direct access for getter/setters, and dispatchers
|
154
|
-
|
155
|
-
return chart;
|
156
|
-
};
|
157
|
-
|