5 #include <unordered_set>
6 #include <unordered_map>
17 namespace datastructure {
19 template <
typename K,
typename E1,
typename E2>
class GraphAdjList;
20 template <
typename K,
typename E1,
typename E2>
class GraphAdjMatrix;
53 template <
typename K,
typename E1,
typename E2>
friend class GraphAdjList;
55 template <
typename K>
friend class Array;
56 template <
typename K>
friend class Array1D;
57 template <
typename K>
friend class Array2D;
58 template <
typename K>
friend class Array3D;
68 static const unordered_map<const Shape, const string, hash<int >> & ShapeNames() {
70 static std::unordered_map<const Shape, const string, hash<int >> sn = {
87 ElementVisualizer* elvis;
92 unordered_map<Element*, LinkVisualizer>
links;
102 explicit Element(
const E& val = E(),
const string& lab =
string()) :
103 label(lab), value(val) {
114 : label(e.label), value(e.value), elvis(new
ElementVisualizer(*(e.elvis))), links(e.links) {
118 this->label = e.label;
119 this->value = e.value;
120 *(this->elvis) = *(e.elvis);
121 this->links = e.links;
125 E& operator= (E
const& e) {
163 if (links.find(
const_cast<Element *
>(el)) != links.end()) {
164 return &(links.at(
const_cast<Element*
>(el)));
167 cerr <<
"Element " << label <<
" not linked to Element "
168 << el->
getLabel() <<
", returning NULL" << endl;
181 return const_cast<Element*
> (
this)->getLinkVisualizer(el);
241 if ( (elvis->getLocationX() != INFINITY) &&
242 (elvis->getLocationY() != INFINITY) ) {
250 QUOTE +
"color" +
QUOTE +
COLON + elvis->getColor().getCSSRepresentation()
254 ShapeNames().at(elvis->getShape()) +
QUOTE +
COMMA +
312 const string& src,
const string& dest) {
330 const string& src,
const string& dest,
331 rapidjson::Document& d) {
333 using namespace rapidjson;
334 Document::AllocatorType& allocator = d.GetAllocator();
340 v.SetString(col_str.c_str(), allocator);
341 lv_obj.AddMember(
"color", v, allocator);
343 v.SetString(lv.
getLabel().c_str(), allocator);
344 lv_obj.AddMember(
"label", v, allocator);
346 lv_obj.AddMember(
"thickness", v.SetDouble(lv.
getThickness()), allocator);
347 v.SetString(src.c_str(), allocator);
348 lv_obj.AddMember(
"source", v, allocator);
349 v2.SetString(dest.c_str(), allocator);
350 lv_obj.AddMember(
"target", v2, allocator);
351 d.AddMember(
"link", lv_obj, allocator);
369 return elvis->getSize();
377 elvis->setColor(col);
386 elvis->setColor(col);
395 return elvis->getColor();
404 elvis->setOpacity(opacity);
413 return elvis->getOpacity();
423 elvis->setShape(shp);
433 return elvis->getShape();
442 elvis->setLocation(locX, locY);
450 return elvis->getLocationX();
457 return elvis->getLocationY();
A BRIDGES 1D array type.
Definition: Array1D.h:53
A BRIDGES array type.
Definition: Array2D.h:42
A BRIDGES array type.
Definition: Array3D.h:42
The foundation of BRIDGES array types. It is not meant to be used directly by students.
Definition: Array.h:21
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:50
const string getCSSRepresentation() const
Definition: Color.h:403
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:51
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:310
void setColor(const Color &col)
Set the color of the Element.
Definition: Element.h:376
void setShape(const Shape &shp)
Set the shape of the element.
Definition: Element.h:422
Element(const E &val=E(), const string &lab=string())
Definition: Element.h:102
void setValue(const E &val)
Sets generic object to "val".
Definition: Element.h:226
virtual const string getElementRepresentation() const
Gets the JSON string of the element representation.
Definition: Element.h:235
void setSize(const double &sz)
Sets size of the element.
Definition: Element.h:359
void setColor(const string col)
Set the color by name.
Definition: Element.h:385
void setLabel(const string &lab)
Sets label of this element.
Definition: Element.h:197
string const & getLabel() const
Gets the label of this element.
Definition: Element.h:188
double getLocationX() const
Gets the X coordinate of the location.
Definition: Element.h:449
LinkVisualizer * getLinkVisualizer(const Element *el)
Returns the LinkVisualizer of element.
Definition: Element.h:162
LinkVisualizer * getLinkVisualizer(const Element *el) const
Returns the LinkVisualizer of element.
Definition: Element.h:180
double getLocationY() const
Gets the Y coordinate of the location.
Definition: Element.h:456
const ElementVisualizer * getVisualizer() const
Get the element visualizer object - constant version.
Definition: Element.h:149
Element(const Element &e)
Definition: Element.h:113
double getSize() const
Get element size.
Definition: Element.h:368
E & getValue()
Gets the object held in the generic object E.
Definition: Element.h:217
static void getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest, rapidjson::Document &d)
Definition: Element.h:328
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:92
void setOpacity(double opacity)
Set opacity of element - use the 4th color component.
Definition: Element.h:403
Shape getShape() const
Returns the shape of the element.
Definition: Element.h:432
double getOpacity()
Definition: Element.h:412
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:207
ElementVisualizer * getVisualizer()
Get the element visualizer object.
Definition: Element.h:141
virtual ~Element()
Definition: Element.h:133
Color getColor() const
Get the current color of the element.
Definition: Element.h:394
void setLocation(const double &locX, const double &locY)
Sets the location attributes of an element.
Definition: Element.h:441
This class maintains the visual properties of the a Bridges element.
Definition: ElementVisualizer.h:31
This class provides methods to represent adjacency list based graphs.
Definition: GraphAdjList.h:110
This class provides methods to represent adjacency matrix based graphs.
Definition: GraphAdjMatrix.h:37
This class maintains the visual properties of links within data structures.
Definition: LinkVisualizer.h:26
double getThickness() const
Get the link thickness.
Definition: LinkVisualizer.h:101
string getLabel() const
Return the link label.
Definition: LinkVisualizer.h:69
Color getColor() const
Return the link color.
Definition: LinkVisualizer.h:125
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
Shape
Definition: ElementVisualizer.h:10
@ DIAMOND
Definition: ElementVisualizer.h:10
@ CIRCLE
Definition: ElementVisualizer.h:10
@ SQUARE
Definition: ElementVisualizer.h:10
@ STAR
Definition: ElementVisualizer.h:10
@ WYE
Definition: ElementVisualizer.h:10
@ TRIANGLE
Definition: ElementVisualizer.h:10
@ CROSS
Definition: ElementVisualizer.h:10
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string OPEN_CURLY
Definition: DataStructure.h:53
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50