VTK  9.7.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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
28 #include "vtkSmartPointer.h" // For SP ivars
29 #include "vtkVector.h" // For vtkVector2f in struct
30 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
31 
32 #include <vector> // for std::vector
33 
34 VTK_ABI_NAMESPACE_BEGIN
35 class vtkAxis;
36 class vtkChartLegend;
37 class vtkIdTypeArray;
39 class vtkPlot;
40 class vtkPlotGrid;
41 class vtkTooltipItem;
42 
43 class vtkChartXYPrivate; // Private class to keep my STL vector in...
44 
45 VTK_ABI_NAMESPACE_END
46 #include <map> // for std::map
47 
48 VTK_ABI_NAMESPACE_BEGIN
49 class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO 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  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
81 
85  vtkIdType AddPlot(vtkPlot* plot) override;
86 
90  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
91 
96  bool RemovePlot(vtkIdType index) override;
97 
101  void ClearPlots() override;
102 
106  vtkPlot* GetPlot(vtkIdType index) override;
107 
112  virtual vtkIdType GetPlotIndex(vtkPlot*);
113 
119  vtkIdType RaisePlot(vtkPlot* plot);
120 
127  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
128 
134  vtkIdType LowerPlot(vtkPlot* plot);
135 
142  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
143 
147  vtkIdType GetNumberOfPlots() override;
148 
152  int GetPlotCorner(vtkPlot* plot);
153 
157  void SetPlotCorner(vtkPlot* plot, int corner);
158 
164  vtkAxis* GetAxis(int axisIndex) override;
165 
171  void SetAxis(int axisIndex, vtkAxis*) override;
172 
176  void SetShowLegend(bool visible) override;
177 
181  vtkChartLegend* GetLegend() override;
182 
186  virtual void SetTooltip(vtkTooltipItem* tooltip);
187 
191  virtual vtkTooltipItem* GetTooltip();
192 
196  vtkIdType GetNumberOfAxes() override;
197 
202  void RecalculateBounds() override;
203 
211  void SetSelectionMethod(int method) override;
212 
216  void RemovePlotSelections();
217 
219 
222  vtkSetMacro(DrawAxesAtOrigin, bool);
223  vtkGetMacro(DrawAxesAtOrigin, bool);
224  vtkBooleanMacro(DrawAxesAtOrigin, bool);
226 
228 
232  vtkSetMacro(AutoAxes, bool);
233  vtkGetMacro(AutoAxes, bool);
234  vtkBooleanMacro(AutoAxes, bool);
236 
238 
241  vtkSetMacro(HiddenAxisBorder, int);
242  vtkGetMacro(HiddenAxisBorder, int);
244 
246 
251  vtkSetMacro(ForceAxesToBounds, bool);
252  vtkGetMacro(ForceAxesToBounds, bool);
253  vtkBooleanMacro(ForceAxesToBounds, bool);
255 
257 
263  vtkSetMacro(IgnoreNanInBounds, bool);
264  vtkGetMacro(IgnoreNanInBounds, bool);
265  vtkBooleanMacro(IgnoreNanInBounds, bool);
267 
269 
276  vtkSetMacro(BarWidthFraction, float);
277  vtkGetMacro(BarWidthFraction, float);
279 
281 
287  vtkSetMacro(ZoomWithMouseWheel, bool);
288  vtkGetMacro(ZoomWithMouseWheel, bool);
289  vtkBooleanMacro(ZoomWithMouseWheel, bool);
291 
293 
298  void SetAxisZoom(int index, bool v);
299  bool GetAxisZoom(int index);
301 
303 
308  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
309  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
310  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
312 
314 
319  vtkSetMacro(DragPointAlongX, bool);
320  vtkGetMacro(DragPointAlongX, bool);
321  vtkBooleanMacro(DragPointAlongX, bool);
323 
325 
330  vtkSetMacro(DragPointAlongY, bool);
331  vtkGetMacro(DragPointAlongY, bool);
332  vtkBooleanMacro(DragPointAlongY, bool);
334 
338  virtual void SetTooltipInfo(const vtkContextMouseEvent&, const vtkVector2d&, vtkIdType, vtkPlot*,
339  vtkIdType segmentIndex = -1);
340 
344  bool Hit(const vtkContextMouseEvent& mouse) override;
345 
349  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
350 
354  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
355 
359  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
360 
364  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
365 
369  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
370 
374  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
375 
379  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
380 
381  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
382 
387  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
388 
392  const std::vector<vtkContextTransform*>& GetTransforms() const;
393 
398  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
399 
403  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
404 
408  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
409 
413  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
414 
421  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
422  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
423 
430  static void BuildSelection(
431  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
432 
437  VTK_DEPRECATED_IN_9_6_0("Use use vtkChart::GetSelectionModeFromMouseModifiers instead")
438  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
439 
440 protected:
441  vtkChartXY();
442  ~vtkChartXY() override;
443 
447  void RecalculatePlotTransforms();
448 
453  void RecalculatePlotBounds();
454 
460  virtual bool UpdateLayout(vtkContext2D* painter);
461 
467  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
468 
473  virtual void SetLegendPosition(const vtkRectf& rect);
474 
479 
484 
488  bool PlotTransformValid;
489 
493  vtkRectf MouseBox;
494 
498  bool DrawBox;
499 
504  vtkContextPolygon SelectionPolygon;
505 
509  bool DrawSelectionPolygon;
510 
514  bool DrawNearestPoint;
515 
521  bool DrawAxesAtOrigin;
522 
526  bool AutoAxes;
527 
531  int HiddenAxisBorder;
532 
537  float BarWidthFraction;
538 
544  bool ForceAxesToBounds;
545 
552  bool IgnoreNanInBounds;
553 
558  bool ZoomWithMouseWheel;
559 
564  bool AxisZoom[4];
565 
570  bool AdjustLowerBoundForLogPlot;
571 
575  bool DragPointAlongX;
576  bool DragPointAlongY;
577 
578 private:
579  vtkChartXY(const vtkChartXY&) = delete;
580  void operator=(const vtkChartXY&) = delete;
581 
582  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
583 
588  bool DragPoint;
589 
593  void CalculateBarPlots();
594 
600  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
601 
602  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
603  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
604 
608  bool RemovePlotFromCorners(vtkPlot* plot);
609 
610  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
611 
616  void ReleasePlotSelections();
617 
621  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
622  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
623  vtkContextPolygon& polygon);
624 };
625 
627 
633 {
637  int Index;
638 };
640 
641 VTK_ABI_NAMESPACE_END
642 #endif // vtkChartXY_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
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...
virtual vtkIdType GetNumberOfAxes()
Get the number of axes in the current chart.
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
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
int vtkIdType
Definition: vtkType.h:363
vtkStdString SeriesName
Definition: vtkChartXY.h:634
virtual void ClearPlots()
Remove all plots from the chart.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
#define VTK_DEPRECATED_IN_9_6_0(reason)
Factory class for drawing 2D charts.
Definition: vtkChart.h:41
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:61
data structure to represent mouse events.
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:636
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:381
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:410
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:635
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse)
Mouse enter event.
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:632
Composite dataset that organizes datasets into blocks.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:27
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.
#define VTK_MARSHALAUTO
takes care of drawing 2D axes
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
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.