Eneboo - Documentación para desarrolladores
tools/aqods/odf-gen/chart.h
Ir a la documentación de este archivo.
00001 /*
00002 odf-gen: Simple API to generate OpenDocument documents.
00003     Copyright (C) 2009  Pablo Jorge, FuDePAN
00004 
00005     This file is part of the odf-gen project.
00006 
00007     odf-gen is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     odf-gen is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with odf-gen.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef CHART_H
00022 #define CHART_H
00023 
00024 #include <iostream>
00025 #include <list>
00026 
00027 #include "odstype.h"
00028 #include "celladdress.h"
00029 #include "color.h"
00030 #include "length.h"
00031 
00032 class Series 
00033 {
00034 public:
00035     Series( const CellAddress& name,
00036             const CellRange& domain,
00037             const CellRange& values,
00038             const Color& color )
00039         : _name( name ),
00040           _domain( domain ),
00041           _values( values ),
00042           _color( color )
00043     {}
00044 
00045     std::ostream& operator << ( std::ostream& ostream ) const
00046     {
00047         ostream << "<series name-address=\"" << _name << "\""
00048                 << "        x-range=\"" << _domain << "\""
00049                 << "        y-range=\"" << _values << "\""
00050                 << "        color=\"" << _color << "\""
00051                 << "/>";
00052         return ostream;
00053     }
00054 
00055 private:
00056     CellAddress _name;
00057     CellRange _domain,
00058               _values;
00059     Color _color;
00060 };
00061 
00062 inline
00063 std::ostream& operator << ( std::ostream &ostream,
00064                             const Series& series ) 
00065 {
00066     return series.operator << (ostream);
00067 }
00068 
00069 class Chart 
00070 {
00071 public:
00072     Chart( const std::string &name,
00073            const Length &width,
00074            const Length &height )
00075         : _name( name ),
00076           _width( width.str() ),
00077           _height( height.str() )
00078     {}
00079 
00080     void add_range( const CellRange &range )
00081     {
00082         _range_list.push_back( range );
00083     }
00084 
00085     void add_series( const Series &series )
00086     {
00087         _series_list.push_back( series );
00088     }
00089     
00090     void set_title( const std::string& title )
00091     {
00092         _title = title;
00093     }
00094 
00095     void set_subtitle( const std::string& subtitle )
00096     {
00097         _subtitle = subtitle;
00098     }
00099 
00100     void set_x_axis_label( const std::string& x_axis_label )
00101     {
00102         _x_axis_label = x_axis_label;
00103     }
00104 
00105     void set_y_axis_label( const std::string& y_axis_label )
00106     {
00107         _y_axis_label = y_axis_label;
00108     }
00109 
00110     std::ostream& operator << ( std::ostream& ostream ) const
00111     {
00112         ostream << "<chart name=\"" << _name << "\""
00113                 << "       width=\"" << _width << "\""
00114                 << "       height=\"" << _height << "\""
00115                 << "       title=\"" << _title << "\""
00116                 << "       subtitle=\"" << _subtitle << "\""
00117                 << "       x-axis-label=\"" << _x_axis_label << "\""
00118                 << "       y-axis-label=\"" << _y_axis_label << "\""
00119                 << "       range=\"";
00120         
00121         for( std::list< CellRange >::const_iterator 
00122              it  = _range_list.begin();
00123              it != _range_list.end();
00124              it++ )
00125             ostream << *it << ";";
00126         
00127         ostream << "\">";
00128         
00129         for( std::list< Series >::const_iterator 
00130              it  = _series_list.begin();
00131              it != _series_list.end();
00132              it++ )
00133             ostream << *it;
00134         
00135         ostream << "</chart>";
00136         
00137         return ostream;
00138     }
00139 
00140 private:
00141     std::string _name,
00142                 _width,
00143                 _height,
00144                 _title,
00145                 _subtitle,
00146                 _x_axis_label,
00147                 _y_axis_label;
00148     std::list< CellRange > _range_list;
00149     std::list< Series > _series_list;
00150 };
00151 
00152 MAP_ODS_TYPE(Chart, object);
00153 
00154 inline
00155 std::ostream& operator << ( std::ostream &ostream,
00156                             const Chart& chart ) 
00157 {
00158     return chart.operator << (ostream);
00159 }
00160 
00161 class AutoChart : public Chart
00162 {
00163 public:
00164     AutoChart( const std::string &name,
00165                const Length &width,
00166                const Length &height,
00167                const Sheet &sheet )
00168         : Chart( name, 
00169                  width, 
00170                  height ) 
00171     {
00172         ColorGenerator generator;
00173 
00174         add_range( CellRange( CellAddress( sheet.get_name(), 1, 1 ),
00175                               CellAddress( sheet.get_name(),
00176                                            sheet.get_columns(),
00177                                            sheet.get_rows() ) ) );
00178 
00179         for( unsigned int i = 2; i <= sheet.get_columns(); i++ ) 
00180         {
00181             CellAddress name( sheet.get_name(), i, 1 ),
00182                         domain_start( sheet.get_name(), 1, 2 ),
00183                         domain_end( sheet.get_name(), 1, sheet.get_rows() ),
00184                         values_start( sheet.get_name(), i, 2 ),
00185                         values_end( sheet.get_name(), i, sheet.get_rows() );
00186             CellRange domain( domain_start, domain_end ),
00187                       values( values_start, values_end );
00188             Color color( generator.next() );
00189 
00190             add_series( Series( name, domain, values, color ) );
00191         }
00192     }
00193 };
00194 
00195 MAP_ODS_TYPE(AutoChart, object);
00196 
00197 #endif // CHART_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'