Skip to content

Commit

Permalink
Support xAxis labels in chart
Browse files Browse the repository at this point in the history
  • Loading branch information
g21589 committed Dec 3, 2015
1 parent 852b5ac commit 0ec6ca3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 47 deletions.
38 changes: 3 additions & 35 deletions js/pptx2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,59 +168,27 @@ 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.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
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.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
break;
case "pieChart":
case "pie3DChart":
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.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
break;
case "scatterChart":

Expand Down
23 changes: 11 additions & 12 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1454,24 +1454,23 @@ function extractChartData(serNode) {
eachElement(serNode, function(innerNode, index) {
var dataRow = new Array();
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
/*

// Category
var rowNames = {};
// category
eachElement(innerNode["c:cat"]["c:strRef"]["c:strCache"]["c:pt"], function(innerNode, index) {
rowNames[innerNode["attrs"]["idx"]] = innerNode["c:v"];
return "";
});
*/
if (getTextByPathList(innerNode, ["c:cat", "c:strRef", "c:strCache", "c:pt"]) !== undefined) {
eachElement(innerNode["c:cat"]["c:strRef"]["c:strCache"]["c:pt"], function(innerNode, index) {
rowNames[innerNode["attrs"]["idx"]] = innerNode["c:v"];
return "";
});
}

// value
// 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({key: colName, values: dataRow});

dataMat.push({key: colName, values: dataRow, xlabels: rowNames});
return "";
});
}
Expand Down

0 comments on commit 0ec6ca3

Please sign in to comment.