All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Chart.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/maptools/Chart.cpp
22 
23  \brief This class represents the informations needed to build map charts.
24 */
25 
26 // TerraLib
27 #include "../se/Utils.h"
28 #include "Chart.h"
29 
30 // STL
31 #include <cassert>
32 #include <cmath>
33 #include <cstdlib>
34 
35 te::map::Chart::Chart(ChartType type, const std::vector<std::string>& properties)
36  : m_type(type),
37  m_properties(properties),
38  m_contourColor(te::color::RGBAColor(0, 0, 0, TE_OPAQUE)),
39  m_contourWidth(1),
40  m_height(24),
41  m_barWidth(16),
42  m_isVisible(true),
43  m_maxValue(0.0),
44  m_avoidConflicts(true),
45  m_summary("AVERAGE")
46 {
47  assert(!properties.empty());
48 
49  // Generates random colors to each property
50  for(std::size_t i = 0; i < m_properties.size(); ++i)
51  {
52  te::color::RGBAColor color(rand() % 255, rand() % 255, rand() % 255, TE_OPAQUE);
53  m_colors.push_back(color);
54  }
55 }
56 
57 te::map::Chart::Chart(ChartType type, const std::vector<std::string>& properties, const std::vector<te::color::RGBAColor>& colors)
58  : m_type(type),
59  m_properties(properties),
60  m_colors(colors),
61  m_contourColor(te::color::RGBAColor(0, 0, 0, TE_OPAQUE)),
62  m_contourWidth(1),
63  m_height(24),
64  m_barWidth(16),
65  m_isVisible(true),
66  m_maxValue(0.0),
67  m_avoidConflicts(true),
68  m_summary("AVERAGE")
69 {
70  assert(!properties.empty());
71  assert(properties.size() == colors.size());
72 }
73 
75 {
76 }
77 
79 {
80  return m_type;
81 }
82 
83 const std::vector<std::string>& te::map::Chart::getProperties() const
84 {
85  return m_properties;
86 }
87 
88 const std::vector<size_t>& te::map::Chart::getPropertiesPos() const
89 {
90  return m_propertiesPos;
91 }
92 
93 void te::map::Chart::setPropertiesPos(const std::vector<size_t>& proPos)
94 {
95  m_propertiesPos = proPos;
96 }
97 
99 {
100  assert(i < m_colors.size());
101 
102  return m_colors[i];
103 }
104 
105 void te::map::Chart::setColor(std::size_t i, const te::color::RGBAColor& color)
106 {
107  assert(i < m_colors.size());
108 
109  m_colors[i] = color;
110 }
111 
113 {
114  return m_contourColor;
115 }
116 
118 {
119  m_contourColor = color;
120 }
121 
123 {
124  return m_contourWidth;
125 }
126 
127 void te::map::Chart::setContourWidth(std::size_t width)
128 {
129  m_contourWidth = width;
130 }
131 
132 std::size_t te::map::Chart::getHeight() const
133 {
134  return m_height;
135 }
136 
137 void te::map::Chart::setHeight(std::size_t height)
138 {
139  m_height = height;
140 }
141 
142 std::size_t te::map::Chart::getWidth() const
143 {
144  // TODO: need review! Cause: dynamic chart sizes...
145  switch(m_type)
146  {
147  case Pie:
148  return m_height;
149 
150  case Bar:
151  return m_barWidth * m_properties.size();
152  }
153 
154  return 0;
155 }
156 
157 std::size_t te::map::Chart::getBarWidth() const
158 {
159  return m_barWidth;
160 }
161 
162 void te::map::Chart::setBarWidth(std::size_t width)
163 {
164  m_barWidth = width;
165 }
166 
167 void te::map::Chart::setMaxValue(double value)
168 {
169  m_maxValue = value;
170 }
171 
173 {
174  return m_maxValue;
175 }
176 
178 {
179  return m_isVisible;
180 }
181 
183 {
184  m_isVisible = visible;
185 }
186 
188 {
189  m_avoidConflicts = on;
190 }
191 
193 {
194  return m_avoidConflicts;
195 }
196 
197 std::string te::map::Chart::getSummary() const
198 {
199  return m_summary;
200 }
201 
202 void te::map::Chart::setSummary(const std::string& summary)
203 {
204  m_summary = summary;
205 }
ChartType
The chart types.
Definition: Enums.h:163
ChartType getType() const
Definition: Chart.cpp:78
const std::vector< std::string > & getProperties() const
Definition: Chart.cpp:83
void setContourColor(const te::color::RGBAColor &color)
Definition: Chart.cpp:117
std::size_t getBarWidth() const
Definition: Chart.cpp:157
void setColor(std::size_t i, const te::color::RGBAColor &color)
Definition: Chart.cpp:105
std::string getSummary() const
It gets the grouping summary. It is used only in case 1 to n.
Definition: Chart.cpp:197
~Chart()
Destructor.
Definition: Chart.cpp:74
std::vector< te::color::RGBAColor > m_colors
The color used to each property.
Definition: Chart.h:139
void setHeight(std::size_t height)
Definition: Chart.cpp:137
Chart(ChartType type, const std::vector< std::string > &properties)
It constructs a new Chart instance.
Definition: Chart.cpp:35
std::vector< std::string > m_properties
The property names that will be used to generate the chart.
Definition: Chart.h:137
void setSummary(const std::string &summary)
It gets the grouping summary. It is used only in case 1 to n.
Definition: Chart.cpp:202
double getMaxValue() const
Definition: Chart.cpp:172
void setAvoidConflicts(bool on)
Definition: Chart.cpp:187
const te::color::RGBAColor & getColor(std::size_t i) const
Definition: Chart.cpp:98
void setBarWidth(std::size_t width)
Definition: Chart.cpp:162
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
std::size_t getHeight() const
Definition: Chart.cpp:132
bool isVisible() const
It gets the chart visibility.
Definition: Chart.cpp:177
void setVisibility(bool visible)
It sets the chart visibility.
Definition: Chart.cpp:182
This class represents the informations needed to build map charts.
void setPropertiesPos(const std::vector< size_t > &propPos)
Definition: Chart.cpp:93
std::size_t getContourWidth() const
Definition: Chart.cpp:122
const te::color::RGBAColor & getContourColor() const
Definition: Chart.cpp:112
const std::vector< size_t > & getPropertiesPos() const
Definition: Chart.cpp:88
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
bool getAvoidConflicts() const
Definition: Chart.cpp:192
void setMaxValue(double value)
Definition: Chart.cpp:167
void setContourWidth(std::size_t width)
Definition: Chart.cpp:127
std::size_t getWidth() const
Definition: Chart.cpp:142