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,159 +0,0 @@
|
|
1
|
-
|
2
|
-
// This is an attempt to make an extremely easy to use chart that is ready to go,
|
3
|
-
// basically the chart models with the extra glue... Queuing, tooltips, automatic resize, etc.
|
4
|
-
// I may make these more specific, like 'time series line with month end data points', etc.
|
5
|
-
// or may make yet another layer of abstraction... common settings.
|
6
|
-
nv.charts.line = function() {
|
7
|
-
var selector = null,
|
8
|
-
data = [],
|
9
|
-
duration = 500,
|
10
|
-
tooltip = function(key, x, y, e, graph) {
|
11
|
-
return '<h3>' + key + '</h3>' +
|
12
|
-
'<p>' + y + ' at ' + x + '</p>'
|
13
|
-
};
|
14
|
-
|
15
|
-
|
16
|
-
var graph = nv.models.lineWithLegend(),
|
17
|
-
showTooltip = function(e) {
|
18
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
19
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
20
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
21
|
-
formatX = graph.xAxis.tickFormat(),
|
22
|
-
formatY = graph.yAxis.tickFormat(),
|
23
|
-
x = formatX(graph.x()(e.point)),
|
24
|
-
y = formatY(graph.y()(e.point)),
|
25
|
-
content = tooltip(e.series.key, x, y, e, graph);
|
26
|
-
|
27
|
-
nv.tooltip.show([left, top], content);
|
28
|
-
};
|
29
|
-
|
30
|
-
//setting component defaults
|
31
|
-
graph.xAxis.tickFormat(d3.format(',r'));
|
32
|
-
graph.yAxis.tickFormat(d3.format(',.2f'));
|
33
|
-
|
34
|
-
|
35
|
-
//TODO: consider a method more similar to how the models are built
|
36
|
-
function chart() {
|
37
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
38
|
-
|
39
|
-
d3.select(selector).select('svg')
|
40
|
-
.datum(data)
|
41
|
-
.transition().duration(duration).call(graph); //consider using transition chaining like in the models
|
42
|
-
|
43
|
-
return chart;
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
// This should always only be called once, then update should be used after,
|
48
|
-
// in which case should consider the 'd3 way' and merge this with update,
|
49
|
-
// but simply do this on enter... should try anoter example that way
|
50
|
-
chart.build = function() {
|
51
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
52
|
-
|
53
|
-
nv.addGraph({
|
54
|
-
generate: function() {
|
55
|
-
var container = d3.select(selector),
|
56
|
-
width = function() { return parseInt(container.style('width')) },
|
57
|
-
height = function() { return parseInt(container.style('height')) },
|
58
|
-
svg = container.append('svg');
|
59
|
-
|
60
|
-
graph
|
61
|
-
.width(width)
|
62
|
-
.height(height);
|
63
|
-
|
64
|
-
svg
|
65
|
-
.attr('width', width())
|
66
|
-
.attr('height', height())
|
67
|
-
.datum(data)
|
68
|
-
.transition().duration(duration).call(graph);
|
69
|
-
|
70
|
-
return graph;
|
71
|
-
},
|
72
|
-
callback: function(graph) {
|
73
|
-
graph.dispatch.on('tooltipShow', showTooltip);
|
74
|
-
graph.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
75
|
-
|
76
|
-
//TODO: create resize queue and have nv core handle resize instead of binding all to window resize
|
77
|
-
window.onresize =
|
78
|
-
function() {
|
79
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
80
|
-
d3.select(selector + ' svg')
|
81
|
-
.attr('width', graph.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
82
|
-
.attr('height', graph.height()())
|
83
|
-
.call(graph);
|
84
|
-
};
|
85
|
-
}
|
86
|
-
});
|
87
|
-
|
88
|
-
return chart;
|
89
|
-
};
|
90
|
-
|
91
|
-
|
92
|
-
/*
|
93
|
-
// moved to chart()
|
94
|
-
chart.update = function() {
|
95
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
96
|
-
|
97
|
-
d3.select(selector).select('svg')
|
98
|
-
.datum(data)
|
99
|
-
.transition().duration(duration).call(graph);
|
100
|
-
|
101
|
-
return chart;
|
102
|
-
};
|
103
|
-
*/
|
104
|
-
|
105
|
-
chart.data = function(_) {
|
106
|
-
if (!arguments.length) return data;
|
107
|
-
data = _;
|
108
|
-
return chart;
|
109
|
-
};
|
110
|
-
|
111
|
-
chart.selector = function(_) {
|
112
|
-
if (!arguments.length) return selector;
|
113
|
-
selector = _;
|
114
|
-
return chart;
|
115
|
-
};
|
116
|
-
|
117
|
-
chart.duration = function(_) {
|
118
|
-
if (!arguments.length) return duration;
|
119
|
-
duration = _;
|
120
|
-
return chart;
|
121
|
-
};
|
122
|
-
|
123
|
-
chart.tooltip = function(_) {
|
124
|
-
if (!arguments.length) return tooltip;
|
125
|
-
tooltip = _;
|
126
|
-
return chart;
|
127
|
-
};
|
128
|
-
|
129
|
-
chart.xTickFormat = function(_) {
|
130
|
-
if (!arguments.length) return graph.xAxis.tickFormat();
|
131
|
-
graph.xAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
132
|
-
return chart;
|
133
|
-
};
|
134
|
-
|
135
|
-
chart.yTickFormat = function(_) {
|
136
|
-
if (!arguments.length) return graph.yAxis.tickFormat();
|
137
|
-
graph.yAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
138
|
-
return chart;
|
139
|
-
};
|
140
|
-
|
141
|
-
chart.xAxisLabel = function(_) {
|
142
|
-
if (!arguments.length) return graph.xAxis.axisLabel();
|
143
|
-
graph.xAxis.axisLabel(_);
|
144
|
-
return chart;
|
145
|
-
};
|
146
|
-
|
147
|
-
chart.yAxisLabel = function(_) {
|
148
|
-
if (!arguments.length) return graph.yAxis.axisLabel();
|
149
|
-
graph.yAxis.axisLabel(_);
|
150
|
-
return chart;
|
151
|
-
};
|
152
|
-
|
153
|
-
d3.rebind(chart, graph, 'x', 'y');
|
154
|
-
|
155
|
-
chart.graph = graph; // Give direct access for getter/setters, and dispatchers
|
156
|
-
|
157
|
-
return chart;
|
158
|
-
};
|
159
|
-
|
@@ -1,168 +0,0 @@
|
|
1
|
-
|
2
|
-
// This is an attempt to make an extremely easy to use chart that is ready to go,
|
3
|
-
// basically the chart models with the extra glue... Queuing, tooltips, automatic resize, etc.
|
4
|
-
// I may make these more specific, like 'time series line with month end data points', etc.
|
5
|
-
// or may make yet another layer of abstraction... common settings.
|
6
|
-
nv.charts.lineChartDaily = function() {
|
7
|
-
var selector = null,
|
8
|
-
data = [],
|
9
|
-
duration = 500,
|
10
|
-
tooltip = function(key, x, y, e, graph) {
|
11
|
-
return '<h3>' + key + '</h3>' +
|
12
|
-
'<p>' + y + ' at ' + x + '</p>'
|
13
|
-
};
|
14
|
-
|
15
|
-
|
16
|
-
var graph = nv.models.lineWithLegend()
|
17
|
-
.x(function(d,i) { return i }),
|
18
|
-
showTooltip = function(e) {
|
19
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
20
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
21
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
22
|
-
formatX = graph.xAxis.tickFormat(),
|
23
|
-
formatY = graph.yAxis.tickFormat(),
|
24
|
-
x = formatX(graph.x()(e, e.pointIndex)),
|
25
|
-
//x = formatX(graph.x()(e.point)),
|
26
|
-
y = formatY(graph.y()(e.point)),
|
27
|
-
content = tooltip(e.series.key, x, y, e, graph);
|
28
|
-
|
29
|
-
nv.tooltip.show([left, top], content);
|
30
|
-
};
|
31
|
-
|
32
|
-
//setting component defaults
|
33
|
-
//graph.xAxis.tickFormat(d3.format(',r'));
|
34
|
-
graph.xAxis.tickFormat(function(d) {
|
35
|
-
//return d3.time.format('%x')(new Date(d))
|
36
|
-
//log(d, data[0].values[d]);
|
37
|
-
return d3.time.format('%x')(new Date(data[0].values[d].x))
|
38
|
-
});
|
39
|
-
|
40
|
-
//graph.yAxis.tickFormat(d3.format(',.2f'));
|
41
|
-
graph.yAxis.tickFormat(d3.format(',.2%'));
|
42
|
-
|
43
|
-
|
44
|
-
//TODO: consider a method more similar to how the models are built
|
45
|
-
function chart() {
|
46
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
47
|
-
|
48
|
-
d3.select(selector).select('svg')
|
49
|
-
.datum(data)
|
50
|
-
.transition().duration(duration).call(graph); //consider using transition chaining like in the models
|
51
|
-
|
52
|
-
return chart;
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
// This should always only be called once, then update should be used after,
|
57
|
-
// in which case should consider the 'd3 way' and merge this with update,
|
58
|
-
// but simply do this on enter... should try anoter example that way
|
59
|
-
chart.build = function() {
|
60
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
61
|
-
|
62
|
-
nv.addGraph({
|
63
|
-
generate: function() {
|
64
|
-
var container = d3.select(selector),
|
65
|
-
width = function() { return parseInt(container.style('width')) },
|
66
|
-
height = function() { return parseInt(container.style('height')) },
|
67
|
-
svg = container.append('svg');
|
68
|
-
|
69
|
-
graph
|
70
|
-
.width(width)
|
71
|
-
.height(height);
|
72
|
-
|
73
|
-
svg
|
74
|
-
.attr('width', width())
|
75
|
-
.attr('height', height())
|
76
|
-
.datum(data)
|
77
|
-
.transition().duration(duration).call(graph);
|
78
|
-
|
79
|
-
return graph;
|
80
|
-
},
|
81
|
-
callback: function(graph) {
|
82
|
-
graph.dispatch.on('tooltipShow', showTooltip);
|
83
|
-
graph.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
84
|
-
|
85
|
-
//TODO: create resize queue and have nv core handle resize instead of binding all to window resize
|
86
|
-
window.onresize =
|
87
|
-
function() {
|
88
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
89
|
-
d3.select(selector + ' svg')
|
90
|
-
.attr('width', graph.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
91
|
-
.attr('height', graph.height()())
|
92
|
-
.call(graph);
|
93
|
-
};
|
94
|
-
}
|
95
|
-
});
|
96
|
-
|
97
|
-
return chart;
|
98
|
-
};
|
99
|
-
|
100
|
-
|
101
|
-
/*
|
102
|
-
// moved to chart()
|
103
|
-
chart.update = function() {
|
104
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
105
|
-
|
106
|
-
d3.select(selector).select('svg')
|
107
|
-
.datum(data)
|
108
|
-
.transition().duration(duration).call(graph);
|
109
|
-
|
110
|
-
return chart;
|
111
|
-
};
|
112
|
-
*/
|
113
|
-
|
114
|
-
chart.data = function(_) {
|
115
|
-
if (!arguments.length) return data;
|
116
|
-
data = _;
|
117
|
-
return chart;
|
118
|
-
};
|
119
|
-
|
120
|
-
chart.selector = function(_) {
|
121
|
-
if (!arguments.length) return selector;
|
122
|
-
selector = _;
|
123
|
-
return chart;
|
124
|
-
};
|
125
|
-
|
126
|
-
chart.duration = function(_) {
|
127
|
-
if (!arguments.length) return duration;
|
128
|
-
duration = _;
|
129
|
-
return chart;
|
130
|
-
};
|
131
|
-
|
132
|
-
chart.tooltip = function(_) {
|
133
|
-
if (!arguments.length) return tooltip;
|
134
|
-
tooltip = _;
|
135
|
-
return chart;
|
136
|
-
};
|
137
|
-
|
138
|
-
chart.xTickFormat = function(_) {
|
139
|
-
if (!arguments.length) return graph.xAxis.tickFormat();
|
140
|
-
graph.xAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
141
|
-
return chart;
|
142
|
-
};
|
143
|
-
|
144
|
-
chart.yTickFormat = function(_) {
|
145
|
-
if (!arguments.length) return graph.yAxis.tickFormat();
|
146
|
-
graph.yAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
147
|
-
return chart;
|
148
|
-
};
|
149
|
-
|
150
|
-
chart.xAxisLabel = function(_) {
|
151
|
-
if (!arguments.length) return graph.xAxis.axisLabel();
|
152
|
-
graph.xAxis.axisLabel(_);
|
153
|
-
return chart;
|
154
|
-
};
|
155
|
-
|
156
|
-
chart.yAxisLabel = function(_) {
|
157
|
-
if (!arguments.length) return graph.yAxis.axisLabel();
|
158
|
-
graph.yAxis.axisLabel(_);
|
159
|
-
return chart;
|
160
|
-
};
|
161
|
-
|
162
|
-
d3.rebind(chart, graph, 'x', 'y');
|
163
|
-
|
164
|
-
chart.graph = graph; // Give direct access for getter/setters, and dispatchers
|
165
|
-
|
166
|
-
return chart;
|
167
|
-
};
|
168
|
-
|
@@ -1,177 +0,0 @@
|
|
1
|
-
|
2
|
-
/***
|
3
|
-
* This chart treats the X position as the INDEX, not the value
|
4
|
-
* Each series at the same index MUST be the same x value for a valid representation
|
5
|
-
* This is needed specifically for daily data where the gap between Friday and Monday
|
6
|
-
* should be equal to the gap from Monday to Tuesday. (and of course, holidays can be
|
7
|
-
* omitted without issue, as long as ALL series omit the same days).
|
8
|
-
* An intentional side effect is that ALL ticks will land on actual data points,
|
9
|
-
* so this visualization can also be used for Month End data points, showing Month End
|
10
|
-
* ticks on the X axis
|
11
|
-
***/
|
12
|
-
|
13
|
-
nv.charts.stackedAreaChart = function() {
|
14
|
-
var selector = null,
|
15
|
-
data = [],
|
16
|
-
duration = 500,
|
17
|
-
tooltip = function(key, x, y, e, graph) {
|
18
|
-
return '<h3>' + key + '</h3>' +
|
19
|
-
'<p>' + y + ' at ' + x + '</p>'
|
20
|
-
};
|
21
|
-
|
22
|
-
|
23
|
-
var graph = nv.models.stackedAreaWithLegend()
|
24
|
-
.x(function(d,i) { return i }),
|
25
|
-
showTooltip = function(e) {
|
26
|
-
var offsetElement = document.getElementById(selector.substr(1)),
|
27
|
-
left = e.pos[0] + offsetElement.offsetLeft,
|
28
|
-
top = e.pos[1] + offsetElement.offsetTop,
|
29
|
-
formatX = graph.xAxis.tickFormat(),
|
30
|
-
formatY = graph.yAxis.tickFormat(),
|
31
|
-
x = formatX(graph.x()(e, e.pointIndex)),
|
32
|
-
//x = formatX(graph.x()(e.point)),
|
33
|
-
y = formatY(graph.y()(e.point)),
|
34
|
-
content = tooltip(e.series.key, x, y, e, graph);
|
35
|
-
|
36
|
-
nv.tooltip.show([left, top], content);
|
37
|
-
};
|
38
|
-
|
39
|
-
//setting component defaults
|
40
|
-
//graph.xAxis.tickFormat(d3.format(',r'));
|
41
|
-
graph.xAxis.tickFormat(function(d) {
|
42
|
-
//return d3.time.format('%x')(new Date(d))
|
43
|
-
//log(d, data[0].values[d]);
|
44
|
-
return d3.time.format('%x')(new Date(data[0].values[d].x))
|
45
|
-
});
|
46
|
-
|
47
|
-
//graph.yAxis.tickFormat(d3.format(',.2f'));
|
48
|
-
graph.yAxis.tickFormat(d3.format(',.2%'));
|
49
|
-
|
50
|
-
|
51
|
-
//TODO: consider a method more similar to how the models are built
|
52
|
-
function chart() {
|
53
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
54
|
-
|
55
|
-
d3.select(selector).select('svg')
|
56
|
-
.datum(data)
|
57
|
-
.transition().duration(duration)
|
58
|
-
.call(graph); //consider using transition chaining like in the models
|
59
|
-
|
60
|
-
return chart;
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
// This should always only be called once, then update should be used after,
|
65
|
-
// in which case should consider the 'd3 way' and merge this with update,
|
66
|
-
// but simply do this on enter... should try anoter example that way
|
67
|
-
chart.build = function() {
|
68
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
69
|
-
|
70
|
-
nv.addGraph({
|
71
|
-
generate: function() {
|
72
|
-
var container = d3.select(selector),
|
73
|
-
width = function() { return parseInt(container.style('width')) },
|
74
|
-
height = function() { return parseInt(container.style('height')) },
|
75
|
-
svg = container.append('svg');
|
76
|
-
|
77
|
-
graph
|
78
|
-
.width(width)
|
79
|
-
.height(height);
|
80
|
-
|
81
|
-
svg
|
82
|
-
.attr('width', width())
|
83
|
-
.attr('height', height())
|
84
|
-
.datum(data)
|
85
|
-
.transition().duration(duration)
|
86
|
-
.call(graph);
|
87
|
-
|
88
|
-
return graph;
|
89
|
-
},
|
90
|
-
callback: function(graph) {
|
91
|
-
graph.dispatch.on('tooltipShow', showTooltip);
|
92
|
-
graph.dispatch.on('tooltipHide', nv.tooltip.cleanup);
|
93
|
-
|
94
|
-
//TODO: create resize queue and have nv core handle resize instead of binding all to window resize
|
95
|
-
window.onresize =
|
96
|
-
function() {
|
97
|
-
// now that width and height are functions, should be automatic..of course you can always override them
|
98
|
-
d3.select(selector + ' svg')
|
99
|
-
.attr('width', graph.width()()) //need to set SVG dimensions, chart is not aware of the SVG component
|
100
|
-
.attr('height', graph.height()())
|
101
|
-
.call(graph);
|
102
|
-
};
|
103
|
-
}
|
104
|
-
});
|
105
|
-
|
106
|
-
return chart;
|
107
|
-
};
|
108
|
-
|
109
|
-
|
110
|
-
/*
|
111
|
-
// moved to chart()
|
112
|
-
chart.update = function() {
|
113
|
-
if (!selector || !data.length) return chart; //do nothing if you have nothing to work with
|
114
|
-
|
115
|
-
d3.select(selector).select('svg')
|
116
|
-
.datum(data)
|
117
|
-
.transition().duration(duration).call(graph);
|
118
|
-
|
119
|
-
return chart;
|
120
|
-
};
|
121
|
-
*/
|
122
|
-
|
123
|
-
chart.data = function(_) {
|
124
|
-
if (!arguments.length) return data;
|
125
|
-
data = _;
|
126
|
-
return chart;
|
127
|
-
};
|
128
|
-
|
129
|
-
chart.selector = function(_) {
|
130
|
-
if (!arguments.length) return selector;
|
131
|
-
selector = _;
|
132
|
-
return chart;
|
133
|
-
};
|
134
|
-
|
135
|
-
chart.duration = function(_) {
|
136
|
-
if (!arguments.length) return duration;
|
137
|
-
duration = _;
|
138
|
-
return chart;
|
139
|
-
};
|
140
|
-
|
141
|
-
chart.tooltip = function(_) {
|
142
|
-
if (!arguments.length) return tooltip;
|
143
|
-
tooltip = _;
|
144
|
-
return chart;
|
145
|
-
};
|
146
|
-
|
147
|
-
chart.xTickFormat = function(_) {
|
148
|
-
if (!arguments.length) return graph.xAxis.tickFormat();
|
149
|
-
graph.xAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
150
|
-
return chart;
|
151
|
-
};
|
152
|
-
|
153
|
-
chart.yTickFormat = function(_) {
|
154
|
-
if (!arguments.length) return graph.yAxis.tickFormat();
|
155
|
-
graph.yAxis.tickFormat(typeof _ === 'function' ? _ : d3.format(_));
|
156
|
-
return chart;
|
157
|
-
};
|
158
|
-
|
159
|
-
chart.xAxisLabel = function(_) {
|
160
|
-
if (!arguments.length) return graph.xAxis.axisLabel();
|
161
|
-
graph.xAxis.axisLabel(_);
|
162
|
-
return chart;
|
163
|
-
};
|
164
|
-
|
165
|
-
chart.yAxisLabel = function(_) {
|
166
|
-
if (!arguments.length) return graph.yAxis.axisLabel();
|
167
|
-
graph.yAxis.axisLabel(_);
|
168
|
-
return chart;
|
169
|
-
};
|
170
|
-
|
171
|
-
d3.rebind(chart, graph, 'x', 'y');
|
172
|
-
|
173
|
-
chart.graph = graph; // Give direct access for getter/setters, and dispatchers
|
174
|
-
|
175
|
-
return chart;
|
176
|
-
};
|
177
|
-
|