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