combo_chart.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: combo_chart.hpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 19:48:03 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_GRAPH___COMBO_CHART__HPP
- #define GUI_GRAPH___COMBO_CHART__HPP
- /* $Id: combo_chart.hpp,v 1000.2 2004/06/01 19:48:03 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Andrey Yazhuk
- *
- * File Description:
- *
- */
- #include <corelib/ncbistl.hpp>
- #include <gui/graph/igraph.hpp>
- #include <gui/graph/igraph_data.hpp>
- #include <gui/graph/legend.hpp>
- /** @addtogroup GUI_GRAPH
- *
- * @{
- */
- BEGIN_NCBI_SCOPE
- /////////////////////////////////////////////////////////////////////////////
- /// interface IComboChartDataSource
- // IComboChartDataSource represents a set of arrays of the same length. Each array
- // represents a series of data points. Labels Arrays contains names of series.
- class IComboChartDataSource : public IGraphDataSource
- {
- public:
- virtual int GetArraysCount() = 0;
- virtual IStringArray* GetLabelsArray() = 0; // one label for each array
-
- virtual INumericArray* GetValueArray(int iArray) = 0;
- virtual void CalculateMinMax(TModelUnit& Min, TModelUnit& Max) = 0;
- };
- ///////////////////////////////////////////////////////////////////////////////
- /// class CComboChart
- class NCBI_GUIGRAPH_EXPORT CComboChart : public CGraphBase, public ILegendDataSource
- {
- public:
- enum EGraphStyle
- {
- eLinePlot,
- eBarChart,
- eStackedBarChart,
- ePercentBarChart
- };
-
- CComboChart();
- virtual ~CComboChart();
- EGraphStyle GetStyle() const { return m_Style; }
- void SetStyle(EGraphStyle Style) { m_Style = Style; }
- // intreface for controlling drawing attributes
- CGlColor GetColor(int iSeries) const;
- void SetColor(int iSeries, CGlColor Color);
- void AssignAutoColors();
-
- CGraphDotMarker::EMarkerType GetMarkerType(int iSeries) const;
- void SetMarkerType(int iSeries, CGraphDotMarker::EMarkerType Type);
- void AssignAutoMarkers();
-
- // IGraph implementation
- virtual bool SetDataSource(IGraphDataSource* pDS);
- virtual void Render(CGlPane* pViewport);
-
- // ILegendDataSource implementation
- virtual bool ShowMarkers();
- virtual IStringArray* GetLabelArray();
- virtual IColorArray* GetColorArray();
- virtual INumericArray* GetMarkerArray();
- protected:
- IComboChartDataSource* GetComboChartDataSource()
- { return dynamic_cast<IComboChartDataSource*>(m_pDataSource); };
- virtual void CalculateLimits();
- CGlColor& x_GetColor(int iSeries);
- CGraphDotMarker::EMarkerType x_GetMarker(int iSeries) const;
-
- virtual void x_RenderLinePlot(int iStart, int iEnd, CGlPane* pPane);
- virtual void x_RenderBarChart(int iStart, int iEnd, CGlPane* pPane);
- virtual void x_RenderStackedBarChart(int iStart, int iEnd);
- virtual void x_RenderPercentBarChart(int iStart, int iEnd);
-
- private:
- //typedef CTypedArrayAdapter<IDataArray::eString> TStringAdapter;
- typedef CTypedArrayAdapter<IDataArray::eColor> TColorAdapter;
- typedef CTypedArrayAdapter<IDataArray::eNumeric, int> TIntAdapter;
- //TStringAdapter m_Labels;
- TColorAdapter m_Colors;
- TIntAdapter m_Markers;
- EGraphStyle m_Style;
- int m_MarkerSize;
- };
- inline CGlColor& CComboChart::x_GetColor(int iSeries)
- {
- return m_Colors.GetContainer()[iSeries];
- }
- inline CGraphDotMarker::EMarkerType CComboChart::x_GetMarker(int iSeries) const
- {
- return (CGraphDotMarker::EMarkerType) m_Markers.GetContainer()[iSeries];
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// class CComboChartDataSource
- class NCBI_GUIGRAPH_EXPORT CComboChartDataSource : public CSeriesBase,
- public IComboChartDataSource
- {
- public:
- typedef double TValueType;
- CComboChartDataSource(int ArrCount, int Length) : CSeriesBase(Length), m_ArrCount(ArrCount) {}
- // IScatterGraph interface
- virtual int GetArraysCount() { return x_GetArraysCount(); }
- virtual IStringArray* GetLabelsArray() { return x_GetStringArray(0); }
-
- virtual INumericArray* GetValueArray(int iArray) { return x_GetNumericArray(iArray+1); }
- virtual void CalculateMinMax(TModelUnit& Min, TModelUnit& Max);
- protected:
- typedef CTypedArrayAdapter<IDataArray::eNumeric, TValueType> TValueAdapter;
- typedef CTypedArrayAdapter<IDataArray::eString> TStringAdapter;
-
- public:
- typedef TStringAdapter::TCont TLabelCont;
- typedef TValueAdapter::TCont TValueCont;
-
- TLabelCont& GetLabelContainer() { return dynamic_cast<TStringAdapter*>(GetArray(0))->GetContainer(); }
- TValueCont& GetValueContainer(int iArray) { return dynamic_cast<TValueAdapter*>(GetArray(iArray+1))->GetContainer(); }
- virtual void CreateArrays();
-
- protected:
- int x_GetArraysCount() const { return m_vpArrays.size() - 1; }
- int m_ArrCount;
- };
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: combo_chart.hpp,v $
- * Revision 1000.2 2004/06/01 19:48:03 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
- *
- * Revision 1.7 2004/05/11 18:54:43 dicuccio
- * Added doxygen modules info
- *
- * Revision 1.6 2004/04/09 20:13:18 yazhuk
- * Made x_Render... functions virtual
- *
- * Revision 1.5 2004/03/24 20:33:42 gorelenk
- * Added missed export prefixes.
- *
- * Revision 1.4 2003/10/08 14:11:30 dicuccio
- * Code clean-up. Use <> instead of "" for #includes. Moved CGlPane into opengl.
- * Moved CGlPoint and CGlRect into opengl.
- *
- * Revision 1.3 2003/09/04 13:58:42 dicuccio
- * Added export specifiers. Inlined destructors of interface classes
- *
- * Revision 1.2 2003/08/10 14:11:18 dicuccio
- * Compilation fixes for gcc
- *
- * Revision 1.1 2003/08/08 16:01:35 yazhuk
- * Initial revision.
- *
- * ===========================================================================
- */
- #endif