Mobile API Reference  MicroStrategy 2019
ValuePlot.h
Go to the documentation of this file.
1 //====================================================================
2 // Filename: ValuePlot.h
3 // AUTHOR : Fangyao Ma, Dong Shi
4 // CREATION : 02/09/09
5 // Copyright (C) MicroStrategy, Inc. 2009
6 //====================================================================
7 
8 #ifndef MsiChart_ValuePlot_h
9 #define MsiChart_ValuePlot_h
10 
11 #include "ValueBasePlot.h"
12 #include "ValueAxis.h"
13 #include "GraphCollectionObject.h"
14 #include "TextObject.h"
15 #include "MarkerObject.h"
16 #include "DataLabelManager.h"
17 #include "PiePlotRenderer.h"
18 
19 namespace MsiChart
20 {
22  {
26  {}
27 
29  //bool mShowDataLabel; /// Show data label
30 
32 
37 
39 
41  std::vector<bool> mIsNullData; //<Indicate for each dp, is it a null data?
42  };
43 
44 
46  struct LabelInfo
47  {
48  bool mIsPut; //<Whether this label is already been 'Smarted'
49  bool mIsClockWise; //< The flag indicate which direction the intuitive try-out will take in.
50  bool mIsValid; //Is Hosting marker valid : null data, etc.
51 
54 
55  Rect2D mHostMarker; //< The position for its hosting marker
56 
57  EnumDSSGraphDataTextPosition mSuggestedStart; //< The suggested starting position for this label
58  EnumDSSGraphFontRotation mLabelRotation; //< rotation info, unsupported yet, leave for future.
60 
63  {}
64 
66  {
67  return mSuggestedStart != iUserSetting;
68  }
69 
71  {
72  Rect2D lRect;
73  mLabelPtr->GetBoundingRect(lRect);
74  return lRect;
75  }
76  };
77 
78  typedef std::vector<LabelInfo> LabelMatrix;
79 
80  typedef enum
81  {
82  VI_X = 0,
83  VI_Y = 1,
84  VI_Z = 2,
86 
87 
88 
89  class ValuePlot: public ValueBasePlot
90  {
91  public:
93  typedef std::vector<std::vector<Point2D> > PointMatrix;
94  typedef std::vector<std::vector<Rect2D> > RecMatrix;
95  ValuePlot(const TripleId& irTripleId, GraphObjectManager* ipManager, const Rect2D& irDataArea);
96 
97  //pure virtual functions from GraphObjectManager
98  virtual void GenerateMapAndList();
99  virtual void GetOptions(Int32 iSeriesId, Int32 iPropertyId, CComVariant* opValue) const;
100 
101  //override functions
102  virtual void Draw();
103  virtual void GenerateView();
104  virtual GraphObject::Ptr OnPointDetection(const Point2D& irCursor) const;
105  virtual void OnRectangleSelection(const Rect2D& irRect, std::vector<GraphObject::Ptr>& iorSelectedObjects) const;
106  virtual void GenerateImageMap(ImageMap& iorImageMap);
107  virtual void RefreshValueAxis(const std::map<Int32, std::pair<double, double> >& irScaleSet, const Rect2D& irRect);
108 
109  //assign the input ValueAxis pointer to proper data memebers
114  virtual void AssignValueAxis(ValueAxis::Ptr iValueAxisPtr, Int32 iIndex);
115 
116  //Populate the series information for the hosting ValuePlot object, called by ValuePlot manager
121  virtual void AssignSeriesInfo(const std::vector<Int32>& irSeriesIndex,
122  const std::vector<Int32>& irVecSeriesVAIndex);
123 
124  //Graph Matrix Padding Required.
125  virtual Int32 GetMaxElementRadius();
126 
127  //Get the radius/offset that is clipped by chart boundary
133  virtual bool GetMaxElementOffsetClippedByBoundary(bool iIsOnXAxis, double& orLowOffset, double& orHighOffset);
134 
135  //AxisOriginLine support
136  void CreateAxisOriginLine();
138  protected:
139  void LoadProperties();
140 
141  //helper function to generate collection objects for later use
145  void hGenerateCollection(std::vector<GraphCollectionObject::Ptr>& orLineCollection);
146 
147  //helper function to generate data-connection lines for one series, denote by the SeriesIndex
153  void hCreateConnectionPolyLine(std::vector<Point2D>& irCoordPoints, Int32 iSeriesIndex, GraphCollectionObject* ipCollection);
154 
155  //helper function to generate Custome lines for Y1 Axis (, Y2 (if dual axis ) ) and X Axis held by this plot.
156  void hGenerateCustomeLine();
157 
158  //helper function to generate data markers for one series specified by iSeriesIndex in one chart area.
166  void hGenerateMarker(RecMatrix& iorRecMatrix, std::vector<Point2D>& irCoordPoints, std::vector<Int32>& irMarkerSizes, Int32 iSeriesIndex, GraphCollectionObject* ipCollection, std::vector<GraphObject::Ptr>& ioShapeList);
167 
168 
169  std::vector<GraphObject::Ptr > hGenerateMarkersForOneDataPoint(Int32 iSeriesIndex, Int32 iGroupId, Point2D& irCoordPoint, Int32 iMarkerSize, GraphCollectionObject* ipCollection, std::vector<GraphObject::Ptr>& ioShaperList);
170  GraphCollectionObject* hPickCollectionForGM(Int32 iIndex, std::vector<GraphCollectionObject::Ptr>& irCollections);
171 
172 
173  //overloaded function:used for scatter chart
177  //void hGenerateMarker(RecMatrix& iorRecMatrix, std::vector<Point2D>& irCoordPoints, Int32 iScatterMarkerSize, Int32 iSeriesIndex, GraphCollectionObject* ipCollection);
178 
179  //helper function to generate trendlines for all the series held by this plot.
180  void hCreateTrendLine();
181  void hCreateGMTrendLine();
182  void hCreateRefLines();
183  Int32 hGetRefLineDir(Int32 iSeriesInfoIndex);
184  TextObject::Ptr hCreateRefLineLable(Int32 iAxisIndex, Int32 iRefLineIndex);
185  ValueAxis::Ptr hGetValueAxis(Int32 iAxisIndex); //GM Support
186 
187  //helper function to generate the data labels for all the series held by this plot
191  void hGenerateDatalabels(RecMatrix& irRecMatrix, GraphCollectionObject* ipColPtr = NULL);
192 
193 
195  void hCreateDataLabelCollection(std::vector<GraphCollectionObject::Ptr>& iorCollections);
198  void hInitDataLabels(const std::vector<std::vector<Rect2D> >& irMarkerMatrix, std::vector<GraphCollectionObject::Ptr>& iorCollections);
199 
201  bool hIsUseCustomMinMax();
202  bool hIsHostMarkerInDataAreaWithCustomMinMax(const Rect2D& irHostMarker);
203 
205  //stage one : Greedy
206  void hCreateSmartLabelCollection(std::vector<GraphCollectionObject::Ptr>& iorCollections);
207  void hInitLabelMatrix(const std::vector<std::vector<Rect2D> >& irMarkerMatrix, std::vector<GraphCollectionObject::Ptr>& iorCollections);
208  void hGetMarkerRectSet(const std::vector<std::vector<Rect2D> >&irRectMatrix, std::vector<Rect2D>& orRectSet) const;
209  bool hIsFallOut(const Rect2D& irLabelRect);
210  Int32 hIsOverlapped(const Rect2D& irLabelRect, std::vector<Rect2D>& irTargetSet, bool iIsTiltRect = false, bool iIsTiltTargets = false);
211  Int32 hIsOverlapped(const LabelInfo& irLabelInfo, std::vector<Rect2D>& irTargetSet, bool iIsTiltTargets = false);
212  Int32 hGreedyPlacer(std::vector<Rect2D>& irMarkerRectSet, std::vector<Rect2D>& iorLabelRectSet, GraphCollectionObject::Ptr iLabelLinesPtr = NULL);
213  bool hPlaceOneLabel(LabelInfo& iorLabel, std::vector<Rect2D>& irMarkerRectSet, std::vector<Rect2D>& iorLabelRectSet, GraphCollectionObject::Ptr iLabelLinesPtr = NULL);
214 
215  //post stage one: Heuristic
216  //bool hHeuristicAdjust(LabelInfo& iorLabel, std::vector<Rect2D>& irMarkerRectSet, std::vector<Rect2D>& iorLabelRectSet, std::vector<Rect2D>& iorTiltLabelRectSet);//< for adjustment
217  //Int32 hGetSuggestedStep(LabelInfo& iorLabel);
218 
219  //stage two: Grid Slicing & placement
220  void hGetSuggestedSliceUnit(Rect2D& orRect);//get the unit rect
221  bool hInitGridMapOccupation(GridMap &iorGridMap); //inital occupation work
222  //bool hAllocateFreeSpace(GridMap &iorGridMap);
223  bool hPlaceLeftOversIntoFreeSpace(GridMap &iorGridMap, GraphCollectionObject::Ptr iLabelLinesPtr = NULL);
224  void hPlaceLeftOvers(GraphCollectionObject::Ptr iLabelLinesPtr);//place all the labels that does not stand a chance to avoid any overlapps
225 
226  //Data label line for smart label
227  bool hGenerateFeelerForOneLabel(LabelInfo& irLabelInfo, GraphCollectionObject* iopCollection, Int32 iSpace = 0);
228 
229  //Get the the offset clipped out of by chart boundary
230  void hGetClippedOffset(double iLowBoundary, double iHighBoundary,
231  double iRadius, const Point2D& irMarkerCenter,
232  bool isXAxis, double& orLowOffset, double& orHighOffset);
233 
234 
235 
236  private:
237 
238  //Find the correct series index for the input series id. 0 will be retruned if there is no match between the input and any series ids.
243  Int32 hFindSeriesInfoID(Int32 iSeriesID) const;
244 
245  //helper function used when generating data labels, just to retrieve the data format.
252  void hGetVAFormattedText(Int32 iSeriesInfoIndex, Int32 iGroupID, EnumValueIndex iVAIndex, MBase::String& orText, GraphCollectionObject* ipCollection = NULL);
253  void hGetGridCellFormattedText(Int32 iSeriesInfoIndex, Int32 iGroupID,EnumValueIndex iVAIndex, MBase::String& orText, GraphCollectionObject* ipCollection = NULL);
254  //helper fuction used when generating markers, to compute the data marker size
262  bool hGetMarkerSize(Int32& orMarkerSize, double& orMarkerSizeValue, Int32 iSeriesInfoIndex, Int32 iGroupId = -3);
263 
264  //helper fuction used to compute the maker position
271  bool hGetMarkerPositon(Int32 iSeriesInfoIndex, Int32 iGroupId, Point2D& orPosition);
272 
273  //helper function to generate the data label for one data group (<x,y> for scatter, <x,y,z> for bubble) of this plot
280  TextObject::Ptr hCreateDataLabel(Int32 iSeriesInfoIndex, Int32 iGroupID, GraphCollectionObject* ipCollection);
281 
282  //helper function to generate the data label for scatter chart, called by hCreateDataLabel
289  TextObject::Ptr hCreateDataLabelForScatter(Int32 iSeriesInfoIndex, Int32 iGroupID, GraphCollectionObject* ipCollection);
290 
291  //helper function to generate the data label for bubble chart, called by hCreateDataLabel
298  TextObject::Ptr hCreateDataLabelForBubble(Int32 iSeriesInfoIndex, Int32 iGroupID, GraphCollectionObject* ipCollection);
299 
300  //helper function to generate the data label for bubble and scatter chart only for Graph Matrix
307  TextObject::Ptr hCreateDataLabelForGraphMatrix(Int32 iSeriesInfoIndex, Int32 iGroupID, GraphCollectionObject* ipCollection);
308 
309  //helper function to move the data labels to a decent position around the its hosting data marker.
315  void hMoveDataLabel(TextObject* ipText, const Rect2D& irRefRect, EnumDSSGraphFontRotation iRotation = DssGraphFontRotateNormal, GraphCollectionObject* ipCollection = NULL);
316  void hGetFeelerLinePosition(Point2D& orVexOnMarker, Point2D& orVexOnLabel, const Rect2D& irMarkerRect, Int32 iSpace, EnumDSSGraphDataTextPosition iLocation);
317  void hGetFeelerLinePosition(Point2D& orVexOnMarker, Point2D& orVexOnLabel, const Rect2D& irMarkerRect, const Rect2D& irLabelRect);
318 
319  Int32 hPutDataLabel(TextObject* ipText, const Rect2D& irRefRect, EnumDSSGraphFontRotation iRotation = DssGraphFontRotateNormal, EnumDSSGraphDataTextPosition iLabelLocation = DssGraphDTPositionCenter);
320  Int32 hPutDataLabel(TextObject* ipText, const Rect2D& irRefRect, const Point2D& irTargetPoint, EnumDSSGraphFontRotation iRotation = DssGraphFontRotateNormal); //used for smart label
321  void hPutDataLabel(TextObject* ipText, const Rect2D& irHostMarkerBound, EnumDssGraphMatrixDataLabelPosition irLocation); //use for data label, to get the data label position
322 
323  //Max Y marker
324  TripleId mMaxYMarker;
325 
326  //helper function : get the max radius for one marker if we slice the plot area by those number of markers
327  /*
328  @return the max radius for the unit.
329  */
330  Int32 hGetMaxRadiusForUnitInDevice();
331 
341  Int32 hGetAdjustedMarkerRadius(const Rect2D& iDataArea, Int32 iXUnitCount, Int32 iYUnitCount, bool iIsGeneric = true);
342 
343  ValueAxis::Ptr hGetValueAxisPtrByIndex(Int32 iIndex) const;
344  void hGetOneAxisOriginLable(ValueAxis::Ptr iXValueAxis ,ValueAxis::Ptr iYValueAxis , std::vector<Point2D>& orLablePointVec, std::vector<MBase::String>& orLableTextVec);
345 
346  Int32 mMaxUnitRadius;
347  bool mDataLabelLine;
348  bool mIsBubbleChart;
349  bool mIsSmarted;
350  double mMaxRadius;
351  bool mIsDrawBySize;
352 
353 
354  Int32 mLabelFormat;
355  EnumDSSGraphDataTextPosition mLabelLocation;
356  ValueAxis::Ptr mXAxisPtr;
357  ValueAxis::Ptr mX2AxisPtr;
358  ValueAxis::Ptr mY1AxisPtr;
359  ValueAxis::Ptr mY2AxisPtr;
360  ValueAxis::Ptr mZAxisPtr;
361  std::vector<ScatterSeriesInfo> mVecSeriesInfo;
362  std::vector<Rect2D> mStandAloneMarkers; //< A set of marker with no labels shown.
363  LabelMatrix mLabelMatrix; //< label matrix for smart label
364  GMDataLabelVecs mDataLabelVec;
365 
366  // GM TrendLine Support
367  std::vector<GraphTrendLineOptions> mGMTrendLineOption;
368  void LoadGMTrendLineProperties(Int32 iGroupId);
369 
370  PiePlotRenderer::Ptr mPieRender;
371 
373  //member methods <for heuristic adjustment
374  bool hIsOverlappedWithHLine(const Point2D& irStart, const Point2D& irEnd, const Point2D& irHStart, const Point2D& irHEnd) const;
375  bool hIsOverlappedWithVLine(const Point2D& irStart, const Point2D& irEnd, const Point2D& irVStart, const Point2D& irVEnd) const;
376  bool hIsTiltLineOverlappedWithNormalRect(const Point2D& irStart, const Point2D& irEnd, const std::vector<Point2D>& irPoints) const;
377  void hGetPrecisePointsForTiltRect(const LabelInfo& irLabelInfo, std::vector<Point2D>& orPoints);
378 
379 
381  void hFactoryHandleDataLabels(std::vector<std::vector<Rect2D> >& irVecMarkerRectangle, bool isDataLabelPossible);
382 
383  };
384 
385  inline bool ComparisionOfScatterLabelInfo(const LabelInfo& iFirst, const LabelInfo& iSecond)
386  {
387  return iFirst.mHostMarker.x < iSecond.mHostMarker.x;
388  }
389 
390 
391 }
392 #endif
MSynch::SmartPtr< ValuePlot > Ptr
Definition: ValuePlot.h:92
ScatterSeriesInfo()
Definition: ValuePlot.h:23
Definition: ValueBasePlot.h:16
EnumDSSGraphDataTextPosition mSuggestedStart
Definition: ValuePlot.h:57
LabelInfo()
Definition: ValuePlot.h:61
Definition: ValuePlot.h:21
bool mShowSmartLabel
Connect the series line.
Definition: ValuePlot.h:31
EnumValueIndex
Definition: ValuePlot.h:80
bool hInitGridMapOccupation(GridMap &iorGridMap)
virtual void GenerateMapAndList()
Int32 mMarkerShape
Marker Size.
Definition: ValuePlot.h:34
virtual void GenerateImageMap(ImageMap &iorImageMap)
virtual void Draw()
std::vector< GraphObject::Ptr > hGenerateMarkersForOneDataPoint(Int32 iSeriesIndex, Int32 iGroupId, Point2D &irCoordPoint, Int32 iMarkerSize, GraphCollectionObject *ipCollection, std::vector< GraphObject::Ptr > &ioShaperList)
bool ComparisionOfScatterLabelInfo(const LabelInfo &iFirst, const LabelInfo &iSecond)
Definition: ValuePlot.h:385
bool hIsFallOut(const Rect2D &irLabelRect)
bool mIsPut
Definition: ValuePlot.h:48
bool hPlaceOneLabel(LabelInfo &iorLabel, std::vector< Rect2D > &irMarkerRectSet, std::vector< Rect2D > &iorLabelRectSet, GraphCollectionObject::Ptr iLabelLinesPtr=NULL)
Definition: GraphCollectionObject.h:19
void hCreateDataLabelCollection(std::vector< GraphCollectionObject::Ptr > &iorCollections)
ValueAxis::Ptr hGetValueAxis(Int32 iAxisIndex)
Int32 mMarkerSize
Show smart label.
Definition: ValuePlot.h:33
GraphCollectionObject * hPickCollectionForGM(Int32 iIndex, std::vector< GraphCollectionObject::Ptr > &irCollections)
Int32 hIsOverlapped(const Rect2D &irLabelRect, std::vector< Rect2D > &irTargetSet, bool iIsTiltRect=false, bool iIsTiltTargets=false)
ValuePlot(const TripleId &irTripleId, GraphObjectManager *ipManager, const Rect2D &irDataArea)
Definition: ValuePlot.h:83
Definition: ValuePlot.h:89
Definition: GridMap.h:39
EnumDSSGraphDataTextPosition
Definition: DSSIPhoneEnums.h:1836
Definition: DSSIPhoneEnums.h:1706
void hCreateSmartLabelCollection(std::vector< GraphCollectionObject::Ptr > &iorCollections)
TextObject::Ptr mLabelPtr
Definition: ValuePlot.h:59
void CreateAxisOriginLineLabels()
virtual bool GetMaxElementOffsetClippedByBoundary(bool iIsOnXAxis, double &orLowOffset, double &orHighOffset)
virtual GraphObject::Ptr OnPointDetection(const Point2D &irCursor) const
bool hIsHostMarkerInDataAreaWithCustomMinMax(const Rect2D &irHostMarker)
#define Int32
Definition: BasicTypes.h:20
bool mIsValid
Definition: ValuePlot.h:50
[refactory] Maybe in future, we may use this also for the normal case
Definition: ValuePlot.h:46
Definition: TextObject.h:181
Int32 mSeriesID
Value axis index - X1 or X2.
Definition: ValuePlot.h:38
std::vector< std::vector< Rect2D > > RecMatrix
Definition: ValuePlot.h:94
virtual void AssignSeriesInfo(const std::vector< Int32 > &irSeriesIndex, const std::vector< Int32 > &irVecSeriesVAIndex)
void hInitDataLabels(const std::vector< std::vector< Rect2D > > &irMarkerMatrix, std::vector< GraphCollectionObject::Ptr > &iorCollections)
void hPrepareDataLabelPositions()
void hPlaceLeftOvers(GraphCollectionObject::Ptr iLabelLinesPtr)
bool mConnectDataPoint
Definition: ValuePlot.h:28
virtual Int32 GetMaxElementRadius()
int x
X-coordinate of left edge.
Definition: Rect2D.h:122
Definition: ValuePlot.h:84
void hCreateConnectionPolyLine(std::vector< Point2D > &irCoordPoints, Int32 iSeriesIndex, GraphCollectionObject *ipCollection)
virtual void OnRectangleSelection(const Rect2D &irRect, std::vector< GraphObject::Ptr > &iorSelectedObjects) const
void hInitLabelMatrix(const std::vector< std::vector< Rect2D > > &irMarkerMatrix, std::vector< GraphCollectionObject::Ptr > &iorCollections)
EnumDSSGraphFontRotation
Definition: DSSIPhoneEnums.h:1704
virtual void GetBoundingRect(Rect2D &orBoundingRect) const
bool hPlaceLeftOversIntoFreeSpace(GridMap &iorGridMap, GraphCollectionObject::Ptr iLabelLinesPtr=NULL)
Definition: DSSIPhoneEnums.h:1838
virtual void GetOptions(Int32 iSeriesId, Int32 iPropertyId, CComVariant *opValue) const
bool mIsClockWise
Definition: ValuePlot.h:49
std::basic_string< WCHAR, std::char_traits< WCHAR >, Allocator< WCHAR > > String
Definition: BaseString.h:26
Definition: ValuePlot.h:82
Definition: ABLPlot.h:21
std::vector< AreaRec * > ImageMap
Definition: ImageMap.h:99
Rect2D ToRectangle()
Definition: ValuePlot.h:70
Int32 mGroupId
Definition: ValuePlot.h:53
EnumDssGraphMatrixDataLabelPosition
Definition: Common.h:131
void hGetMarkerRectSet(const std::vector< std::vector< Rect2D > > &irRectMatrix, std::vector< Rect2D > &orRectSet) const
Definition: Msi_ccomvariant.h:24
void hGetClippedOffset(double iLowBoundary, double iHighBoundary, double iRadius, const Point2D &irMarkerCenter, bool isXAxis, double &orLowOffset, double &orHighOffset)
std::vector< GMDataLabelInfo > GMDataLabelVecs
Definition: DataLabelManager.h:93
void hGenerateDatalabels(RecMatrix &irRecMatrix, GraphCollectionObject *ipColPtr=NULL)
GraphTrendLineOptions mTrendLineOptions
Series ID.
Definition: ValuePlot.h:40
void hGetSuggestedSliceUnit(Rect2D &orRect)
EnumDSSGraphFontRotation mLabelRotation
Definition: ValuePlot.h:58
Rect2D mHostMarker
Definition: ValuePlot.h:55
bool hGenerateFeelerForOneLabel(LabelInfo &irLabelInfo, GraphCollectionObject *iopCollection, Int32 iSpace=0)
std::vector< std::vector< Point2D > > PointMatrix
Definition: ValuePlot.h:93
Int32 mXValueAxisIndex
Value axis index - Y1 or Y2.
Definition: ValuePlot.h:36
Definition: DSSIPhoneEnums.h:1839
Int32 mValueAxisIndex
Marker Shape.
Definition: ValuePlot.h:35
bool IsMoved(EnumDSSGraphDataTextPosition iUserSetting)
Definition: ValuePlot.h:65
void hGenerateCollection(std::vector< GraphCollectionObject::Ptr > &orLineCollection)
Int32 hGreedyPlacer(std::vector< Rect2D > &irMarkerRectSet, std::vector< Rect2D > &iorLabelRectSet, GraphCollectionObject::Ptr iLabelLinesPtr=NULL)
TextObject::Ptr hCreateRefLineLable(Int32 iAxisIndex, Int32 iRefLineIndex)
#define NULL
Definition: Null.h:10
virtual void RefreshValueAxis(const std::map< Int32, std::pair< double, double > > &irScaleSet, const Rect2D &irRect)
Definition: GraphObjectManager.h:37
DataLabelManager::Ptr hInitDataLabelManager()
Use four Int32 values to represent a 2D rectangle.
Definition: Rect2D.h:25
virtual void GenerateView()
Definition: Plot.h:30
void hGenerateMarker(RecMatrix &iorRecMatrix, std::vector< Point2D > &irCoordPoints, std::vector< Int32 > &irMarkerSizes, Int32 iSeriesIndex, GraphCollectionObject *ipCollection, std::vector< GraphObject::Ptr > &ioShapeList)
std::vector< bool > mIsNullData
Definition: ValuePlot.h:41
virtual void AssignValueAxis(ValueAxis::Ptr iValueAxisPtr, Int32 iIndex)
std::vector< LabelInfo > LabelMatrix
Definition: ValuePlot.h:78
Int32 mSeriesId
Definition: ValuePlot.h:52
Definition: Common.h:397
Int32 hGetRefLineDir(Int32 iSeriesInfoIndex)