Beispiel #1
0
static BoundingBox labelBoundingBoxForNode(Graph *graph, node n) {
  IntegerProperty *viewShape = graph->getProperty<IntegerProperty>("viewShape");
  LayoutProperty *viewLayout = graph->getProperty<LayoutProperty>("viewLayout");
  SizeProperty *viewSize = graph->getProperty<SizeProperty>("viewSize");
  BoundingBox renderingBox;
  GlyphsManager::getGlyph(viewShape->getNodeValue(n))->getTextBoundingBox(renderingBox);
  const Coord &pos = viewLayout->getNodeValue(n);
  const Size &size = viewSize->getNodeValue(n) * Size(renderingBox.width(), renderingBox.height(), renderingBox.depth());
  return BoundingBox(pos - size/2.f, pos + size/2.f);
}
Beispiel #2
0
//=================================================================================
PropertyInterface* IntegerProperty::clonePrototype(Graph * g, const std::string& n) {
  if( !g )
    return 0;

  // allow to get an unregistered property (empty name)
  IntegerProperty * p = n.empty()
                        ? new IntegerProperty(g) : g->getLocalProperty<IntegerProperty>( n );
  p->setAllNodeValue( getNodeDefaultValue() );
  p->setAllEdgeValue( getEdgeDefaultValue() );
  return p;
}
Beispiel #3
0
// 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));
}