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 
155  virtual void SetAxis(int axisIndex, vtkAxis*) override;
156 
160  void SetShowLegend(bool visible) override;
161 
165  vtkChartLegend* GetLegend() override;
166 
170  virtual void SetTooltip(vtkTooltipItem* tooltip);
171 
175  virtual vtkTooltipItem* GetTooltip();
176 
180  vtkIdType GetNumberOfAxes() override;
181 
186  void RecalculateBounds() override;
187 
195  void SetSelectionMethod(int method) override;
196 
200  void RemovePlotSelections();
201 
203 
206  vtkSetMacro(DrawAxesAtOrigin, bool);
207  vtkGetMacro(DrawAxesAtOrigin, bool);
208  vtkBooleanMacro(DrawAxesAtOrigin, bool);
210 
212 
216  vtkSetMacro(AutoAxes, bool);
217  vtkGetMacro(AutoAxes, bool);
218  vtkBooleanMacro(AutoAxes, bool);
220 
222 
225  vtkSetMacro(HiddenAxisBorder, int);
226  vtkGetMacro(HiddenAxisBorder, int);
228 
230 
235  vtkSetMacro(ForceAxesToBounds, bool);
236  vtkGetMacro(ForceAxesToBounds, bool);
237  vtkBooleanMacro(ForceAxesToBounds, bool);
239 
241 
248  vtkSetMacro(BarWidthFraction, float);
249  vtkGetMacro(BarWidthFraction, float);
251 
253 
259  vtkSetMacro(ZoomWithMouseWheel, bool);
260  vtkGetMacro(ZoomWithMouseWheel, bool);
261  vtkBooleanMacro(ZoomWithMouseWheel, bool);
263 
265 
270  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
271  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
272  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
274 
276 
281  vtkSetMacro(DragPointAlongX, bool);
282  vtkGetMacro(DragPointAlongX, bool);
283  vtkBooleanMacro(DragPointAlongX, bool);
285 
287 
292  vtkSetMacro(DragPointAlongY, bool);
293  vtkGetMacro(DragPointAlongY, bool);
294  vtkBooleanMacro(DragPointAlongY, bool);
296 
300  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
301  vtkIdType segmentIndex = -1);
302 
306  bool Hit(const vtkContextMouseEvent& mouse) override;
307 
311  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
312 
316  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
317 
321  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
322 
326  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
327 
331  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
332 
336  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
337 
341  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
342 
343 protected:
344  vtkChartXY();
345  ~vtkChartXY() override;
346 
350  void RecalculatePlotTransforms();
351 
356  void RecalculatePlotBounds();
357 
363  virtual bool UpdateLayout(vtkContext2D* painter);
364 
370  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
371 
376  virtual void SetLegendPosition(const vtkRectf& rect);
377 
382 
387 
392 
397 
401  bool DrawBox;
402 
408 
413 
418 
425 
429  bool AutoAxes;
430 
435 
441 
448 
454 
460 
466 
467 private:
468  vtkChartXY(const vtkChartXY&) = delete;
469  void operator=(const vtkChartXY&) = delete;
470 
471  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
472 
477  bool DragPoint;
478 
482  void CalculateBarPlots();
483 
489  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
490 
491  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
492  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
493 
497  bool RemovePlotFromCorners(vtkPlot* plot);
498 
499  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* orign, float* max);
500 
505  void ReleasePlotSelections();
506 
510  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
511  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
512  vtkContextPolygon& polygon);
513 };
514 
516 
522 {
526  int Index;
527 };
529 
530 #endif // vtkChartXY_h
vtkChart
Factory class for drawing 2D charts.
Definition: vtkChart.h:44
vtkChart::GetNumberOfPlots
virtual vtkIdType GetNumberOfPlots()
Get the number of plots the chart contains.
vtkChartXY::MouseBox
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:396
vtkContextPolygon.h
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:34
vtkChart::RemovePlot
virtual bool RemovePlot(vtkIdType index)
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:34
vtkChart::SetSelectionMethod
virtual void SetSelectionMethod(int method)
Set the selection method, which controls how selections are handled by the chart.
vtkChartXY::Legend
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:381
vtkX3D::type
Definition: vtkX3D.h:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkChartPlotData
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition: vtkChartXY.h:521
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:45
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkX3D::key
Definition: vtkX3D.h:257
vtkChartLegend
draw the chart legend
Definition: vtkChartLegend.h:39
vtkChart.h
vtkAbstractContextItem::KeyPressEvent
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkChartPlotData::SeriesName
vtkStdString SeriesName
Definition: vtkChartXY.h:523
vtkChartXY::Tooltip
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition: vtkChartXY.h:386
vtkSmartPointer< vtkChartLegend >
vtkVector.h
vtkTooltipItem
takes care of drawing 2D axes
Definition: vtkTooltipItem.h:39
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkChart::SetAxis
virtual void SetAxis(int axisIndex, vtkAxis *)
Set the axis specified by axisIndex.
vtkChart::AddPlot
virtual vtkPlot * AddPlot(int type)
Add a plot to the chart, defaults to using the name of the y column.
vtkChartXY::DragPointAlongX
bool DragPointAlongX
Properties to enable the drag of a point for the ClickAndDrag Action.
Definition: vtkChartXY.h:464
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:46
vtkChartXY::AutoAxes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:429
vtkChartXY::BarWidthFraction
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:440
vtkChartXY::DrawNearestPoint
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition: vtkChartXY.h:417
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkVector2d
Definition: vtkVector.h:424
vtkChartXY::ZoomWithMouseWheel
bool ZoomWithMouseWheel
Property to enable zooming the chart with the mouse wheel.
Definition: vtkChartXY.h:453
vtkX3D::position
Definition: vtkX3D.h:261
vtkChart::Paint
bool Paint(vtkContext2D *painter) override=0
Paint event for the chart, called whenever the chart needs to be drawn.
vtkChartXY::DragPointAlongY
bool DragPointAlongY
Definition: vtkChartXY.h:465
vtkChartXY::DrawAxesAtOrigin
bool DrawAxesAtOrigin
Keep the axes drawn at the origin? This will attempt to keep the axes drawn at the origin,...
Definition: vtkChartXY.h:424
vtkChart::GetLegend
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
vtkPlotGrid
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:38
vtkChartXY::AdjustLowerBoundForLogPlot
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition: vtkChartXY.h:459
vtkChartXY::ForceAxesToBounds
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition: vtkChartXY.h:447
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkChartXY::PlotTransformValid
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:391
vtkAbstractContextItem::Hit
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
vtkChart::GetPlot
virtual vtkPlot * GetPlot(vtkIdType index)
Get the plot at the specified index, returns null if the index is invalid.
vtkSmartPointer.h
vtkContextPolygon
Definition: vtkContextPolygon.h:26
vtkAbstractContextItem::MouseMoveEvent
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
vtkChartPlotData::ScreenPosition
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:525
vtkChartXY::HiddenAxisBorder
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:434
vtkAbstractContextItem::MouseButtonReleaseEvent
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
Mouse button release event.
vtkChart::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAxis
takes care of drawing 2D axes
Definition: vtkAxis.h:68
vtkAbstractContextItem::MouseEnterEvent
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse)
Mouse enter event.
vtkChart::ClearPlots
virtual void ClearPlots()
Remove all plots from the chart.
vtkChartPlotData::Position
vtkVector2f Position
Definition: vtkChartXY.h:524
vtkChartXY::SelectionPolygon
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition: vtkChartXY.h:407
vtkChart::RecalculateBounds
virtual void RecalculateBounds()
Request that the chart recalculates the range of its axes.
vtkChart::GetNumberOfAxes
virtual vtkIdType GetNumberOfAxes()
Get the number of axes in the current chart.
vtkAbstractContextItem::MouseLeaveEvent
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse)
Mouse leave event.
vtkAbstractContextItem::MouseButtonPressEvent
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...
vtkVector2i
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:405
vtkChartPlotData::Index
int Index
Definition: vtkChartXY.h:526
vtkChartXY
Factory class for drawing XY charts.
Definition: vtkChartXY.h:43
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkChartXY::DrawSelectionPolygon
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:412
vtkChartXY::DrawBox
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:401
vtkX3D::index
Definition: vtkX3D.h:246
vtkChart::GetAxis
virtual vtkAxis * GetAxis(int axisIndex)
Get the axis specified by axisIndex.
vtkRectf
Definition: vtkRect.h:293
vtkVector2f
Definition: vtkVector.h:415
vtkAbstractContextItem::MouseWheelEvent
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta)
Mouse wheel event, positive delta indicates forward movement of the wheel.
vtkChart::SetShowLegend
virtual void SetShowLegend(bool visible)
Set/get whether the chart should draw a legend.
vtkAbstractContextItem::Update
virtual void Update()
Perform any updates to the item that may be necessary before rendering.