![]() |
|
Navigation |
Synopsis Visualize an Algebraic Datatype as a tree.
Description In ColoredTrees we have discussed the Algebraic Data Type
ColoredTree .
Here we show how to create a visualization for them. The global approach is:
Examples Here is our solution:
@license{ Copyright (c) 2009-2013 CWI All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html } module demo::vis::VisADT import vis::Figure; import vis::Render; data ColoredTree = leaf(int N) | red(ColoredTree left, ColoredTree right) | black(ColoredTree left, ColoredTree right) | green(ColoredTree left, ColoredTree right) ; public Figure visColoredTree(leaf(int N)) = box(text("<N>"), gap(2), fillColor("lightyellow"));
ColoredTree rb we can set a standard (see Rascal:std) Rascal:size and standard Rascal:gap:
import demo::vis::VisADT; render(space(visColoredTree(rb), std(size(30)), std(gap(30))));and the result is: ![]() Note that:
import demo::vis::VisADT; render(space(visColoredTree(rb), std(size(30)), std(gap(30)), std(manhattan(false))));the result is: ![]() It is also possible to change the Rascal:orientation of the tree and draw it, for example, from left to right: import demo::vis::VisADT; render(space(visColoredTree(rb), std(size(30)), std(gap(30)), std(orientation(leftRight()))));the result is: ![]() ![]() |