rvspt / D3DynamicTreeLayout-QS

Qlik Sense extension that displays an Hierarchical Tree using D3, with user interaction
MIT License
10 stars 9 forks source link

Error with Selections #8

Closed fcorivasd closed 6 years ago

fcorivasd commented 6 years ago

Hi,

First of all great extension!. Very useful and make hierarchy looks good.

I have an issue when I try to select a value in the hierarchy. The app only returns an error and I can't select a value and make a drill down of the information (invalid parameters). I search your javascript code and I think that the error comes in the next line:

app_this.selectValues(3,testz,false);

Another thing, I make the same move that another user post with the 'NodeName' (#Issue Name: Does not render in Sense Sept 2017) to make this extension work in Qlik Sense. (I use the November 2017).

Best Regards

Francisco

getsemacni commented 6 years ago

Hi Francisco, I have the same problem than you, and as you said I had to modify the js code to the extension work (I´m talking about Node name problem).

Did you solve the problem about the invalid parameters when you select any label in the tree?

Thanks!

Gabrz commented 6 years ago

Hi, I have a solution for this.

you have to make some changes in d3dynamictreelayout-qs.js:

1) On lines 83, 102, 126, 149 : pass on 2 extra variables(app and layout) to function launchTree : launchTree(app,layout,reply, etc...

2) on line 158 : add 2 parameters(app and layout) to the function declaration : function launchTree(app,layout,treeData, ... etc...

3) On line 230 : pass on the 2 variables to function renderChart : renderChart(app,layout,tree, ... etc...

4) on line 249 : add the parameters to function declaration : function renderChart(app,layout,planted_tree, .... etc ...

5) on line 706 : replace code : app_this.selectValues(3,testz,false); with app.field(layout.properties.treeStructure.nodeName).clear(); // optional, but select function made more sense to me app.field(layout.properties.treeStructure.nodeName).select(testz, true, true);

Not sure if this is the most elegant solution, I've been programming js for 2 weeks now. But for me this works.

getsemacni commented 6 years ago

Thanks! It Works :D!

kevinholden commented 6 years ago

I agree this is great app and looking forward to using it. Is there any explaination for how we should load the Hierarchy data so that you can filter and the tree will regenerate? I have tried Hierarchy and Hierarchybelongsto but still don't have any luck so seeing the data load editor details might be helpful.

thanks.

Gabrz commented 6 years ago

Hi Kevin, Here is an example of a load:

[InlEmp]:
load column1 as inlEmpID
,    column2 as inlEmpName
,    column3 as inlMngID
Inline [
column1, column2, column3
1,'Frank Roll',4
2,'Erik Presley',
3,'Rob Carsson',4
4,'Joan Callins',2
5,'Ingrid Hendrix',4
6,'Lennart Skoglund',4
7,'Tom Lindwall',4
8,'Leif Shine',2
9,'Helen Brolin',4
19,'David Lawson',8
20,'John Cleaves',8
21,'Miro Takako',8
22,'Binh Protzmann',8
23,'Cezar Sandu',19
24,'Judy Crawford',19
27,'Mario Kregler',22
29,'Sven Stevenson',22
30,'Ira Baumel',22
32,'Rolf Wesenlund',20
33,'Ann Lindquist',20
36,'Jacques Clouseau',20
37,'Jerry Tessel',21
38,'John Applegate',21
39,'Marcus Salvatori',21
41,'Sunil Gupta',21
42,'Östen Ärlig',3
43,'Bob Park',7
44,'Andrew Kent',7
45,'Joe Cheng',5
46,'Kaya Alpan',5
47,'Michelle Tyson',6
48,'Ricardo Gucci',6
51,'Luke Lanza',4
52,'Mike Ashkenaz',42
161,'Stefan Lind',27
];

[Emp]:
Hierarchy(EmpID, MngID, EmpName, ParentName, NodeName, PathName, '/', Depth)
LOAD
    inlEmpID as EmpID,
    inlEmpName as EmpName,
    inlMngID as MngID
resident [InlEmp]
;

drop table [InlEmp];

You can now use Empname as Node Name, Depth as Node Depth, EmpID as Node ID and MngID as Parent Node ID

Gabrz commented 6 years ago

I had this other problem with the selections, it occurs if you have a dataset where the nodeName is not Unique. Then these 2 records have the same qElemNumber and are both selected and can mess up your Tree (especially when these records have a different depth).

I've fixed this by selecting the qElemNumber belonging to NodeID (instead of NodeName)

var child = new node(node_id+iterator,
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][1].qText, //element_id
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][2].qText, //parent_id
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][3].qText, //name
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][4].qText, //measure
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][0].qText, //depth
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][**3**].qElemNumber, //name's qElement
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][5].qText, //strokeColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][6].qText, //parentFillColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][7].qText, //childFillColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][8].qText, //linkStrokeColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][9].qText) //nodeFontColor
var child = new node(node_id+iterator,
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][1].qText, //element_id
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][2].qText, //parent_id
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][3].qText, //name
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][4].qText, //measure
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][0].qText, //depth
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][**1**].qElemNumber, //element_id qElement
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][5].qText, //strokeColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][6].qText, //parentFillColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][7].qText, //childFillColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][8].qText, //linkStrokeColor
     treeData.qHyperCube.qDataPages[page_nr].qMatrix[row_nr][9].qText) //nodeFontColor

You then also need to change the field you make the selection on app.field(layout.properties.treeStructure.nodeID).select(testz, true, true);

rvspt commented 6 years ago

Updated the extension. v1.3.1 should cover the issue.