VTK  9.2.6
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 #include <vector> // for std::vector
43 
44 class vtkAxis;
45 class vtkChartLegend;
46 class vtkIdTypeArray;
48 class vtkPlot;
49 class vtkPlotGrid;
50 class vtkTooltipItem;
51 
52 class vtkChartXYPrivate; // Private class to keep my STL vector in...
53 
54 #include <map> // for std::map
55 
56 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
57 {
58 public:
59  vtkTypeMacro(vtkChartXY, vtkChart);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
65  static vtkChartXY* New();
66 
72  void Update() override;
73 
77  bool Paint(vtkContext2D* painter) override;
78 
82  vtkPlot* AddPlot(int type) override;
83 
87  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
88 
92  vtkIdType AddPlot(vtkPlot* plot) override;
93 
97  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
98 
103  bool RemovePlot(vtkIdType index) override;
104 
108  void ClearPlots() override;
109 
113  vtkPlot* GetPlot(vtkIdType index) override;
114 
119  virtual vtkIdType GetPlotIndex(vtkPlot*);
120 
126  vtkIdType RaisePlot(vtkPlot* plot);
127 
134  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
135 
141  vtkIdType LowerPlot(vtkPlot* plot);
142 
149  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
150 
154  vtkIdType GetNumberOfPlots() override;
155 
159  int GetPlotCorner(vtkPlot* plot);
160 
164  void SetPlotCorner(vtkPlot* plot, int corner);
165 
171  vtkAxis* GetAxis(int axisIndex) override;
172 
178  void SetAxis(int axisIndex, vtkAxis*) override;
179 
183  void SetShowLegend(bool visible) override;
184 
188  vtkChartLegend* GetLegend() override;
189 
193  virtual void SetTooltip(vtkTooltipItem* tooltip);
194 
198  virtual vtkTooltipItem* GetTooltip();
199 
203  vtkIdType GetNumberOfAxes() override;
204 
209  void RecalculateBounds() override;
210 
218  void SetSelectionMethod(int method) override;
219 
223  void RemovePlotSelections();
224 
226 
229  vtkSetMacro(DrawAxesAtOrigin, bool);
230  vtkGetMacro(DrawAxesAtOrigin, bool);
231  vtkBooleanMacro(DrawAxesAtOrigin, bool);
233 
235 
239  vtkSetMacro(AutoAxes, bool);
240  vtkGetMacro(AutoAxes, bool);
241  vtkBooleanMacro(AutoAxes, bool);
243 
245 
248  vtkSetMacro(HiddenAxisBorder, int);
249  vtkGetMacro(HiddenAxisBorder, int);
251 
253 
258  vtkSetMacro(ForceAxesToBounds, bool);
259  vtkGetMacro(ForceAxesToBounds, bool);
260  vtkBooleanMacro(ForceAxesToBounds, bool);
262 
264 
270  vtkSetMacro(IgnoreNanInBounds, bool);
271  vtkGetMacro(IgnoreNanInBounds, bool);
272  vtkBooleanMacro(IgnoreNanInBounds, bool);
274 
276 
283  vtkSetMacro(BarWidthFraction, float);
284  vtkGetMacro(BarWidthFraction, float);
286 
288 
294  vtkSetMacro(ZoomWithMouseWheel, bool);
295  vtkGetMacro(ZoomWithMouseWheel, bool);
296  vtkBooleanMacro(ZoomWithMouseWheel, bool);
298 
300 
305  void SetAxisZoom(int index, bool v);
306  bool GetAxisZoom(int index);
308 
310 
315  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
316  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
317  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
319 
321 
326  vtkSetMacro(DragPointAlongX, bool);
327  vtkGetMacro(DragPointAlongX, bool);
328  vtkBooleanMacro(DragPointAlongX, bool);
330 
332 
337  vtkSetMacro(DragPointAlongY, bool);
338  vtkGetMacro(DragPointAlongY, bool);
339  vtkBooleanMacro(DragPointAlongY, bool);
341 
345  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
346  vtkIdType segmentIndex = -1);
347 
351  bool Hit(const vtkContextMouseEvent& mouse) override;
352 
356  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
357 
361  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
362 
366  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
367 
371  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
372 
376  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
377 
381  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
382 
386  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
387 
388  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
389 
394  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
395 
399  const std::vector<vtkContextTransform*>& GetTransforms() const;
400 
405  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
406 
410  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
411 
415  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
416 
420  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
421 
428  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
429  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
430 
437  static void BuildSelection(
438  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
439 
444  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
445 
446 protected:
447  vtkChartXY();
448  ~vtkChartXY() override;
449 
453  void RecalculatePlotTransforms();
454 
459  void RecalculatePlotBounds();
460 
466  virtual bool UpdateLayout(vtkContext2D* painter);
467 
473  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
474 
479  virtual void SetLegendPosition(const vtkRectf& rect);
480 
485 
490 
495 
500 
504  bool DrawBox;
505 
511 
516 
521 
528 
532  bool AutoAxes;
533 
538 
544 
551 
559 
565 
570  bool AxisZoom[4];
571 
577 
583 
584 private:
585  vtkChartXY(const vtkChartXY&) = delete;
586  void operator=(const vtkChartXY&) = delete;
587 
588  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
589 
594  bool DragPoint;
595 
599  void CalculateBarPlots();
600 
606  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
607 
608  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
609  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
610 
614  bool RemovePlotFromCorners(vtkPlot* plot);
615 
616  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
617 
622  void ReleasePlotSelections();
623 
627  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
628  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
629  vtkContextPolygon& polygon);
630 };
631 
633 
639 {
643  int Index;
644 };
646 
647 #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:527
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
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:576
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode...
Definition: vtkChartXY.h:510
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:550
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.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:332
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:537
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:515
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:499
vtkStdString SeriesName
Definition: vtkChartXY.h:640
virtual void ClearPlots()
Remove all plots from the chart.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
Factory class for drawing 2D charts.
Definition: vtkChart.h:51
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:642
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
std::map< unsigned int, vtkSmartPointer< vtkIdTypeArray > > MapIndexToIds
Definition: vtkChartXY.h:388
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:504
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:421
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:53
vtkVector2f Position
Definition: vtkChartXY.h:641
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:484
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:581
Factory class for drawing XY charts.
Definition: vtkChartXY.h:56
draw the chart legend
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
Definition: vtkChartXY.h:558
Small struct used by InvokeEvent to send some information about the point that was clicked on...
Definition: vtkChartXY.h:638
Composite dataset that organizes datasets into blocks.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
bool DragPointAlongY
Definition: vtkChartXY.h:582
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:564
takes care of drawing 2D axes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:532
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:489
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:543
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:520
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:494