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 
33 #ifndef vtkChartXY_h
34 #define vtkChartXY_h
35 
36 #include "vtkChart.h"
37 #include "vtkChartsCoreModule.h" // For export macro
38 #include "vtkContextPolygon.h" // For vtkContextPolygon
39 #include "vtkSmartPointer.h" // For SP ivars
40 #include "vtkVector.h" // For vtkVector2f in struct
41 
42 class vtkPlot;
43 class vtkAxis;
44 class vtkPlotGrid;
45 class vtkChartLegend;
46 class vtkTooltipItem;
47 class vtkChartXYPrivate; // Private class to keep my STL vector in...
48 
49 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
50 {
51 public:
52  vtkTypeMacro(vtkChartXY, vtkChart);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
58  static vtkChartXY* New();
59 
65  void Update() override;
66 
70  bool Paint(vtkContext2D* painter) override;
71 
75  vtkPlot* AddPlot(int type) override;
76 
80  vtkIdType AddPlot(vtkPlot* plot) override;
81 
86  bool RemovePlot(vtkIdType index) override;
87 
91  void ClearPlots() override;
92 
96  vtkPlot* GetPlot(vtkIdType index) override;
97 
102  virtual vtkIdType GetPlotIndex(vtkPlot*);
103 
109  vtkIdType RaisePlot(vtkPlot* plot);
110 
117  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
118 
124  vtkIdType LowerPlot(vtkPlot* plot);
125 
132  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
133 
137  vtkIdType GetNumberOfPlots() override;
138 
142  int GetPlotCorner(vtkPlot* plot);
143 
147  void SetPlotCorner(vtkPlot* plot, int corner);
148 
154  vtkAxis* GetAxis(int axisIndex) override;
155 
161  virtual void SetAxis(int axisIndex, vtkAxis*) override;
162 
166  void SetShowLegend(bool visible) override;
167 
171  vtkChartLegend* GetLegend() override;
172 
176  virtual void SetTooltip(vtkTooltipItem* tooltip);
177 
181  virtual vtkTooltipItem* GetTooltip();
182 
186  vtkIdType GetNumberOfAxes() override;
187 
192  void RecalculateBounds() override;
193 
201  void SetSelectionMethod(int method) override;
202 
206  void RemovePlotSelections();
207 
209 
212  vtkSetMacro(DrawAxesAtOrigin, bool);
213  vtkGetMacro(DrawAxesAtOrigin, bool);
214  vtkBooleanMacro(DrawAxesAtOrigin, bool);
216 
218 
222  vtkSetMacro(AutoAxes, bool);
223  vtkGetMacro(AutoAxes, bool);
224  vtkBooleanMacro(AutoAxes, bool);
226 
228 
231  vtkSetMacro(HiddenAxisBorder, int);
232  vtkGetMacro(HiddenAxisBorder, int);
234 
236 
241  vtkSetMacro(ForceAxesToBounds, bool);
242  vtkGetMacro(ForceAxesToBounds, bool);
243  vtkBooleanMacro(ForceAxesToBounds, bool);
245 
247 
254  vtkSetMacro(BarWidthFraction, float);
255  vtkGetMacro(BarWidthFraction, float);
257 
259 
265  vtkSetMacro(ZoomWithMouseWheel, bool);
266  vtkGetMacro(ZoomWithMouseWheel, bool);
267  vtkBooleanMacro(ZoomWithMouseWheel, bool);
269 
271 
276  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
277  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
278  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
280 
282 
287  vtkSetMacro(DragPointAlongX, bool);
288  vtkGetMacro(DragPointAlongX, bool);
289  vtkBooleanMacro(DragPointAlongX, bool);
291 
293 
298  vtkSetMacro(DragPointAlongY, bool);
299  vtkGetMacro(DragPointAlongY, bool);
300  vtkBooleanMacro(DragPointAlongY, bool);
302 
306  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
307  vtkIdType segmentIndex = -1);
308 
312  bool Hit(const vtkContextMouseEvent& mouse) override;
313 
317  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
318 
322  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
323 
327  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
328 
332  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
333 
337  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
338 
342  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
343 
347  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
348 
349 protected:
350  vtkChartXY();
351  ~vtkChartXY() override;
352 
356  void RecalculatePlotTransforms();
357 
362  void RecalculatePlotBounds();
363 
369  virtual bool UpdateLayout(vtkContext2D* painter);
370 
376  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
377 
382  virtual void SetLegendPosition(const vtkRectf& rect);
383 
388 
393 
398 
403 
407  bool DrawBox;
408 
414 
419 
424 
431 
435  bool AutoAxes;
436 
441 
447 
454 
460 
466 
472 
473 private:
474  vtkChartXY(const vtkChartXY&) = delete;
475  void operator=(const vtkChartXY&) = delete;
476 
477  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
478 
483  bool DragPoint;
484 
488  void CalculateBarPlots();
489 
495  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
496 
497  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
498  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
499 
503  bool RemovePlotFromCorners(vtkPlot* plot);
504 
505  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* orign, float* max);
506 
511  void ReleasePlotSelections();
512 
516  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
517  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
518  vtkContextPolygon& polygon);
519 };
520 
522 
528 {
532  int Index;
533 };
535 
536 #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:430
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
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:465
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode...
Definition: vtkChartXY.h:413
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:453
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:347
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:440
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:418
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:402
vtkStdString SeriesName
Definition: vtkChartXY.h:529
virtual void ClearPlots()
Remove all plots from the chart.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
Factory class for drawing 2D charts.
Definition: vtkChart.h:50
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:71
data structure to represent mouse events.
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:531
virtual void SetAxis(int axisIndex, vtkAxis *)
Set the axis specified by axisIndex.
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
a simple class to control print indentation
Definition: vtkIndent.h:39
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:407
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:408
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:52
vtkVector2f Position
Definition: vtkChartXY.h:530
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:387
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:470
Factory class for drawing XY charts.
Definition: vtkChartXY.h:49
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:527
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
bool DragPointAlongY
Definition: vtkChartXY.h:471
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:459
takes care of drawing 2D axes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:435
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:392
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:446
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:423
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:397