Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data formatting and updating #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions js/radialBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ function radialBarChart() {
// Scales & other useful things
var numBars = null;
var barScale = null;
var keys = null;
var keys = [];
var labelRadius = 0;
var axis = d3.svg.axis();


function init(d) {
barScale = d3.scale.linear().domain(domain).range([0, barHeight]);

keys = d3.map(d[0].data).keys();
if (Array.isArray(d[0].data)) {
for (var i = 0; i < d[0].data.length; ++i) {
keys.push(d[0].data[i][0]);
}
} else {
keys = d3.map(d[0].data).keys();
}
numBars = keys.length;

// Radius of the key labels
Expand Down Expand Up @@ -72,7 +79,7 @@ function radialBarChart() {

// Axis
var axisScale = d3.scale.linear().domain(domain).range([0, -barHeight]);
var axis = d3.svg.axis().scale(axisScale).orient('right');
axis.scale(axisScale).orient('right');
if(tickValues)
axis.tickValues(tickValues);
g.append('g')
Expand Down Expand Up @@ -108,7 +115,6 @@ function radialBarChart() {

function chart(selection) {
selection.each(function(d) {

init(d);

if(reverseLayerOrder)
Expand Down Expand Up @@ -142,8 +148,17 @@ function radialBarChart() {
var segments = layers
.selectAll('path')
.data(function(d) {
var m = d3.map(d.data);
return m.values();
var m = d3.map(d.data),
mValues = m.values(),
mArr = [];
if (Array.isArray(mValues)) {
for (var i = 0; i < mValues.length; ++i) {
mArr.push(mValues[i][1]);
}
} else {
mArr = mValues;
}
return mArr;
});

segments
Expand All @@ -159,24 +174,35 @@ function radialBarChart() {
segments
.transition()
.duration(transitionDuration)
.attr('d', d3.svg.arc().innerRadius(0).outerRadius(or).startAngle(sa).endAngle(ea))
.attr('d', d3.svg.arc().innerRadius(0).outerRadius(or).startAngle(sa).endAngle(ea));

if(!update)
if(!update) {
renderOverlays(this);
} else {
var axisScale = d3.scale.linear().domain(domain).range([0, -barHeight]);
axis.scale(axisScale)
.orient('right');
if (tickValues)
axis.tickValues(tickValues);
d3.select('.radial .axis')
.transition()
.duration(2000)
.call(axis);
}
});

}

/* Arc functions */
or = function(d, i) {
return barScale(d);
}
};
sa = function(d, i) {
return (i * 2 * Math.PI) / numBars;
}
};
ea = function(d, i) {
return ((i + 1) * 2 * Math.PI) / numBars;
}
};

/* Configuration getters/setters */
chart.margin = function(_) {
Expand Down Expand Up @@ -240,4 +266,4 @@ function radialBarChart() {
};

return chart;
}
}