Ag-grid tree data - trying to expand specific parent node but the node is undefined - ag-grid

I have tree data in ag-grid that is coming in like this:
[{"colorName": "Magenta", parentColor: "Red", "namePath": ["Red", "Magenta"]},
{"colorName": "Pink", parentColor: "Red", "namePath": ["Red", "Pink"]},
{"colorName": "Cerulean", parentColor: "Blue", "namePath": ["Blue", "Cerulean"]},
{"colorName": "Goldenrod", parentColor: "Yellow", "namePath": ["Yellow", "Goldenrod"]}]
The ag-grid ends up with Red, Blue, and Yellow as parent rows, which you can click to expand to reveal the child rows, like Magenta and Pink for Red. Now I am trying to automatically expand a specific parent row upon load. For example, say a user's preferred color is Red, so when the ag-grid loads, I want the Red parent group to be already expanded.
The problem is I have trouble identifying the node programmatically. I tried going through the node data with forEachNode, like:
onFirstDataRendered(params) {
this.gridApi.forEachNode((node) => {
if (node != undefined && node.data != undefined) {
console.log("node: " + JSON.stringify(node.data);
}
});
}
I only get node data from the child rows, like Magenta or Pink. The nodes for the parent rows are undefined. I thought maybe I could access the parent row by going up a row index from the first child row, but I'm unable to figure out how to traverse up a row index and use it to expand the row.

I figured it out. Instead of using node.data, I used node.key. Now I can see the parent row name.

Related

Editing the labels on a flow chart with DiagrammeR

I’m trying to make a flow chart with R. Attached is the chart I made in word (which is what I'm trying to get to). I don’t want to copy and paste it, I want to actually make it in R. I’ve been using DiagrammeR to try, and the code is below.
I'm having the main trouble with the labels, how to change some parts to bold and make them a nice distance away from the nodes. I've added in the blue and pink boxes in my code, which I like.
Code:
library(DiagrammeR)
graph <- "
digraph boxes_and_circles{
# Add node statements
# This states that all following nodes have a box shape
node[
shape=box,
style=rounded,
fontname=Helvetica,
penwidth=2,
fixedsize = true
width=4
]
# Connect the nodes with edge statements
edge[
arrowhead = normal,
arrowtail = none
]
# These are the main nodes at top of graph
'##1'->'##2'
[label=' Cleaning Function:
Text to lower case
Contractions expanded
Numbers replaced
Abbreviations expanded (Qdap)
NA’s ignored
Kerns replaced
White space removed', fontname=Helvetica, fontsize=20, fontweight=bold]
'##2'->'##3'
'##2'->'##4'
# Make subnodes with boxes around for tidy text grouping
# graph, node, and edge definitions
graph [
compound = true,
nodesep = 1,
ranksep = 0.25,
color = pink
]
# subgraph for tidy text, direct the flow
subgraph cluster0 {
'##3'->'##5'
[label=' -Tokenization
-Lemetisation
-Stop words removed', fontname=Helvetica, fontsize=20, fontweight=bold]
}
# Make subnodes with boxes around for Dictionary grouping
# graph, node, and edge definitions
graph [
compound = true,
nodesep = 1,
ranksep = .25,
color = blue
]
# subgraph for Dictionary direct the flow
subgraph cluster1 {
node [
fixedsize = true,
width = 3
]
'##4'->'##6' [label=' Scoring function (sentimentr)
Inner Join (dplyr)',fontname=Helvetica]
'##6'->'##7' [label=' Grouping
Summarise (dplyr)',fontname=Helvetica]
'##7'->'##8'
}
#Add a graph statement to change the properties of the graph
graph[nodesep=1] #this modifies distance between nodes
}
# Name the nodes
[1]: 'Response Data'
[2]: 'Clean Data'
[3]: 'Tidy Text'
[4]: 'Dictionary Creation'
[5]: 'Visualisation'
[6]: 'Sentiment Lexicon'
[7]: 'Summarised Text'
[8]: 'Visualisation and Statistics'
"

Get similar objects in Drools

Assuming I have a list of objects from the type shirt, and each shirt has a color property.
Is there a way to create a rule which will get only shirts of the same color (no matter what the color is)?
You're looking for the collect function. (Link is to the Drools documentation, scroll down a bit to find "collect".) Like its name indicates, it collects things that match a condition.
Let's assume a simple class Shirt with a String color variable. Let's also assume that there are a variety of shirt instances in working memory.
rule "Collect shirts by color"
when
Shirt( $color: color )
$shirts: List() from collect( Shirt( color === $color ) )
then
// $shirts will now contain all shirts of $color
end
This rule will individually consider each shirt, and then collect all of the other shirts which have the same color. So if you have Red, Blue, and Green shirts, you'll enter the right hand side at least once with $shirts of that single color.
Of course the problem here is that you'll trigger the rule on a per-shirt basis instead of on a per-color basis. So if you have two Red shirts, you'll trigger the 'then' clause with all red shirt twice (once for each red shirt, since each red shirt will independently meet the first criteria.)
If you don't mind this, then you can use this as-is. But if you just want your consequences to fire once per shirt color, we have to be a bit more tricksy.
In order for colors to be the first class citizen, we'll need to extract the distinct set (not list!) of shirt colors, and then use those to collect our lists as needed. Here I use the accumulate function; you can read more about that at the same link I shared previously to the Drools documentation (accumulate is directly after collect.)
rule "Get shirt colors"
when
// Get all unique shirt colors
$colors: Set() from accumulate( Shirt( $color: color), collectSet( $color ))
// Get one of those colors
$color: String() from $colors
// Find all shirts of that color
$shirts: List() from collect( Shirt( color === $color ) )
then
// $shirts is all shirts of $color
end
In this second rule, you will only trigger the right hand side once per color because we started by distilling all possible colors into a distinct set of unique ones.
Doing the opposite is even simpler. If all you need to do is confirm there is at least one shirt that is not the same color, we just need to get all of the colors and verify that there's at least 2 different colors present.
rule "At least one shirt of a different color"
when
$colors: Set( size > 1 ) from accumulate(
Shirt( $color: color),
collectSet( $color )
)
then
// $colors contains more than 1 color, so there's at
// least 1 shirt present that is not the same color
// as the rest
end

Query by item in array of document, and sort by item's position in the array

I have a collection dinosaurs with documents of this structure:
doc#1:
name: "Tyrannosaurus rex",
dominantColors: [
"beige",
"blue",
"green"
]
doc#2:
name: "Velociraptor",
dominantColors: [
"green",
"orange",
"white"
]
I want to query the collection by color name (for example: green) to get documents sorted by color's position in dominantColors array. First get the documents in which green occurs higher in the array, then those in which it is lower. So, in the provided case I would get doc#2 first, then doc#1.
Each dominantColors array contains 3 elements, with elements sorted from most dominant to least.
I am looking through documentation, but am not able to find a solution. Maybe I need a different data structure altogether?
Cloud Firestore doesn't support querying arrays by ranked index. The only way you can query an array is using an array-contains type query.
What you could do instead is organize your colors using maps where the color is the key and their rank is the value:
name: "Tyrannosaurus rex",
dominantColors: {
"beige": 1,
"blue": 2,
"green": 3
}
Then you can order the query by the value of the map's property. So, in JavaScript, it would be something like this:
firebase
.collection('dinosaurs')
.where('dominantColors.green', '>', 0)
.orderBy('dominantColors.green')

Assign a color to individual row numbers

I am trying to assign an individual color to each row in a group. There are approximately 50 rows I need to assign a color and they all must be unique. What would be the easiest way to do this?
I do not want to do the alternating row colors:
"=IIf(RowNumber("DataSet1") Mod 2 = 1, "White","Blue")",
but if there was a way to modify this expression to do 50 colors and then repeat I'd be okay with that.
you can use choose . otherwise use custom code function
=Choose(ROWNUMBER(nothing) mod 50, "Brown", "Blue", "GoldenRod", "Olive", "MediumTurquoise","Red", "Green", "DeepSkyBlue", "Yellow", "Chocolate", "Purple", "DarkOrange" ,.....)

How to change cell color in a listgrid

I want to change font and color of a specific cell in a ListGrid.
I succeeded to change the color of the entire row with the following lines, but not of a single row:
for (ListGrid table : tables)
{
ListGridField[] columns = table.getFields();
for (Record record : table.getRecords())
{
....
record.setAttribute("cssText",
"font-weight:bold; font-size:80%; color:#FF3300;");
I don't want to use getCellCSSText function, i tried the following but it didn't work:
ListGridField gridfield = table.getField(columns[1].getName());
gridfield.setAttribute("cssText",
"font-weight:bold; font-size:80%; color:#FF3300;");
table.refreshFields();
I'm sure there is a better way to do it. But this is how i did it:
I added a hidden column to the table, that contain the color.
In getCellCSSText i read the color and the column name and set the color.
Is there a way to add an invisible parameter to a ListGridRecord? So that i won't add an entire column.