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

If a sub-group value is not present in the first data point of the first main category, it isn't displayed at all #24

Open
apippin opened this issue Jun 10, 2020 · 1 comment

Comments

@apippin
Copy link

apippin commented Jun 10, 2020

When using the latest version of this plugin with Grafana v7.0.1, we've noticed a bug in how the sub-group values are shown. If a sub-group value is not present in the first data point of the first main category column, but is present on subsequent main category columns, it won't be shown on any of them.

Take this SQL:
CONCAT(MONTH(sampled),"/",DAY(sampled)) as date,
recipe,
ber,
sampled
ORDER BY sampled

Which generates these values:
image

Generates this plot:
image

Note how it is missing the GENZ_ALL_IBIST_OTXEQ sub-group values. However, if we change the time range such that the first main category column has a value for that sub-group (starting at 6/4 vs 6/3), it shows up as expected for the rest of the main category columns:

image

@apippin
Copy link
Author

apippin commented Jun 10, 2020

I tried to root cause the issue, but couldn't track it down. I did create a simple patch to workaround the issue. The patch looks like this, and works great:

diff --git a/dist/ctrl.js b/dist/ctrl.js
index 9da3a76..9bb34c5 100644
--- a/dist/ctrl.js
+++ b/dist/ctrl.js
@@ -149,6 +149,29 @@ System.register(['app/plugins/sdk', 'lodash', 'app/core/utils/kbn', 'app/core/ti
                     key: 'onDataReceived',
                     value: function onDataReceived(dataList) {
                         if (dataList && dataList.length) {
+                            // Workaround bug where bars are missing if not present in first data point
+                            if (dataList[0].rows && dataList[0].rows.length) { 
+                                // Make a set of all the main categories used in any data point
+                                let mySet = new Set()
+                                var firstCategory = dataList[0].rows[0][0];
+                                dataList[0].rows.forEach((element) => {
+                                        mySet.add(element[1]);
+                                })
+                                // Remove the main categories already part of the first data point
+                                dataList[0].rows.forEach((element) => {
+                                        if (firstCategory == element[0]) {
+                                                mySet.delete(element[1]);
+                                        };
+                                })
+                                // Add the main categories missing from the first data point to it with data=0
+                                for (let item of mySet) {
+                                        var row = Array.from(dataList[0].rows[0]);
+                                        row[1] = item;
+                                        row[2] = 0;
+                                        dataList[0].rows.push(row);
+                                };
+                            }
+
                             var o = _.groupBy(dataList[0].rows, function (e) {
                                 return e[0];
                             });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant