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) 2001-2009 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 {
46  assert(!properties.empty());
47 
48  // Generates random colors to each property
49  for(std::size_t i = 0; i < m_properties.size(); ++i)
50  {
51  te::color::RGBAColor color(rand() % 255, rand() % 255, rand() % 255, TE_OPAQUE);
52  m_colors.push_back(color);
53  }
54 }
55 
56 te::map::Chart::Chart(ChartType type, const std::vector<std::string>& properties, const std::vector<te::color::RGBAColor>& colors)
57  : m_type(type),
58  m_properties(properties),
59  m_colors(colors),
60  m_contourColor(te::color::RGBAColor(0, 0, 0, TE_OPAQUE)),
61  m_contourWidth(1),
62  m_height(24),
63  m_barWidth(16),
64  m_isVisible(true),
65  m_maxValue(0.0),
66  m_avoidConflicts(true)
67 {
68  assert(!properties.empty());
69  assert(properties.size() == colors.size());
70 }
71 
73 {
74 }
75 
77 {
78  return m_type;
79 }
80 
81 const std::vector<std::string>& te::map::Chart::getProperties() const
82 {
83  return m_properties;
84 }
85 
87 {
88  assert(i < m_colors.size());
89 
90  return m_colors[i];
91 }
92 
93 void te::map::Chart::setColor(std::size_t i, const te::color::RGBAColor& color)
94 {
95  assert(i < m_colors.size());
96 
97  m_colors[i] = color;
98 }
99 
101 {
102  return m_contourColor;
103 }
104 
106 {
107  m_contourColor = color;
108 }
109 
111 {
112  return m_contourWidth;
113 }
114 
115 void te::map::Chart::setContourWidth(std::size_t width)
116 {
117  m_contourWidth = width;
118 }
119 
120 std::size_t te::map::Chart::getHeight() const
121 {
122  return m_height;
123 }
124 
125 void te::map::Chart::setHeight(std::size_t height)
126 {
127  m_height = height;
128 }
129 
130 std::size_t te::map::Chart::getWidth() const
131 {
132  // TODO: need review! Cause: dynamic chart sizes...
133  switch(m_type)
134  {
135  case Pie:
136  return m_height;
137 
138  case Bar:
139  return m_barWidth * m_properties.size();
140  }
141 
142  return 0;
143 }
144 
145 std::size_t te::map::Chart::getBarWidth() const
146 {
147  return m_barWidth;
148 }
149 
150 void te::map::Chart::setBarWidth(std::size_t width)
151 {
152  m_barWidth = width;
153 }
154 
155 void te::map::Chart::setMaxValue(double value)
156 {
157  m_maxValue = value;
158 }
159 
161 {
162  return m_maxValue;
163 }
164 
166 {
167  return m_isVisible;
168 }
169 
171 {
172  m_isVisible = visible;
173 }
174 
176 {
177  m_avoidConflicts = on;
178 }
179 
181 {
182  return m_avoidConflicts;
183 }
ChartType
The chart types.
Definition: Enums.h:163
ChartType getType() const
Definition: Chart.cpp:76
const std::vector< std::string > & getProperties() const
Definition: Chart.cpp:81
void setContourColor(const te::color::RGBAColor &color)
Definition: Chart.cpp:105
std::size_t getBarWidth() const
Definition: Chart.cpp:145
void setColor(std::size_t i, const te::color::RGBAColor &color)
Definition: Chart.cpp:93
~Chart()
Destructor.
Definition: Chart.cpp:72
std::vector< te::color::RGBAColor > m_colors
The color used to each property.
Definition: Chart.h:123
void setHeight(std::size_t height)
Definition: Chart.cpp:125
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:122
double getMaxValue() const
Definition: Chart.cpp:160
void setAvoidConflicts(bool on)
Definition: Chart.cpp:175
const te::color::RGBAColor & getColor(std::size_t i) const
Definition: Chart.cpp:86
void setBarWidth(std::size_t width)
Definition: Chart.cpp:150
#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:120
bool isVisible() const
It gets the chart visibility.
Definition: Chart.cpp:165
void setVisibility(bool visible)
It sets the chart visibility.
Definition: Chart.cpp:170
This class represents the informations needed to build map charts.
std::size_t getContourWidth() const
Definition: Chart.cpp:110
const te::color::RGBAColor & getContourColor() const
Definition: Chart.cpp:100
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
bool getAvoidConflicts() const
Definition: Chart.cpp:180
void setMaxValue(double value)
Definition: Chart.cpp:155
void setContourWidth(std::size_t width)
Definition: Chart.cpp:115
std::size_t getWidth() const
Definition: Chart.cpp:130