Merge branch 'development' of https://github.com/novus/nvd3 into development

master
Tyler Wolf 11 years ago
commit 396de28528

@ -9,7 +9,7 @@
"Frank Shao"
],
"description": "Re-usable charts and chart components for d3.",
"main": "nv.d3.js",
"main": ["nv.d3.js", "src/nv.d3.css"],
"keywords": [
"d3",
"visualization",
@ -18,15 +18,15 @@
],
"license": "Apache License, v2.0",
"dependencies": {
d3: "3.3.5"
}
"d3": "3.3.5"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"src",
"src/models/*",
"src/*.js",
"lib",
"examples",
"deprecated"

3833
nv.d3.js

File diff suppressed because it is too large Load Diff

4
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -2,7 +2,7 @@
var nv = window.nv || {};
nv.version = '1.1.11b';
nv.version = '1.1.13b';
nv.dev = true //set false when in production
window.nv = nv;

@ -57,7 +57,7 @@ nv.models.stackedArea = function() {
//------------------------------------------------------------
var dataRaw = data;
// Injecting point index into each point because d3.layout.stack().out does not give index
data = data.map(function(aseries, i) {
aseries.seriesIndex = i;
@ -209,6 +209,29 @@ nv.models.stackedArea = function() {
});
//============================================================
//Special offset functions
chart.d3_stackedOffset_stackPercent = function(stackData) {
var n = stackData.length, //How many series
m = stackData[0].length, //how many points per series
k = 1 / n,
i,
j,
o,
y0 = [];
for (j = 0; j < m; ++j) { //Looping through all points
for (i = 0, o = 0; i < dataRaw.length; i++) //looping through series'
o += getY(dataRaw[i].values[j]) //total value of all points at a certian point in time.
if (o) for (i = 0; i < n; i++)
stackData[i][j][1] /= o;
else
for (i = 0; i < n; i++)
stackData[i][j][1] = k;
}
for (j = 0; j < m; ++j) y0[j] = 0;
return y0;
};
});
@ -234,7 +257,6 @@ nv.models.stackedArea = function() {
//============================================================
//============================================================
// Global getters and setters
//------------------------------------------------------------
@ -326,6 +348,10 @@ nv.models.stackedArea = function() {
chart.offset('expand');
chart.order('default');
break;
case 'stack_percent':
chart.offset(chart.d3_stackedOffset_stackPercent);
chart.order('default');
break;
}
return chart;

@ -37,6 +37,7 @@ nv.models.stackedAreaChart = function() {
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, controlWidth = 250
, cData = ['Stacked','Stream','Expanded']
, controlLabels = {}
, transitionDuration = 250
;
@ -175,15 +176,36 @@ nv.models.stackedAreaChart = function() {
if (showControls) {
var controlsData = [
{ key: 'Stacked', disabled: stacked.offset() != 'zero' },
{ key: 'Stream', disabled: stacked.offset() != 'wiggle' },
{ key: 'Expanded', disabled: stacked.offset() != 'expand' }
{
key: controlLabels.stacked || 'Stacked',
metaKey: 'Stacked',
disabled: stacked.style() != 'stack',
style: 'stack'
},
{
key: controlLabels.stream || 'Stream',
metaKey: 'Stream',
disabled: stacked.style() != 'stream',
style: 'stream'
},
{
key: controlLabels.expanded || 'Expanded',
metaKey: 'Expanded',
disabled: stacked.style() != 'expand',
style: 'expand'
},
{
key: controlLabels.stack_percent || 'Stack %',
metaKey: 'Stack_Percent',
disabled: stacked.style() != 'stack_percent',
style: 'stack_percent'
}
];
controlWidth = (cData.length/3) * 260;
controlsData = controlsData.filter(function(d) {
return cData.indexOf(d.key) > -1;
return cData.indexOf(d.metaKey) !== -1;
})
controls
@ -265,7 +287,8 @@ nv.models.stackedAreaChart = function() {
.scale(y)
.ticks(stacked.offset() == 'wiggle' ? 0 : availableHeight / 36)
.tickSize(-availableWidth, 0)
.setTickFormat(stacked.offset() == 'expand' ? d3.format('%') : yAxisTickFormat);
.setTickFormat( (stacked.style() == 'expand' || stacked.style() == 'stack_percent')
? d3.format('%') : yAxisTickFormat);
g.select('.nv-y.nv-axis')
.transition().duration(0)
@ -312,17 +335,8 @@ nv.models.stackedAreaChart = function() {
});
d.disabled = false;
switch (d.key) {
case 'Stacked':
stacked.style('stack');
break;
case 'Stream':
stacked.style('stream');
break;
case 'Expanded':
stacked.style('expand');
break;
}
stacked.style(d.style);
state.style = stacked.style();
dispatch.stateChange(state);
@ -595,6 +609,13 @@ nv.models.stackedAreaChart = function() {
return chart;
};
chart.controlLabels = function(_) {
if (!arguments.length) return controlLabels;
if (typeof _ !== 'object') return controlLabels;
controlLabels = _;
return chart;
};
yAxis.setTickFormat = yAxis.tickFormat;
yAxis.tickFormat = function(_) {

Loading…
Cancel
Save