chartx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +145 -0
- data/Rakefile +1 -0
- data/chartx.gemspec +40 -0
- data/lib/chartx/engine.rb +11 -0
- data/lib/chartx/helper.rb +184 -0
- data/lib/chartx/version.rb +3 -0
- data/lib/chartx.rb +3 -0
- data/screenshots/barchart.png +0 -0
- data/screenshots/bulletchart.png +0 -0
- data/screenshots/horizontalbarchart.png +0 -0
- data/screenshots/linechart.png +0 -0
- data/screenshots/linewithfocuschart.png +0 -0
- data/screenshots/multibarchart2.png +0 -0
- data/screenshots/piechart.png +0 -0
- data/screenshots/scatterchart.png +0 -0
- data/screenshots/stackedareachart.png +0 -0
- data/screenshots/stackedareachart3.png +0 -0
- data/vendor/assets/javascripts/chartx-core.js +9 -0
- data/vendor/assets/javascripts/chartx-models.js +2 -0
- data/vendor/assets/javascripts/nvd3/.gitignore +27 -0
- data/vendor/assets/javascripts/nvd3/.jshintrc +3 -0
- data/vendor/assets/javascripts/nvd3/LICENSE.md +49 -0
- data/vendor/assets/javascripts/nvd3/README.md +1 -0
- data/vendor/assets/javascripts/nvd3/lib/cie.js +155 -0
- data/vendor/assets/javascripts/nvd3/lib/crossfilter.js +1180 -0
- data/vendor/assets/javascripts/nvd3/lib/crossfilter.min.js +1 -0
- data/vendor/assets/javascripts/nvd3/lib/d3.js +8798 -0
- data/vendor/assets/javascripts/nvd3/lib/d3.min.js +5 -0
- data/vendor/assets/javascripts/nvd3/lib/fisheye.js +86 -0
- data/vendor/assets/javascripts/nvd3/lib/hive.js +80 -0
- data/vendor/assets/javascripts/nvd3/lib/horizon.js +192 -0
- data/vendor/assets/javascripts/nvd3/lib/sankey.js +292 -0
- data/vendor/assets/javascripts/nvd3/nv.d3.js +13048 -0
- data/vendor/assets/javascripts/nvd3/nv.d3.min.js +6 -0
- data/vendor/assets/javascripts/nvd3/src/core.js +118 -0
- data/vendor/assets/javascripts/nvd3/src/intro.js +1 -0
- data/vendor/assets/javascripts/nvd3/src/models/axis.js +398 -0
- data/vendor/assets/javascripts/nvd3/src/models/boilerplate.js +102 -0
- data/vendor/assets/javascripts/nvd3/src/models/bullet.js +377 -0
- data/vendor/assets/javascripts/nvd3/src/models/bulletChart.js +341 -0
- data/vendor/assets/javascripts/nvd3/src/models/cumulativeLineChart.js +685 -0
- data/vendor/assets/javascripts/nvd3/src/models/discreteBar.js +327 -0
- data/vendor/assets/javascripts/nvd3/src/models/discreteBarChart.js +290 -0
- data/vendor/assets/javascripts/nvd3/src/models/distribution.js +146 -0
- data/vendor/assets/javascripts/nvd3/src/models/historicalBar.js +289 -0
- data/vendor/assets/javascripts/nvd3/src/models/historicalBarChart.js +421 -0
- data/vendor/assets/javascripts/nvd3/src/models/indentedTree.js +317 -0
- data/vendor/assets/javascripts/nvd3/src/models/legend.js +207 -0
- data/vendor/assets/javascripts/nvd3/src/models/line.js +284 -0
- data/vendor/assets/javascripts/nvd3/src/models/lineChart.js +421 -0
- data/vendor/assets/javascripts/nvd3/src/models/linePlusBarChart.js +455 -0
- data/vendor/assets/javascripts/nvd3/src/models/linePlusBarWithFocusChart.js +665 -0
- data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheye.js +197 -0
- data/vendor/assets/javascripts/nvd3/src/models/lineWithFisheyeChart.js +319 -0
- data/vendor/assets/javascripts/nvd3/src/models/lineWithFocusChart.js +560 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBar.js +442 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBarChart.js +506 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontal.js +420 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBarHorizontalChart.js +448 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeries.js +371 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiBarTimeSeriesChart.js +403 -0
- data/vendor/assets/javascripts/nvd3/src/models/multiChart.js +444 -0
- data/vendor/assets/javascripts/nvd3/src/models/ohlcBar.js +365 -0
- data/vendor/assets/javascripts/nvd3/src/models/parallelCoordinates.js +238 -0
- data/vendor/assets/javascripts/nvd3/src/models/pie.js +386 -0
- data/vendor/assets/javascripts/nvd3/src/models/pieChart.js +302 -0
- data/vendor/assets/javascripts/nvd3/src/models/scatter.js +660 -0
- data/vendor/assets/javascripts/nvd3/src/models/scatterChart.js +614 -0
- data/vendor/assets/javascripts/nvd3/src/models/scatterPlusLineChart.js +610 -0
- data/vendor/assets/javascripts/nvd3/src/models/sparkline.js +179 -0
- data/vendor/assets/javascripts/nvd3/src/models/sparklinePlus.js +293 -0
- data/vendor/assets/javascripts/nvd3/src/models/stackedArea.js +336 -0
- data/vendor/assets/javascripts/nvd3/src/models/stackedAreaChart.js +490 -0
- data/vendor/assets/javascripts/nvd3/src/nv.d3.css +704 -0
- data/vendor/assets/javascripts/nvd3/src/outro.js +1 -0
- data/vendor/assets/javascripts/nvd3/src/tooltip.js +133 -0
- data/vendor/assets/javascripts/nvd3/src/utils.js +118 -0
- data/vendor/assets/javascripts/set-env.js.erb +1 -0
- data/vendor/assets/stylesheets/chartx.css +3 -0
- metadata +189 -0
@@ -0,0 +1,398 @@
|
|
1
|
+
nv.models.axis = function() {
|
2
|
+
|
3
|
+
//============================================================
|
4
|
+
// Public Variables with Default Settings
|
5
|
+
//------------------------------------------------------------
|
6
|
+
|
7
|
+
var axis = d3.svg.axis()
|
8
|
+
;
|
9
|
+
|
10
|
+
var margin = {top: 0, right: 0, bottom: 0, left: 0}
|
11
|
+
, width = 75 //only used for tickLabel currently
|
12
|
+
, height = 60 //only used for tickLabel currently
|
13
|
+
, scale = d3.scale.linear()
|
14
|
+
, axisLabelText = null
|
15
|
+
, showMaxMin = true //TODO: showMaxMin should be disabled on all ordinal scaled axes
|
16
|
+
, highlightZero = true
|
17
|
+
, rotateLabels = 0
|
18
|
+
, rotateYLabel = true
|
19
|
+
, staggerLabels = false
|
20
|
+
, isOrdinal = false
|
21
|
+
, ticks = null
|
22
|
+
;
|
23
|
+
|
24
|
+
axis
|
25
|
+
.scale(scale)
|
26
|
+
.orient('bottom')
|
27
|
+
.tickFormat(function(d) { return d })
|
28
|
+
;
|
29
|
+
|
30
|
+
//============================================================
|
31
|
+
|
32
|
+
|
33
|
+
//============================================================
|
34
|
+
// Private Variables
|
35
|
+
//------------------------------------------------------------
|
36
|
+
|
37
|
+
var scale0;
|
38
|
+
|
39
|
+
//============================================================
|
40
|
+
|
41
|
+
|
42
|
+
function chart(selection) {
|
43
|
+
selection.each(function(data) {
|
44
|
+
var container = d3.select(this);
|
45
|
+
|
46
|
+
|
47
|
+
//------------------------------------------------------------
|
48
|
+
// Setup containers and skeleton of chart
|
49
|
+
|
50
|
+
var wrap = container.selectAll('g.nv-wrap.nv-axis').data([data]);
|
51
|
+
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-axis');
|
52
|
+
var gEnter = wrapEnter.append('g');
|
53
|
+
var g = wrap.select('g')
|
54
|
+
|
55
|
+
//------------------------------------------------------------
|
56
|
+
|
57
|
+
|
58
|
+
if (ticks !== null)
|
59
|
+
axis.ticks(ticks);
|
60
|
+
else if (axis.orient() == 'top' || axis.orient() == 'bottom')
|
61
|
+
axis.ticks(Math.abs(scale.range()[1] - scale.range()[0]) / 100);
|
62
|
+
|
63
|
+
|
64
|
+
//TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component
|
65
|
+
|
66
|
+
|
67
|
+
d3.transition(g)
|
68
|
+
.call(axis);
|
69
|
+
|
70
|
+
scale0 = scale0 || axis.scale();
|
71
|
+
|
72
|
+
var fmt = axis.tickFormat();
|
73
|
+
if (fmt == null) {
|
74
|
+
fmt = scale0.tickFormat();
|
75
|
+
}
|
76
|
+
|
77
|
+
var axisLabel = g.selectAll('text.nv-axislabel')
|
78
|
+
.data([axisLabelText || null]);
|
79
|
+
axisLabel.exit().remove();
|
80
|
+
switch (axis.orient()) {
|
81
|
+
case 'top':
|
82
|
+
axisLabel.enter().append('text').attr('class', 'nv-axislabel');
|
83
|
+
var w = (scale.range().length==2) ? scale.range()[1] : (scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]));
|
84
|
+
axisLabel
|
85
|
+
.attr('text-anchor', 'middle')
|
86
|
+
.attr('y', 0)
|
87
|
+
.attr('x', w/2);
|
88
|
+
if (showMaxMin) {
|
89
|
+
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
|
90
|
+
.data(scale.domain());
|
91
|
+
axisMaxMin.enter().append('g').attr('class', 'nv-axisMaxMin').append('text');
|
92
|
+
axisMaxMin.exit().remove();
|
93
|
+
axisMaxMin
|
94
|
+
.attr('transform', function(d,i) {
|
95
|
+
return 'translate(' + scale(d) + ',0)'
|
96
|
+
})
|
97
|
+
.select('text')
|
98
|
+
.attr('dy', '0em')
|
99
|
+
.attr('y', -axis.tickPadding())
|
100
|
+
.attr('text-anchor', 'middle')
|
101
|
+
.text(function(d,i) {
|
102
|
+
var v = fmt(d);
|
103
|
+
return ('' + v).match('NaN') ? '' : v;
|
104
|
+
});
|
105
|
+
d3.transition(axisMaxMin)
|
106
|
+
.attr('transform', function(d,i) {
|
107
|
+
return 'translate(' + scale.range()[i] + ',0)'
|
108
|
+
});
|
109
|
+
}
|
110
|
+
break;
|
111
|
+
case 'bottom':
|
112
|
+
var xLabelMargin = 36;
|
113
|
+
var maxTextWidth = 30;
|
114
|
+
var xTicks = g.selectAll('g').select("text");
|
115
|
+
if (rotateLabels%360) {
|
116
|
+
//Calculate the longest xTick width
|
117
|
+
xTicks.each(function(d,i){
|
118
|
+
var width = this.getBBox().width;
|
119
|
+
if(width > maxTextWidth) maxTextWidth = width;
|
120
|
+
});
|
121
|
+
//Convert to radians before calculating sin. Add 30 to margin for healthy padding.
|
122
|
+
var sin = Math.abs(Math.sin(rotateLabels*Math.PI/180));
|
123
|
+
var xLabelMargin = (sin ? sin*maxTextWidth : maxTextWidth)+30;
|
124
|
+
//Rotate all xTicks
|
125
|
+
xTicks
|
126
|
+
.attr('transform', function(d,i,j) { return 'rotate(' + rotateLabels + ' 0,0)' })
|
127
|
+
.attr('text-anchor', rotateLabels%360 > 0 ? 'start' : 'end');
|
128
|
+
}
|
129
|
+
axisLabel.enter().append('text').attr('class', 'nv-axislabel');
|
130
|
+
var w = (scale.range().length==2) ? scale.range()[1] : (scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]));
|
131
|
+
axisLabel
|
132
|
+
.attr('text-anchor', 'middle')
|
133
|
+
.attr('y', xLabelMargin)
|
134
|
+
.attr('x', w/2);
|
135
|
+
if (showMaxMin) {
|
136
|
+
//if (showMaxMin && !isOrdinal) {
|
137
|
+
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
|
138
|
+
//.data(scale.domain())
|
139
|
+
.data([scale.domain()[0], scale.domain()[scale.domain().length - 1]]);
|
140
|
+
axisMaxMin.enter().append('g').attr('class', 'nv-axisMaxMin').append('text');
|
141
|
+
axisMaxMin.exit().remove();
|
142
|
+
axisMaxMin
|
143
|
+
.attr('transform', function(d,i) {
|
144
|
+
return 'translate(' + (scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0)) + ',0)'
|
145
|
+
})
|
146
|
+
.select('text')
|
147
|
+
.attr('dy', '.71em')
|
148
|
+
.attr('y', axis.tickPadding())
|
149
|
+
.attr('transform', function(d,i,j) { return 'rotate(' + rotateLabels + ' 0,0)' })
|
150
|
+
.attr('text-anchor', rotateLabels ? (rotateLabels%360 > 0 ? 'start' : 'end') : 'middle')
|
151
|
+
.text(function(d,i) {
|
152
|
+
var v = fmt(d);
|
153
|
+
return ('' + v).match('NaN') ? '' : v;
|
154
|
+
});
|
155
|
+
d3.transition(axisMaxMin)
|
156
|
+
.attr('transform', function(d,i) {
|
157
|
+
//return 'translate(' + scale.range()[i] + ',0)'
|
158
|
+
//return 'translate(' + scale(d) + ',0)'
|
159
|
+
return 'translate(' + (scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0)) + ',0)'
|
160
|
+
});
|
161
|
+
}
|
162
|
+
if (staggerLabels)
|
163
|
+
xTicks
|
164
|
+
.attr('transform', function(d,i) { return 'translate(0,' + (i % 2 == 0 ? '0' : '12') + ')' });
|
165
|
+
|
166
|
+
break;
|
167
|
+
case 'right':
|
168
|
+
axisLabel.enter().append('text').attr('class', 'nv-axislabel');
|
169
|
+
axisLabel
|
170
|
+
.attr('text-anchor', rotateYLabel ? 'middle' : 'begin')
|
171
|
+
.attr('transform', rotateYLabel ? 'rotate(90)' : '')
|
172
|
+
.attr('y', rotateYLabel ? (-Math.max(margin.right,width) + 12) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
|
173
|
+
.attr('x', rotateYLabel ? (scale.range()[0] / 2) : axis.tickPadding());
|
174
|
+
if (showMaxMin) {
|
175
|
+
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
|
176
|
+
.data(scale.domain());
|
177
|
+
axisMaxMin.enter().append('g').attr('class', 'nv-axisMaxMin').append('text')
|
178
|
+
.style('opacity', 0);
|
179
|
+
axisMaxMin.exit().remove();
|
180
|
+
axisMaxMin
|
181
|
+
.attr('transform', function(d,i) {
|
182
|
+
return 'translate(0,' + scale(d) + ')'
|
183
|
+
})
|
184
|
+
.select('text')
|
185
|
+
.attr('dy', '.32em')
|
186
|
+
.attr('y', 0)
|
187
|
+
.attr('x', axis.tickPadding())
|
188
|
+
.attr('text-anchor', 'start')
|
189
|
+
.text(function(d,i) {
|
190
|
+
var v = fmt(d);
|
191
|
+
return ('' + v).match('NaN') ? '' : v;
|
192
|
+
});
|
193
|
+
d3.transition(axisMaxMin)
|
194
|
+
.attr('transform', function(d,i) {
|
195
|
+
return 'translate(0,' + scale.range()[i] + ')'
|
196
|
+
})
|
197
|
+
.select('text')
|
198
|
+
.style('opacity', 1);
|
199
|
+
}
|
200
|
+
break;
|
201
|
+
case 'left':
|
202
|
+
/*
|
203
|
+
//For dynamically placing the label. Can be used with dynamically-sized chart axis margins
|
204
|
+
var yTicks = g.selectAll('g').select("text");
|
205
|
+
yTicks.each(function(d,i){
|
206
|
+
var labelPadding = this.getBBox().width + axis.tickPadding() + 16;
|
207
|
+
if(labelPadding > width) width = labelPadding;
|
208
|
+
});
|
209
|
+
*/
|
210
|
+
axisLabel.enter().append('text').attr('class', 'nv-axislabel');
|
211
|
+
axisLabel
|
212
|
+
.attr('text-anchor', rotateYLabel ? 'middle' : 'end')
|
213
|
+
.attr('transform', rotateYLabel ? 'rotate(-90)' : '')
|
214
|
+
.attr('y', rotateYLabel ? (-Math.max(margin.left,width) + 12) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
|
215
|
+
.attr('x', rotateYLabel ? (-scale.range()[0] / 2) : -axis.tickPadding());
|
216
|
+
if (showMaxMin) {
|
217
|
+
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
|
218
|
+
.data(scale.domain());
|
219
|
+
axisMaxMin.enter().append('g').attr('class', 'nv-axisMaxMin').append('text')
|
220
|
+
.style('opacity', 0);
|
221
|
+
axisMaxMin.exit().remove();
|
222
|
+
axisMaxMin
|
223
|
+
.attr('transform', function(d,i) {
|
224
|
+
return 'translate(0,' + scale0(d) + ')'
|
225
|
+
})
|
226
|
+
.select('text')
|
227
|
+
.attr('dy', '.32em')
|
228
|
+
.attr('y', 0)
|
229
|
+
.attr('x', -axis.tickPadding())
|
230
|
+
.attr('text-anchor', 'end')
|
231
|
+
.text(function(d,i) {
|
232
|
+
var v = fmt(d);
|
233
|
+
return ('' + v).match('NaN') ? '' : v;
|
234
|
+
});
|
235
|
+
d3.transition(axisMaxMin)
|
236
|
+
.attr('transform', function(d,i) {
|
237
|
+
return 'translate(0,' + scale.range()[i] + ')'
|
238
|
+
})
|
239
|
+
.select('text')
|
240
|
+
.style('opacity', 1);
|
241
|
+
}
|
242
|
+
break;
|
243
|
+
}
|
244
|
+
axisLabel
|
245
|
+
.text(function(d) { return d });
|
246
|
+
|
247
|
+
|
248
|
+
if (showMaxMin && (axis.orient() === 'left' || axis.orient() === 'right')) {
|
249
|
+
//check if max and min overlap other values, if so, hide the values that overlap
|
250
|
+
g.selectAll('g') // the g's wrapping each tick
|
251
|
+
.each(function(d,i) {
|
252
|
+
d3.select(this).select('text').attr('opacity', 1);
|
253
|
+
if (scale(d) < scale.range()[1] + 10 || scale(d) > scale.range()[0] - 10) { // 10 is assuming text height is 16... if d is 0, leave it!
|
254
|
+
if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL
|
255
|
+
d3.select(this).attr('opacity', 0);
|
256
|
+
|
257
|
+
d3.select(this).select('text').attr('opacity', 0); // Don't remove the ZERO line!!
|
258
|
+
}
|
259
|
+
});
|
260
|
+
|
261
|
+
//if Max and Min = 0 only show min, Issue #281
|
262
|
+
if (scale.domain()[0] == scale.domain()[1] && scale.domain()[0] == 0)
|
263
|
+
wrap.selectAll('g.nv-axisMaxMin')
|
264
|
+
.style('opacity', function(d,i) { return !i ? 1 : 0 });
|
265
|
+
|
266
|
+
}
|
267
|
+
|
268
|
+
if (showMaxMin && (axis.orient() === 'top' || axis.orient() === 'bottom')) {
|
269
|
+
var maxMinRange = [];
|
270
|
+
wrap.selectAll('g.nv-axisMaxMin')
|
271
|
+
.each(function(d,i) {
|
272
|
+
try {
|
273
|
+
if (i) // i== 1, max position
|
274
|
+
maxMinRange.push(scale(d) - this.getBBox().width - 4) //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case)
|
275
|
+
else // i==0, min position
|
276
|
+
maxMinRange.push(scale(d) + this.getBBox().width + 4)
|
277
|
+
}catch (err) {
|
278
|
+
if (i) // i== 1, max position
|
279
|
+
maxMinRange.push(scale(d) - 4) //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case)
|
280
|
+
else // i==0, min position
|
281
|
+
maxMinRange.push(scale(d) + 4)
|
282
|
+
}
|
283
|
+
});
|
284
|
+
g.selectAll('g') // the g's wrapping each tick
|
285
|
+
.each(function(d,i) {
|
286
|
+
if (scale(d) < maxMinRange[0] || scale(d) > maxMinRange[1]) {
|
287
|
+
if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL
|
288
|
+
d3.select(this).remove();
|
289
|
+
else
|
290
|
+
d3.select(this).select('text').remove(); // Don't remove the ZERO line!!
|
291
|
+
}
|
292
|
+
});
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
//highlight zero line ... Maybe should not be an option and should just be in CSS?
|
297
|
+
if (highlightZero)
|
298
|
+
g.selectAll('.tick')
|
299
|
+
.filter(function(d) { return !parseFloat(Math.round(d.__data__*100000)/1000000) && (d.__data__ !== undefined) }) //this is because sometimes the 0 tick is a very small fraction, TODO: think of cleaner technique
|
300
|
+
.classed('zero', true);
|
301
|
+
|
302
|
+
//store old scales for use in transitions on update
|
303
|
+
scale0 = scale.copy();
|
304
|
+
|
305
|
+
});
|
306
|
+
|
307
|
+
return chart;
|
308
|
+
}
|
309
|
+
|
310
|
+
|
311
|
+
//============================================================
|
312
|
+
// Expose Public Variables
|
313
|
+
//------------------------------------------------------------
|
314
|
+
|
315
|
+
// expose chart's sub-components
|
316
|
+
chart.axis = axis;
|
317
|
+
|
318
|
+
d3.rebind(chart, axis, 'orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat');
|
319
|
+
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands'); //these are also accessible by chart.scale(), but added common ones directly for ease of use
|
320
|
+
|
321
|
+
chart.margin = function(_) {
|
322
|
+
if(!arguments.length) return margin;
|
323
|
+
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
324
|
+
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
325
|
+
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
326
|
+
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
327
|
+
return chart;
|
328
|
+
}
|
329
|
+
|
330
|
+
chart.width = function(_) {
|
331
|
+
if (!arguments.length) return width;
|
332
|
+
width = _;
|
333
|
+
return chart;
|
334
|
+
};
|
335
|
+
|
336
|
+
chart.ticks = function(_) {
|
337
|
+
if (!arguments.length) return ticks;
|
338
|
+
ticks = _;
|
339
|
+
return chart;
|
340
|
+
};
|
341
|
+
|
342
|
+
chart.height = function(_) {
|
343
|
+
if (!arguments.length) return height;
|
344
|
+
height = _;
|
345
|
+
return chart;
|
346
|
+
};
|
347
|
+
|
348
|
+
chart.axisLabel = function(_) {
|
349
|
+
if (!arguments.length) return axisLabelText;
|
350
|
+
axisLabelText = _;
|
351
|
+
return chart;
|
352
|
+
}
|
353
|
+
|
354
|
+
chart.showMaxMin = function(_) {
|
355
|
+
if (!arguments.length) return showMaxMin;
|
356
|
+
showMaxMin = _;
|
357
|
+
return chart;
|
358
|
+
}
|
359
|
+
|
360
|
+
chart.highlightZero = function(_) {
|
361
|
+
if (!arguments.length) return highlightZero;
|
362
|
+
highlightZero = _;
|
363
|
+
return chart;
|
364
|
+
}
|
365
|
+
|
366
|
+
chart.scale = function(_) {
|
367
|
+
if (!arguments.length) return scale;
|
368
|
+
scale = _;
|
369
|
+
axis.scale(scale);
|
370
|
+
isOrdinal = typeof scale.rangeBands === 'function';
|
371
|
+
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands');
|
372
|
+
return chart;
|
373
|
+
}
|
374
|
+
|
375
|
+
chart.rotateYLabel = function(_) {
|
376
|
+
if(!arguments.length) return rotateYLabel;
|
377
|
+
rotateYLabel = _;
|
378
|
+
return chart;
|
379
|
+
}
|
380
|
+
|
381
|
+
chart.rotateLabels = function(_) {
|
382
|
+
if(!arguments.length) return rotateLabels;
|
383
|
+
rotateLabels = _;
|
384
|
+
return chart;
|
385
|
+
}
|
386
|
+
|
387
|
+
chart.staggerLabels = function(_) {
|
388
|
+
if (!arguments.length) return staggerLabels;
|
389
|
+
staggerLabels = _;
|
390
|
+
return chart;
|
391
|
+
};
|
392
|
+
|
393
|
+
|
394
|
+
//============================================================
|
395
|
+
|
396
|
+
|
397
|
+
return chart;
|
398
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
nv.models.chartName = function() {
|
3
|
+
|
4
|
+
//============================================================
|
5
|
+
// Public Variables with Default Settings
|
6
|
+
//------------------------------------------------------------
|
7
|
+
|
8
|
+
|
9
|
+
var margin = {top: 30, right: 10, bottom: 10, left: 10}
|
10
|
+
, width = 960
|
11
|
+
, height = 500
|
12
|
+
, color = nv.utils.getColor(d3.scale.category20c().range())
|
13
|
+
, dispatch = d3.dispatch('stateChange', 'changeState')
|
14
|
+
;
|
15
|
+
|
16
|
+
//============================================================
|
17
|
+
|
18
|
+
|
19
|
+
//============================================================
|
20
|
+
// Private Variables
|
21
|
+
//------------------------------------------------------------
|
22
|
+
|
23
|
+
|
24
|
+
//============================================================
|
25
|
+
|
26
|
+
|
27
|
+
function chart(selection) {
|
28
|
+
selection.each(function(data) {
|
29
|
+
var availableWidth = width - margin.left - margin.right,
|
30
|
+
availableHeight = height - margin.top - margin.bottom,
|
31
|
+
container = d3.select(this);
|
32
|
+
|
33
|
+
|
34
|
+
//------------------------------------------------------------
|
35
|
+
// Setup Scales
|
36
|
+
|
37
|
+
|
38
|
+
//------------------------------------------------------------
|
39
|
+
|
40
|
+
|
41
|
+
//------------------------------------------------------------
|
42
|
+
// Setup containers and skeleton of chart
|
43
|
+
|
44
|
+
var wrap = container.selectAll('g.nv-wrap.nv-chartName').data([data]);
|
45
|
+
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-chartName');
|
46
|
+
var gEnter = wrapEnter.append('g');
|
47
|
+
var g = wrap.select('g')
|
48
|
+
|
49
|
+
gEnter.append('g').attr('class', 'nv-mainWrap');
|
50
|
+
|
51
|
+
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
52
|
+
|
53
|
+
//------------------------------------------------------------
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
});
|
59
|
+
|
60
|
+
return chart;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
//============================================================
|
65
|
+
// Expose Public Variables
|
66
|
+
//------------------------------------------------------------
|
67
|
+
|
68
|
+
|
69
|
+
chart.dispatch = dispatch;
|
70
|
+
|
71
|
+
chart.margin = function(_) {
|
72
|
+
if (!arguments.length) return margin;
|
73
|
+
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
|
74
|
+
margin.right = typeof _.right != 'undefined' ? _.right : margin.right;
|
75
|
+
margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom;
|
76
|
+
margin.left = typeof _.left != 'undefined' ? _.left : margin.left;
|
77
|
+
return chart;
|
78
|
+
};
|
79
|
+
|
80
|
+
chart.width = function(_) {
|
81
|
+
if (!arguments.length) return width;
|
82
|
+
width = _;
|
83
|
+
return chart;
|
84
|
+
};
|
85
|
+
|
86
|
+
chart.height = function(_) {
|
87
|
+
if (!arguments.length) return height;
|
88
|
+
height = _;
|
89
|
+
return chart;
|
90
|
+
};
|
91
|
+
|
92
|
+
chart.color = function(_) {
|
93
|
+
if (!arguments.length) return color;
|
94
|
+
color = nv.utils.getColor(_)
|
95
|
+
return chart;
|
96
|
+
};
|
97
|
+
|
98
|
+
//============================================================
|
99
|
+
|
100
|
+
|
101
|
+
return chart;
|
102
|
+
}
|