VTK  9.3.1
vtkChartXY.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
21 #ifndef vtkChartXY_h
22 #define vtkChartXY_h
23 
24 #include "vtkChart.h"
25 #include "vtkChartsCoreModule.h" // For export macro
26 #include "vtkContextPolygon.h" // For vtkContextPolygon
27 #include "vtkSmartPointer.h" // For SP ivars
28 #include "vtkVector.h" // For vtkVector2f in struct
29 
30 #include <vector> // for std::vector
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkAxis;
34 class vtkChartLegend;
35 class vtkIdTypeArray;
37 class vtkPlot;
38 class vtkPlotGrid;
39 class vtkTooltipItem;
40 
41 class vtkChartXYPrivate; // Private class to keep my STL vector in...
42 
43 VTK_ABI_NAMESPACE_END
44 #include <map> // for std::map
45 
46 VTK_ABI_NAMESPACE_BEGIN
47 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
48 {
49 public:
50  vtkTypeMacro(vtkChartXY, vtkChart);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
56  static vtkChartXY* New();
57 
63  void Update() override;
64 
68  bool Paint(vtkContext2D* painter) override;
69 
73  vtkPlot* AddPlot(int type) override;
74 
78  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
79 
83  vtkIdType AddPlot(vtkPlot* plot) override;
84 
88  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
89 
94  bool RemovePlot(vtkIdType index) override;
95 
99  void ClearPlots() override;
100 
104  vtkPlot* GetPlot(vtkIdType index) override;
105 
110  virtual vtkIdType GetPlotIndex(vtkPlot*);
111 
117  vtkIdType RaisePlot(vtkPlot* plot);
118 
125  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
126 
132  vtkIdType LowerPlot(vtkPlot* plot);
133 
140  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
141 
145  vtkIdType GetNumberOfPlots() override;
146 
150  int GetPlotCorner(vtkPlot* plot);
151 
155  void SetPlotCorner(vtkPlot* plot, int corner);
156 
162  vtkAxis* GetAxis(int axisIndex) override;
163 
169  void SetAxis(int axisIndex, vtkAxis*) override;
170 
174  void SetShowLegend(bool visible) override;
175 
179  vtkChartLegend* GetLegend() override;
180 
184  virtual void SetTooltip(vtkTooltipItem* tooltip);
185 
189  virtual vtkTooltipItem* GetTooltip();
190 
194  vtkIdType GetNumberOfAxes() override;
195 
200  void RecalculateBounds() override;
201 
209  void SetSelectionMethod(int method) override;
210 
214  void RemovePlotSelections();
215 
217 
220  vtkSetMacro(DrawAxesAtOrigin, bool);
221  vtkGetMacro(DrawAxesAtOrigin, bool);
222  vtkBooleanMacro(DrawAxesAtOrigin, bool);
224 
226 
230  vtkSetMacro(AutoAxes, bool);
231  vtkGetMacro(AutoAxes, bool);
232  vtkBooleanMacro(AutoAxes, bool);
234 
236 
239  vtkSetMacro(HiddenAxisBorder, int);
240  vtkGetMacro(HiddenAxisBorder, int);
242 
244 
249  vtkSetMacro(ForceAxesToBounds, bool);
250  vtkGetMacro(ForceAxesToBounds, bool);
251  vtkBooleanMacro(ForceAxesToBounds, bool);
253 
255 
261  vtkSetMacro(IgnoreNanInBounds, bool);
262  vtkGetMacro(IgnoreNanInBounds, bool);
263  vtkBooleanMacro(IgnoreNanInBounds, bool);
265 
267 
274  vtkSetMacro(BarWidthFraction, float);
275  vtkGetMacro(BarWidthFraction, float);
277 
279 
285  vtkSetMacro(ZoomWithMouseWheel, bool);
286  vtkGetMacro(ZoomWithMouseWheel, bool);
287  vtkBooleanMacro(ZoomWithMouseWheel, bool);
289 
291 
296  void SetAxisZoom(int index, bool v);
297  bool GetAxisZoom(int index);
299 
301 
306  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
307  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
308  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
310 
312 
317  vtkSetMacro(DragPointAlongX, bool);
318  vtkGetMacro(DragPointAlongX, bool);
319  vtkBooleanMacro(DragPointAlongX, bool);
321 
323 
328  vtkSetMacro(DragPointAlongY, bool);
329  vtkGetMacro(DragPointAlongY, bool);
330  vtkBooleanMacro(DragPointAlongY, bool);
332 
336  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
337  vtkIdType segmentIndex = -1);
338 
342  bool Hit(const vtkContextMouseEvent& mouse) override;
343 
347  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
348 
352  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
353 
357  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
358 
362  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
363 
367  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
368 
372  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
373 
377  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
378 
379  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
380 
385  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
386 
390  const std::vector<vtkContextTransform*>& GetTransforms() const;
391 
396  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
397 
401  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
402 
406  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
407 
411  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
412 
419  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
420  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
421 
428  static void BuildSelection(
429  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
430 
435  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
436 
437 protected:
438  vtkChartXY();
439  ~vtkChartXY() override;
440 
444  void RecalculatePlotTransforms();
445 
450  void RecalculatePlotBounds();
451 
457  virtual bool UpdateLayout(vtkContext2D* painter);
458 
464  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
465 
470  virtual void SetLegendPosition(const vtkRectf& rect);
471 
476 
481 
486 
491 
495  bool DrawBox;
496 
502 
507 
512 
519 
523  bool AutoAxes;
524 
529 
535 
542 
550 
556 
561  bool AxisZoom[4];
562 
568 
574 
575 private:
576  vtkChartXY(const vtkChartXY&) = delete;
577  void operator=(const vtkChartXY&) = delete;
578 
579  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
580 
585  bool DragPoint;
586 
590  void CalculateBarPlots();
591 
597  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
598 
599  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
600  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
601 
605  bool RemovePlotFromCorners(vtkPlot* plot);
606 
607  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
608 
613  void ReleasePlotSelections();
614 
618  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
619  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
620  vtkContextPolygon& polygon);
621 };
622 
624 
630 {
634  int Index;
635 };
637 
638 VTK_ABI_NAMESPACE_END
639 #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:518
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
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:567
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode...
Definition: vtkChartXY.h:501
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:541
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:315
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:528
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:506
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:490
vtkStdString SeriesName
Definition: vtkChartXY.h:631
virtual void ClearPlots()
Remove all plots from the chart.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
Factory class for drawing 2D charts.
Definition: vtkChart.h:40
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:60
data structure to represent mouse events.
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:633
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:28
std::map< unsigned int, vtkSmartPointer< vtkIdTypeArray > > MapIndexToIds
Definition: vtkChartXY.h:379
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:495
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:440
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:43
vtkVector2f Position
Definition: vtkChartXY.h:632
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:475
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:572
Factory class for drawing XY charts.
Definition: vtkChartXY.h:47
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:549
Small struct used by InvokeEvent to send some information about the point that was clicked on...
Definition: vtkChartXY.h:629
Composite dataset that organizes datasets into blocks.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
bool DragPointAlongY
Definition: vtkChartXY.h:573
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:26
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:555
takes care of drawing 2D axes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:523
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:480
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:534
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:511
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:485