Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Multiple chart fixes #166

Merged
merged 8 commits into from

2 participants

@nurkiewicz

Incorrect output when multiple header columns

If more then one level or hierarchy is used for columns, chart output is incorrect. Turns out only the first row of top-level hierarchy was visible. Take the following report on Sales cube as an example:

report

Before:

Only Q1 is shown.

before

After:

All rows are shown:

after

Looks like the same bug (if it works as expected, it's waaay to confusing) is present when multiple header rows are selected, but I didn't manage to fix it.

[NN] counter optional

Previously every label on X-axis had a counter, e.g. "Virginia [1] | Oregon [2], ... Now it's added only if there are duplicated labels on the chart.

Stacked bar empty when some data unavailable

Sometimes when some cells in report are empty, stacked bar doesn't display anything. It's fixed by implicitly placing 0 in such cells.

For example in Sales cube put Month in columns and City (from Customer dimension). Stacked bar is invisible without this fix.

More colors

Increased the number of distinct colors from 5 to 11 (based on default jqPlot pallet).

@pstoellberger pstoellberger merged commit af3e316 into from
@pstoellberger
Collaborator

there still is an issue if you have several items on the columns axis, can you fix that as well?

thanks for the pull request!

@pstoellberger
Collaborator

and as i said in the other pull request, doing both in 1 pass would be great if possible

@nurkiewicz

I was aware of the problem with multiple items in columns. But since it wasn't an issue in my project, I left it. I already feel I might have introduced some new subtle bugs, so I am a bit worried and reluctant to work on that code further before it stabilizes and proves to be correct.

I'll try to get rid of the second iteration/pass though.

@pstoellberger
Collaborator

once you got rid of the second iteration i can take a look as well, i think it can be an easy fix to do it for the columns as well

what bugs are you referring to though?

@nurkiewicz

No bugs in particular, I tested my changes manually with several charts on demo and my own cubes and they all seem to work. So I hope everything is in better shape than it used to be.

@nurkiewicz nurkiewicz deleted the branch
@pstoellberger
Collaborator

i have made the row label a one-pass algorithm and also implemented the fix for the column labels

would be great if you could check out the latest version and give feedback!
thanks for pushing this. i wanted to do that for ages

@nurkiewicz

Thank you for fixing column labels. I confirm, now chart works properly when multiple dimensions are applied on rows (my fix) and column (yours). Thanks again!

@pstoellberger
Collaborator

btw i noticed that your chart export doesnt work in chrome for some reason

@nurkiewicz

Indeed, sorry for that. I mentioned about it in original pull request. Unfortunately I couldn't find where the problem lies :-(.

@pstoellberger
Collaborator

ah didnt see that. no worries, i will take a look

@pstoellberger
Collaborator

if you can have a look whats wrong with the pdf export that would be great ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 10, 2013
  1. @nurkiewicz
  2. @nurkiewicz

    * Fixing charts when rows using multiple levels of the same hierarchy

    nurkiewicz authored
    * Labels from all levels are now joined, e.g. 'Feb/Q1/2012' instead of 'Feb'
  3. @nurkiewicz
  4. @nurkiewicz
  5. @nurkiewicz
  6. @nurkiewicz
  7. @nurkiewicz

    Fixing stacked bar chart by implicitly changing empty strings to 0

    nurkiewicz authored
    Without it empty strings caused maximum value in stacked bar chart to be incorrectly computed (NaN?) and nothing was displayed
  8. @nurkiewicz
This page is out of date. Refresh to see the latest.
Showing with 63 additions and 31 deletions.
  1. +2 −0  .gitignore
  2. +61 −31 js/saiku/plugins/Chart/plugin.js
View
2  .gitignore
@@ -4,3 +4,5 @@ target/
node_modules/
*.DS_Store
.*.swp
+*.iml
+.idea
View
92 js/saiku/plugins/Chart/plugin.js
@@ -47,15 +47,15 @@ var Chart = Backbone.View.extend({
"</div>").css({
'padding-bottom': '10px'
});
- this.nav.find('a').css({
- color: '#666',
- 'margin-right': '5px',
- 'text-decoration': 'none',
- 'border': '1px solid #ccc',
- padding: '5px'
+ this.nav.find('a').css({
+ color: '#666',
+ 'margin-right': '5px',
+ 'text-decoration': 'none',
+ 'border': '1px solid #ccc',
+ padding: '5px'
})
.click(this.setOptions);
-
+
// Append chart to workspace
$(this.workspace.el).find('.workspace_results')
.prepend($(this.el).hide())
@@ -141,7 +141,7 @@ var Chart = Backbone.View.extend({
legend: true,
legendPosition:"top",
legendAlign: "right",
- colors: ["#B40010", "#CCC8B4", "#DDB965", "#72839D", "#1D2D40"],
+ colors: ["#4bb2c5", "#c5b47f", "#EAA228", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"],
type: 'BarChart'
}, this.options);
@@ -204,50 +204,80 @@ var Chart = Backbone.View.extend({
this.data.metadata = [];
this.data.height = 0;
this.data.width = 0;
-
- if (args.data.cellset && args.data.cellset.length > 0) {
+
+ function makeSureUniqueLabels(resultset) {
+ function appendUniqueCounter() {
+ for(var i = 0; i < resultset.length; ++i) {
+ var record = resultset[i];
+ record[0] = record[0] + ' [' + (i + 1) + ']';
+ }
+ }
+
+ var labelsSet = {};
+ for(var i = 0; i < resultset.length; ++i) {
+ var record = resultset[i];
+ var label = record[0];
+ if(labelsSet[label]) {
+ appendUniqueCounter();
+ return;
+ } else {
+ labelsSet[label] = true;
+ }
+ }
+ }
+
+ var cellset = args.data.cellset;
+ if (cellset && cellset.length > 0) {
var lowest_level = 0;
- for (var row = 0; row < args.data.cellset.length; row++) {
- if (args.data.cellset[row][0].type == "ROW_HEADER_HEADER") {
+ for (var row = 0; row < cellset.length; row++) {
+ if (cellset[row][0].type == "ROW_HEADER_HEADER") {
this.data.metadata = [];
- for (var field = 0; field < args.data.cellset[row].length; field++) {
- if (args.data.cellset[row][field].type == "ROW_HEADER_HEADER") {
+ for (var field = 0; field < cellset[row].length; field++) {
+ if (cellset[row][field].type == "ROW_HEADER_HEADER") {
this.data.metadata.shift();
lowest_level = field;
}
this.data.metadata.push({
colIndex: field,
- colType: typeof(args.data.cellset[row + 1][field].value) !== "number" &&
- isNaN(args.data.cellset[row + 1][field].value
+ colType: typeof(cellset[row + 1][field].value) !== "number" &&
+ isNaN(cellset[row + 1][field].value
.replace(/[^a-zA-Z 0-9.]+/g,'')) ? "String" : "Numeric",
- colName: args.data.cellset[row][field].value
+ colName: cellset[row][field].value
});
}
- } else if (args.data.cellset[row][0].value !== "null" && args.data.cellset[row][0].value !== "") {
+ } else if (cellset[row][0].value !== "") {
var record = [];
- this.data.width = args.data.cellset[row].length;
- for (var col = lowest_level; col < args.data.cellset[row].length; col++) {
- var value = args.data.cellset[row][col].value;
- // check if the resultset contains the raw value, if not try to parse the given value
- if (args.data.cellset[row][col].properties.raw && args.data.cellset[row][col].properties.raw !== "null")
- {
- value = parseFloat(args.data.cellset[row][col].properties.raw);
- } else if (typeof(args.data.cellset[row][col].value) !== "number" &&
- parseFloat(args.data.cellset[row][col].value.replace(/[^a-zA-Z 0-9.]+/g,'')))
- {
- value = parseFloat(args.data.cellset[row][col].value.replace(/[^a-zA-Z 0-9.]+/g,''));
+ this.data.width = cellset[row].length;
+ var label = [];
+ for (var labelCol = lowest_level; labelCol >= 0; labelCol--) {
+ var lastKnownUpperLevelRow = row;
+ while(cellset[lastKnownUpperLevelRow] && cellset[lastKnownUpperLevelRow][labelCol].value === 'null') {
+ --lastKnownUpperLevelRow;
}
- if (col == lowest_level) {
- value += " [" + row + "]";
+ if(cellset[lastKnownUpperLevelRow]) {
+ label.push(cellset[lastKnownUpperLevelRow][labelCol].value);
+ }
+ }
+ record.push(label.join('/'));
+ for (var col = lowest_level + 1; col < cellset[row].length; col++) {
+ var cell = cellset[row][col];
+ var value = cell.value || 0;
+ // check if the resultset contains the raw value, if not try to parse the given value
+ var raw = cell.properties.raw;
+ if (raw && raw !== "null") {
+ value = parseFloat(raw);
+ } else if (typeof(cell.value) !== "number" && parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g,''))) {
+ value = parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g,''));
}
record.push(value);
}
this.data.resultset.push(record);
}
}
+ makeSureUniqueLabels(this.data.resultset);
this.data.height = this.data.resultset.length;
this.render();
} else {
Something went wrong with that request. Please try again.