Author: aschnell
Date: Wed Feb 4 12:49:35 2009
New Revision: 55233
URL: http://svn.opensuse.org/viewcvs/yast?rev=55233&view=rev
Log:
- work on styles for nodes and edges
Modified:
trunk/storage/libstorage/src/Graph.cc
Modified: trunk/storage/libstorage/src/Graph.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Graph.cc?rev=55233&r1=55232&r2=55233&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Graph.cc (original)
+++ trunk/storage/libstorage/src/Graph.cc Wed Feb 4 12:49:35 2009
@@ -18,53 +18,78 @@
namespace storage
{
- enum Rank { RANK_NONE, RANK_DISK, RANK_PARTITION, RANK_MD, RANK_LVMVG, RANK_LVMLV,
- RANK_MOUNTPOINT };
- typedef array Ranks;
- const Ranks ranks = { { RANK_DISK, RANK_PARTITION, RANK_MD, RANK_LVMVG, RANK_LVMLV,
- RANK_MOUNTPOINT } };
+ enum NodeType { NODE_DISK, NODE_PARTITION, NODE_MDRAID, NODE_LVMVG, NODE_LVMLV, NODE_MOUNTPOINT };
struct Node
{
- Node(const string& id, Rank rank, const string& label, const string& attributes = "")
- : id(id), rank(rank), label(label), attributes(attributes)
+ Node(NodeType type, const string& id, const string& label)
+ : type(type), id(id), label(label)
{}
+ NodeType type;
string id;
- Rank rank;
string label;
- string attributes;
};
+
+ enum EdgeType { EDGE_SUBDEVICE, EDGE_MOUNT, EDGE_USED };
+
struct Edge
{
- Edge(const string& id1, const string& id2, const string& attributes = "")
- : id1(id1), id2(id2), attributes(attributes)
+ Edge(EdgeType type, const string& id1, const string& id2)
+ : type(type), id1(id1), id2(id2)
{}
+ EdgeType type;
string id1;
string id2;
- string attributes;
};
+
+ typedef array Ranks;
+ const Ranks ranks = { { NODE_DISK, NODE_PARTITION, NODE_MDRAID, NODE_LVMVG, NODE_LVMLV,
+ NODE_MOUNTPOINT } };
+
+
string dotQuote(const string& str)
{
return '"' + boost::replace_all_copy(str, "\"", "\\\"") + '"';
}
+
std::ostream& operator<<(std::ostream& s, const Node& node)
{
s << dotQuote(node.id) << " [label=" << dotQuote(node.label);
- if (!node.attributes.empty())
- s << ", " << node.attributes;
+ switch (node.type)
+ {
+ case NODE_DISK:
+ s << ", color=red, fillcolor=yellow";
+ break;
+ case NODE_PARTITION:
+ s << ", color=blue, fillcolor=lightblue";
+ break;
+ case NODE_MOUNTPOINT:
+ s << ", color=green, fillcolor=lightgreen";
+ break;
+ }
return s << "];";
}
std::ostream& operator<<(std::ostream& s, const Edge& edge)
{
s << dotQuote(edge.id1) << " -> " << dotQuote(edge.id2);
- if (!edge.attributes.empty())
- s << " [" << edge.attributes << "]";
+ switch (edge.type)
+ {
+ case EDGE_SUBDEVICE:
+ s << " [color=blue]";
+ break;
+ case EDGE_MOUNT:
+ s << " [color=green]";
+ break;
+ case EDGE_USED:
+ s << " [color=red]";
+ break;
+ }
return s << ";";
}
@@ -85,12 +110,12 @@
{
case DISK: {
- Node disk_node("device:" + i1->device, RANK_DISK, i1->device);
+ Node disk_node(NODE_DISK, "device:" + i1->device, i1->device);
nodes.push_back(disk_node);
if (!i1->usedByDevice.empty())
{
- edges.push_back(Edge(disk_node.id, "device:" + i1->usedByDevice));
+ edges.push_back(EDGE_USED, disk_node.id, "device:" + i1->usedByDevice);
}
deque<PartitionInfo> partitions;
@@ -101,22 +126,22 @@
if (i2->partitionType == EXTENDED)
continue;
- Node partition_node("device:" + i2->v.device, RANK_PARTITION, i2->v.device);
+ Node partition_node(NODE_PARTITION, "device:" + i2->v.device, i2->v.device);
nodes.push_back(partition_node);
- edges.push_back(Edge(disk_node.id, partition_node.id));
+ edges.push_back(EDGE_SUBDEVICE, disk_node.id, partition_node.id);
if (!i2->v.usedByDevice.empty())
{
- edges.push_back(Edge(partition_node.id, "device:" + i2->v.usedByDevice, "color=green"));
+ edges.push_back(EDGE_USED, partition_node.id, "device:" + i2->v.usedByDevice);
}
if (!i2->v.mount.empty())
{
- Node mountpoint_node("mountpoint:" + i2->v.mount, RANK_MOUNTPOINT, i2->v.mount);
+ Node mountpoint_node(NODE_MOUNTPOINT, "mountpoint:" + i2->v.mount, i2->v.mount);
nodes.push_back(mountpoint_node);
- edges.push_back(Edge(partition_node.id, mountpoint_node.id, "color=blue"));
+ edges.push_back(EDGE_MOUNT, partition_node.id, mountpoint_node.id);
}
}
@@ -124,7 +149,7 @@
case LVM: {
- Node vg_node("device:" + i1->device, RANK_LVMVG, i1->device);
+ Node vg_node(NODE_LVMVG, "device:" + i1->device, i1->device);
nodes.push_back(vg_node);
deque<LvmLvInfo> lvs;
@@ -132,17 +157,17 @@
for (deque<LvmLvInfo>::iterator i2 = lvs.begin();
i2 != lvs.end(); ++i2)
{
- Node lv_node("device:" + i2->v.device, RANK_LVMLV, i2->v.device);
+ Node lv_node(NODE_LVMLV, "device:" + i2->v.device, i2->v.device);
nodes.push_back(lv_node);
- edges.push_back(Edge(vg_node.id, lv_node.id));
+ edges.push_back(EDGE_SUBDEVICE, vg_node.id, lv_node.id);
if (!i2->v.mount.empty())
{
- Node mountpoint_node("mountpoint:" + i2->v.mount, RANK_MOUNTPOINT, i2->v.mount);
+ Node mountpoint_node(NODE_MOUNTPOINT, "mountpoint:" + i2->v.mount, i2->v.mount);
nodes.push_back(mountpoint_node);
- edges.push_back(Edge(lv_node.id, mountpoint_node.id));
+ edges.push_back(EDGE_MOUNT, lv_node.id, mountpoint_node.id);
}
}
@@ -155,20 +180,20 @@
for (deque<MdInfo>::iterator i2 = mds.begin(); i2 != mds.end(); ++i2)
{
- Node md_node("device:" + i2->v.device, RANK_MD, i2->v.device, "color=red, fillcolor=yellow");
+ Node md_node(NODE_MDRAID, "device:" + i2->v.device, i2->v.device);
nodes.push_back(md_node);
if (!i2->v.usedByDevice.empty())
{
- edges.push_back(Edge(md_node.id, "device:" + i2->v.usedByDevice));
+ edges.push_back(EDGE_USED, md_node.id, "device:" + i2->v.usedByDevice);
}
if (!i2->v.mount.empty())
{
- Node mountpoint_node("mountpoint:" + i2->v.mount, RANK_MOUNTPOINT, i2->v.mount);
+ Node mountpoint_node(NODE_MOUNTPOINT, "mountpoint:" + i2->v.mount, i2->v.mount);
nodes.push_back(mountpoint_node);
- edges.push_back(Edge(md_node.id, mountpoint_node.id));
+ edges.push_back(EDGE_MOUNT, md_node.id, mountpoint_node.id);
}
}
@@ -196,7 +221,7 @@
{
list<string> ids;
for (list<Node>::const_iterator node = nodes.begin(); node != nodes.end(); ++node)
- if (node->rank == *rank)
+ if (node->type == *rank)
ids.push_back(dotQuote(node->id));
if (!ids.empty())
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org