VTK
vtkChartXY.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkChartXY.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
27 #ifndef vtkChartXY_h
28 #define vtkChartXY_h
29 
30 #include "vtkChart.h"
31 #include "vtkChartsCoreModule.h" // For export macro
32 #include "vtkContextPolygon.h" // For vtkContextPolygon
33 #include "vtkSmartPointer.h" // For SP ivars
34 #include "vtkVector.h" // For vtkVector2f in struct
35 
36 class vtkPlot;
37 class vtkAxis;
38 class vtkPlotGrid;
39 class vtkChartLegend;
40 class vtkTooltipItem;
41 class vtkChartXYPrivate; // Private class to keep my STL vector in...
42 
43 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
44 {
45 public:
46  vtkTypeMacro(vtkChartXY, vtkChart);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
52  static vtkChartXY* New();
53 
59  void Update() override;
60 
64  bool Paint(vtkContext2D* painter) override;
65 
69  vtkPlot* AddPlot(int type) override;
70 
74  vtkIdType AddPlot(vtkPlot* plot) override;
75 
80  bool RemovePlot(vtkIdType index) override;
81 
85  void ClearPlots() override;
86 
90  vtkPlot* GetPlot(vtkIdType index) override;
91 
96  virtual vtkIdType GetPlotIndex(vtkPlot*);
97 
103  vtkIdType RaisePlot(vtkPlot* plot);
104 
111  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
112 
118  vtkIdType LowerPlot(vtkPlot* plot);
119 
126  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
127 
131  vtkIdType GetNumberOfPlots() override;
132 
136  int GetPlotCorner(vtkPlot* plot);
137 
141  void SetPlotCorner(vtkPlot* plot, int corner);
142 
148  vtkAxis* GetAxis(int axisIndex) override;
149 
153  void SetShowLegend(bool visible) override;
154 
158  vtkChartLegend* GetLegend() override;
159 
163  virtual void SetTooltip(vtkTooltipItem* tooltip);
164 
168  virtual vtkTooltipItem* GetTooltip();
169 
173  vtkIdType GetNumberOfAxes() override;
174 
179  void RecalculateBounds() override;
180 
188  void SetSelectionMethod(int method) override;
189 
191 
194  vtkSetMacro(DrawAxesAtOrigin, bool);
195  vtkGetMacro(DrawAxesAtOrigin, bool);
196  vtkBooleanMacro(DrawAxesAtOrigin, bool);
198 
200 
204  vtkSetMacro(AutoAxes, bool);
205  vtkGetMacro(AutoAxes, bool);
206  vtkBooleanMacro(AutoAxes, bool);
208 
210 
213  vtkSetMacro(HiddenAxisBorder, int);
214  vtkGetMacro(HiddenAxisBorder, int);
216 
218 
223  vtkSetMacro(ForceAxesToBounds, bool);
224  vtkGetMacro(ForceAxesToBounds, bool);
225  vtkBooleanMacro(ForceAxesToBounds, bool);
227 
229 
236  vtkSetMacro(BarWidthFraction, float);
237  vtkGetMacro(BarWidthFraction, float);
239 
241 
247  vtkSetMacro(ZoomWithMouseWheel, bool);
248  vtkGetMacro(ZoomWithMouseWheel, bool);
249  vtkBooleanMacro(ZoomWithMouseWheel, bool);
251 
253 
258  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
259  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
260  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
262 
264 
269  vtkSetMacro(DragPointAlongX, bool);
270  vtkGetMacro(DragPointAlongX, bool);
271  vtkBooleanMacro(DragPointAlongX, bool);
273 
275 
280  vtkSetMacro(DragPointAlongY, bool);
281  vtkGetMacro(DragPointAlongY, bool);
282  vtkBooleanMacro(DragPointAlongY, bool);
284 
288  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
289  vtkIdType segmentIndex = -1);
290 
294  bool Hit(const vtkContextMouseEvent& mouse) override;
295 
299  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
300 
304  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
305 
309  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
310 
314  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
315 
319  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
320 
324  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
325 
329  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
330 
331 protected:
332  vtkChartXY();
333  ~vtkChartXY() override;
334 
338  void RecalculatePlotTransforms();
339 
344  void RecalculatePlotBounds();
345 
349  void ReleasePlotSelections();
350 
356  virtual bool UpdateLayout(vtkContext2D* painter);
357 
363  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
364 
369  virtual void SetLegendPosition(const vtkRectf& rect);
370 
375 
380 
385 
390 
394  bool DrawBox;
395 
401 
406 
411 
418 
422  bool AutoAxes;
423 
428 
434 
441 
447 
453 
459 
460 private:
461  vtkChartXY(const vtkChartXY&) = delete;
462  void operator=(const vtkChartXY&) = delete;
463 
464  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
465 
470  bool DragPoint;
471 
475  void CalculateBarPlots();
476 
482  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
483 
484  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
485  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
486 
490  bool RemovePlotFromCorners(vtkPlot* plot);
491 
492  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* orign, float* max);
493 
497  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
498  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
499  vtkContextPolygon& polygon);
500 };
501 
503 
509 {
513  int Index;
514 };
516 
517 #endif // vtkChartXY_h
bool DrawAxesAtOrigin
Keep the axes drawn at the origin? This will attempt to keep the axes drawn at the origin,...
Definition: vtkChartXY.h:417
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
data structure to represent key events.
virtual void SetShowLegend(bool visible)
Set/get whether the chart should draw a legend.
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
Mouse button down event Return true if the item holds the event, false if the event can be propagated...
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition: vtkChartXY.h:452
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition: vtkChartXY.h:400
virtual vtkIdType GetNumberOfAxes()
Get the number of axes in the current chart.
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition: vtkChartXY.h:440
bool Paint(vtkContext2D *painter) override=0
Paint event for the chart, called whenever the chart needs to be drawn.
virtual void RecalculateBounds()
Request that the chart recalculates the range of its axes.
int vtkIdType
Definition: vtkType.h:345
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:427
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:405
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:389
vtkStdString SeriesName
Definition: vtkChartXY.h:510
virtual void ClearPlots()
Remove all plots from the chart.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
Factory class for drawing 2D charts.
Definition: vtkChart.h:44
virtual bool RemovePlot(vtkIdType index)
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta)
Mouse wheel event, positive delta indicates forward movement of the wheel.
takes care of drawing 2D axes
Definition: vtkAxis.h:68
data structure to represent mouse events.
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:512
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
a simple class to control print indentation
Definition: vtkIndent.h:33
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:394
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:405
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
virtual vtkIdType GetNumberOfPlots()
Get the number of plots the chart contains.
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:46
vtkVector2f Position
Definition: vtkChartXY.h:511
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:374
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse)
Mouse enter event.
bool DragPointAlongX
Properties to enable the drag of a point for the ClickAndDrag Action.
Definition: vtkChartXY.h:457
Factory class for drawing XY charts.
Definition: vtkChartXY.h:43
draw the chart legend
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition: vtkChartXY.h:508
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
bool DragPointAlongY
Definition: vtkChartXY.h:458
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:38
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
virtual vtkPlot * GetPlot(vtkIdType index)
Get the plot at the specified index, returns null if the index is invalid.
bool ZoomWithMouseWheel
Property to enable zooming the chart with the mouse wheel.
Definition: vtkChartXY.h:446
takes care of drawing 2D axes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:422
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition: vtkChartXY.h:379
float BarWidthFraction
The fraction of the interval taken up along the x axis by any bars that are drawn on the chart.
Definition: vtkChartXY.h:433
virtual void SetSelectionMethod(int method)
Set the selection method, which controls how selections are handled by the chart.
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse)
Mouse leave event.
virtual vtkPlot * AddPlot(int type)
Add a plot to the chart, defaults to using the name of the y column.
#define max(a, b)
virtual vtkAxis * GetAxis(int axisIndex)
Get the axis specified by axisIndex.
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition: vtkChartXY.h:410
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:384