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 
74 te::map::Chart::~Chart() = default;
75 
77 {
82  c->setHeight(m_height);
88 
89  return c;
90 }
91 
93 {
94  return m_type;
95 }
96 
97 const std::vector<std::string>& te::map::Chart::getProperties() const
98 {
99  return m_properties;
100 }
101 
102 const std::vector<size_t>& te::map::Chart::getPropertiesPos() const
103 {
104  return m_propertiesPos;
105 }
106 
107 void te::map::Chart::setPropertiesPos(const std::vector<size_t>& proPos)
108 {
109  m_propertiesPos = proPos;
110 }
111 
113 {
114  assert(i < m_colors.size());
115 
116  return m_colors[i];
117 }
118 
119 void te::map::Chart::setColor(std::size_t i, const te::color::RGBAColor& color)
120 {
121  assert(i < m_colors.size());
122 
123  m_colors[i] = color;
124 }
125 
127 {
128  return m_contourColor;
129 }
130 
132 {
133  m_contourColor = color;
134 }
135 
137 {
138  return m_contourWidth;
139 }
140 
141 void te::map::Chart::setContourWidth(std::size_t width)
142 {
143  m_contourWidth = width;
144 }
145 
146 std::size_t te::map::Chart::getHeight() const
147 {
148  return m_height;
149 }
150 
151 void te::map::Chart::setHeight(std::size_t height)
152 {
153  m_height = height;
154 }
155 
156 std::size_t te::map::Chart::getWidth() const
157 {
158  // TODO: need review! Cause: dynamic chart sizes...
159  switch(m_type)
160  {
161  case Pie:
162  return m_height;
163 
164  case Bar:
165  return m_barWidth * m_properties.size();
166  }
167 
168  return 0;
169 }
170 
171 std::size_t te::map::Chart::getBarWidth() const
172 {
173  return m_barWidth;
174 }
175 
176 void te::map::Chart::setBarWidth(std::size_t width)
177 {
178  m_barWidth = width;
179 }
180 
181 void te::map::Chart::setMaxValue(double value)
182 {
183  m_maxValue = value;
184 }
185 
187 {
188  return m_maxValue;
189 }
190 
192 {
193  return m_isVisible;
194 }
195 
197 {
198  m_isVisible = visible;
199 }
200 
202 {
203  m_avoidConflicts = on;
204 }
205 
207 {
208  return m_avoidConflicts;
209 }
210 
211 std::string te::map::Chart::getSummary() const
212 {
213  return m_summary;
214 }
215 
216 void te::map::Chart::setSummary(const std::string& summary)
217 {
218  m_summary = summary;
219 }
ChartType
The chart types.
Chart * clone()
Definition: Chart.cpp:76
ChartType getType() const
Definition: Chart.cpp:92
const std::vector< std::string > & getProperties() const
Definition: Chart.cpp:97
std::size_t m_height
The chart height (in pixels).
Definition: Chart.h:144
void setContourColor(const te::color::RGBAColor &color)
Definition: Chart.cpp:131
std::size_t getBarWidth() const
Definition: Chart.cpp:171
void setColor(std::size_t i, const te::color::RGBAColor &color)
Definition: Chart.cpp:119
std::string getSummary() const
It gets the grouping summary. It is used only in case 1 to n.
Definition: Chart.cpp:211
~Chart()
Destructor.
double m_maxValue
The max value of the chart.
Definition: Chart.h:147
std::vector< te::color::RGBAColor > m_colors
The color used to each property.
Definition: Chart.h:141
std::size_t m_barWidth
The bar width for char Bar type (in pixels).
Definition: Chart.h:145
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
void setHeight(std::size_t height)
Definition: Chart.cpp:151
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:139
void setSummary(const std::string &summary)
It gets the grouping summary. It is used only in case 1 to n.
Definition: Chart.cpp:216
double getMaxValue() const
Definition: Chart.cpp:186
void setAvoidConflicts(bool on)
Definition: Chart.cpp:201
const te::color::RGBAColor & getColor(std::size_t i) const
Definition: Chart.cpp:112
This class represents the informations needed to build map charts.
Definition: Chart.h:51
ChartType m_type
The chart type.
Definition: Chart.h:138
void setBarWidth(std::size_t width)
Definition: Chart.cpp:176
std::size_t getHeight() const
Definition: Chart.cpp:146
te::color::RGBAColor m_contourColor
The chart contour color.
Definition: Chart.h:142
URI C++ Library.
Definition: Attributes.h:37
bool isVisible() const
It gets the chart visibility.
Definition: Chart.cpp:191
void setVisibility(bool visible)
It sets the chart visibility.
Definition: Chart.cpp:196
std::string m_summary
The summary used in case 1 to n.
Definition: Chart.h:149
This class represents the informations needed to build map charts.
void setPropertiesPos(const std::vector< size_t > &propPos)
Definition: Chart.cpp:107
bool m_isVisible
A flag that indicates if the chart is visible.
Definition: Chart.h:146
std::size_t getContourWidth() const
Definition: Chart.cpp:136
const te::color::RGBAColor & getContourColor() const
Definition: Chart.cpp:126
std::vector< size_t > m_propertiesPos
The properties position.
Definition: Chart.h:140
const std::vector< size_t > & getPropertiesPos() const
Definition: Chart.cpp:102
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
bool getAvoidConflicts() const
Definition: Chart.cpp:206
void setMaxValue(double value)
Definition: Chart.cpp:181
std::size_t m_contourWidth
The chart contour width (in pixels).
Definition: Chart.h:143
bool m_avoidConflicts
A flag that indicates if conflicts must be avoided.
Definition: Chart.h:148
void setContourWidth(std::size_t width)
Definition: Chart.cpp:141
std::size_t getWidth() const
Definition: Chart.cpp:156