Skip to content

Commit

Permalink
Support sequence names in chart
Browse files Browse the repository at this point in the history
  • Loading branch information
g21589 committed Dec 2, 2015
1 parent 2bb04b3 commit 852b5ac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
34 changes: 22 additions & 12 deletions js/pptx2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,61 +168,71 @@ function processSingleMsg(d) {
var chart = null;
switch (chartType) {
case "lineChart":
/*
for (var i=0; i<chartData.length; i++) {
var arr = [];
for (var j=0; j<chartData[i].length; j++) {
arr.push({x: j, y: chartData[i][j]});
}
data.push({key: 'data' + (i + 1), values: arr});
}
*/
data = chartData;
chart = nv.models.lineChart()
.useInteractiveGuideline(true);
chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
//chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
//chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
break;
case "barChart":
/*
for (var i=0; i<chartData.length; i++) {
var arr = [];
for (var j=0; j<chartData[i].length; j++) {
arr.push({x: j, y: chartData[i][j]});
}
data.push({key: 'data' + (i + 1), values: arr});
}
*/
data = chartData;
chart = nv.models.multiBarChart();
chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
//chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
//chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
break;
case "pieChart":
case "pie3DChart":
for (var j=0; j<chartData[0].length; j++) {
data.push({label: "Item " + (j + 1), value: chartData[0][j]});
}
chart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value });
data = chartData[0].values;
chart = nv.models.pieChart();
//.x(function(d) { return d.x })
//.y(function(d) { return d.y });
break;
case "areaChart":
/*
for (var i=0; i<chartData.length; i++) {
var arr = [];
for (var j=0; j<chartData[i].length; j++) {
arr.push({x: j, y: chartData[i][j]});
}
data.push({key: 'data' + (i + 1), values: arr});
}
*/
data = chartData;
chart = nv.models.stackedAreaChart()
.clipEdge(true)
.useInteractiveGuideline(true);
chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
//chart.xAxis.axisLabel('X').tickFormat(d3.format(',r'));
//chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
break;
case "scatterChart":

for (var i=0; i<chartData.length; i++) {
var arr = [];
for (var j=0; j<chartData[i].length; j++) {
arr.push({x: j, y: chartData[i][j]});
}
data.push({key: 'data' + (i + 1), values: arr});
}

//data = chartData;
chart = nv.models.scatterChart()
.showDistX(true)
.showDistY(true)
Expand Down
30 changes: 22 additions & 8 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,25 +1439,39 @@ function extractChartData(serNode) {

if (serNode["c:xVal"] !== undefined) {
var dataRow = new Array();
eachElement(serNode["c:xVal"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode) {
eachElement(serNode["c:xVal"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode, index) {
dataRow.push(parseFloat(innerNode["c:v"]));
return "";
});
dataMat.push(dataRow);
dataRow = new Array();
eachElement(serNode["c:yVal"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode) {
eachElement(serNode["c:yVal"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode, index) {
dataRow.push(parseFloat(innerNode["c:v"]));
return "";
});
dataMat.push(dataRow);
} else {
eachElement(serNode, function(innerNode) {
eachElement(serNode, function(innerNode, index) {
var dataRow = new Array();
eachElement(innerNode["c:val"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode) {
dataRow.push(parseFloat(innerNode["c:v"]));
var colName = getTextByPathList(innerNode, ["c:tx", "c:strRef", "c:strCache", "c:pt", "c:v"]) || index;

// Bug: Category string must be quantifed to display on chart
/*
var rowNames = {};
// category
eachElement(innerNode["c:cat"]["c:strRef"]["c:strCache"]["c:pt"], function(innerNode, index) {
rowNames[innerNode["attrs"]["idx"]] = innerNode["c:v"];
return "";
});
*/

// value
eachElement(innerNode["c:val"]["c:numRef"]["c:numCache"]["c:pt"], function(innerNode, index) {
//dataRow.push({x: rowNames[innerNode["attrs"]["idx"]], y: parseFloat(innerNode["c:v"])});
dataRow.push({x: innerNode["attrs"]["idx"], y: parseFloat(innerNode["c:v"])});
return "";
});
dataMat.push(dataRow);
dataMat.push({key: colName, values: dataRow});
return "";
});
}
Expand Down Expand Up @@ -1514,10 +1528,10 @@ function eachElement(node, doFunction) {
if (node.constructor === Array) {
var l = node.length;
for (var i=0; i<l; i++) {
result += doFunction(node[i]);
result += doFunction(node[i], i);
}
} else {
result += doFunction(node);
result += doFunction(node, 0);
}
return result;
}
Expand Down

0 comments on commit 852b5ac

Please sign in to comment.