// That function sets some visual properties on a complete tree whose depth equals 5 void setTreeVisualProperties(Graph *tree) { // First compute a layout, we use the Bubble Tree algorithm LayoutProperty *viewLayout = tree->getProperty<LayoutProperty>("viewLayout"); std::string errMsg; tree->applyPropertyAlgorithm("Bubble Tree", viewLayout, errMsg); // Then apply Auto Sizing on the nodes SizeProperty *viewSize = tree->getProperty<SizeProperty>("viewSize"); tree->applyPropertyAlgorithm("Auto Sizing", viewSize, errMsg); // Labels the node with their id StringProperty *viewLabel = tree->getProperty<StringProperty>("viewLabel"); for (auto n : tree->nodes()) { viewLabel->setNodeValue(n, QStringToTlpString(QString::number(n.id))); } // Add a border to the nodes, keep the default color who is black DoubleProperty *viewBorderWidth = tree->getProperty<DoubleProperty>("viewBorderWidth"); viewBorderWidth->setAllNodeValue(1); // Build some maps to set shapes and colors according to the dag level of a node std::vector<int> glyphsMap; glyphsMap.push_back(tlp::NodeShape::Square); glyphsMap.push_back(tlp::NodeShape::Circle); glyphsMap.push_back(tlp::NodeShape::RoundedBox); glyphsMap.push_back(tlp::NodeShape::Hexagon); glyphsMap.push_back(tlp::NodeShape::Star); glyphsMap.push_back(tlp::NodeShape::Ring); std::vector<Color> colorsMap; colorsMap.push_back(Color::Red); colorsMap.push_back(Color::Azure); colorsMap.push_back(Color::Lemon); colorsMap.push_back(Color::SpringGreen); colorsMap.push_back(Color::Apricot); colorsMap.push_back(Color::Magenta); // Compute the Dag Level metric, the value of each node will correspond // to their layer id in the tree DoubleProperty dagLevel(tree); tree->applyPropertyAlgorithm("Dag Level", &dagLevel, errMsg); // Sets different shapes and colors for each layer of the tree IntegerProperty *viewShape = tree->getProperty<IntegerProperty>("viewShape"); ColorProperty *viewColor = tree->getProperty<ColorProperty>("viewColor"); for (auto n : tree->nodes()) { viewShape->setNodeValue(n, glyphsMap[int(dagLevel.getNodeValue(n))]); viewColor->setNodeValue(n, colorsMap[int(dagLevel.getNodeValue(n))]); } }
void TestPropertiesMinMaxAfterAddNode::testIntegerPropertyMinMaxAfterAddNode() { IntegerProperty *intProp = graph->getProperty<IntegerProperty>("intProp"); // add two nodes node n1 = graph->addNode(); node n2 = graph->addNode(); const int i1 = 3; const int i2 = 56; // set values to doubleProp intProp->setNodeValue(n1, i1); intProp->setNodeValue(n2, i2); CPPUNIT_ASSERT_EQUAL(i1, intProp->getNodeMin(graph)); CPPUNIT_ASSERT_EQUAL(i2, intProp->getNodeMax(graph)); // add a new node, the value associated to doubleProp property is the default one 0 graph->addNode(); // min should be 0 CPPUNIT_ASSERT_EQUAL(0, intProp->getNodeMin(graph)); CPPUNIT_ASSERT_EQUAL(i2, intProp->getNodeMax(graph)); }