VTK  9.3.20240419
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 
130 #ifndef vtkChartXY_h
131 #define vtkChartXY_h
132 
133 #include "vtkChart.h"
134 #include "vtkChartsCoreModule.h" // For export macro
135 #include "vtkContextPolygon.h" // For vtkContextPolygon
136 #include "vtkSmartPointer.h" // For SP ivars
137 #include "vtkVector.h" // For vtkVector2f in struct
138 
139 #include <vector> // for std::vector
140 
141 VTK_ABI_NAMESPACE_BEGIN
142 class vtkAxis;
143 class vtkChartLegend;
144 class vtkIdTypeArray;
146 class vtkPlot;
147 class vtkPlotGrid;
148 class vtkTooltipItem;
149 
150 class vtkChartXYPrivate; // Private class to keep my STL vector in...
151 
152 VTK_ABI_NAMESPACE_END
153 #include <map> // for std::map
154 
155 VTK_ABI_NAMESPACE_BEGIN
156 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
157 {
158 public:
159  vtkTypeMacro(vtkChartXY, vtkChart);
160  void PrintSelf(ostream& os, vtkIndent indent) override;
161 
165  static vtkChartXY* New();
166 
172  void Update() override;
173 
177  bool Paint(vtkContext2D* painter) override;
178 
182  vtkPlot* AddPlot(int type) override;
183 
187  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
188 
192  vtkIdType AddPlot(vtkPlot* plot) override;
193 
197  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
198 
203  bool RemovePlot(vtkIdType index) override;
204 
208  void ClearPlots() override;
209 
214 
220 
227 
234  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
235 
242 
249  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
250 
255 
259  int GetPlotCorner(vtkPlot* plot);
260 
264  void SetPlotCorner(vtkPlot* plot, int corner);
265 
271  vtkAxis* GetAxis(int axisIndex) override;
272 
278  void SetAxis(int axisIndex, vtkAxis*) override;
279 
283  void SetShowLegend(bool visible) override;
284 
289 
293  virtual void SetTooltip(vtkTooltipItem* tooltip);
294 
299 
304 
309  void RecalculateBounds() override;
310 
318  void SetSelectionMethod(int method) override;
319 
324 
326 
329  vtkSetMacro(DrawAxesAtOrigin, bool);
330  vtkGetMacro(DrawAxesAtOrigin, bool);
331  vtkBooleanMacro(DrawAxesAtOrigin, bool);
333 
335 
339  vtkSetMacro(AutoAxes, bool);
340  vtkGetMacro(AutoAxes, bool);
341  vtkBooleanMacro(AutoAxes, bool);
343 
345 
348  vtkSetMacro(HiddenAxisBorder, int);
349  vtkGetMacro(HiddenAxisBorder, int);
351 
353 
358  vtkSetMacro(ForceAxesToBounds, bool);
359  vtkGetMacro(ForceAxesToBounds, bool);
360  vtkBooleanMacro(ForceAxesToBounds, bool);
362 
364 
370  vtkSetMacro(IgnoreNanInBounds, bool);
371  vtkGetMacro(IgnoreNanInBounds, bool);
372  vtkBooleanMacro(IgnoreNanInBounds, bool);
374 
376 
383  vtkSetMacro(BarWidthFraction, float);
384  vtkGetMacro(BarWidthFraction, float);
386 
388 
394  vtkSetMacro(ZoomWithMouseWheel, bool);
395  vtkGetMacro(ZoomWithMouseWheel, bool);
396  vtkBooleanMacro(ZoomWithMouseWheel, bool);
398 
400 
405  void SetAxisZoom(int index, bool v);
406  bool GetAxisZoom(int index);
408 
410 
415  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
416  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
417  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
419 
421 
426  vtkSetMacro(DragPointAlongX, bool);
427  vtkGetMacro(DragPointAlongX, bool);
428  vtkBooleanMacro(DragPointAlongX, bool);
430 
432 
437  vtkSetMacro(DragPointAlongY, bool);
438  vtkGetMacro(DragPointAlongY, bool);
439  vtkBooleanMacro(DragPointAlongY, bool);
441 
446  vtkIdType segmentIndex = -1);
447 
451  bool Hit(const vtkContextMouseEvent& mouse) override;
452 
456  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
457 
461  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
462 
466  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
467 
471  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
472 
476  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
477 
481  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
482 
486  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
487 
488  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
489 
494  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
495 
499  const std::vector<vtkContextTransform*>& GetTransforms() const;
500 
505  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
506 
510  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
511 
515  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
516 
520  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
521 
528  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
529  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
530 
537  static void BuildSelection(
538  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
539 
544  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
545 
546 protected:
548  ~vtkChartXY() override;
549 
554 
560 
566  virtual bool UpdateLayout(vtkContext2D* painter);
567 
573  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
574 
579  virtual void SetLegendPosition(const vtkRectf& rect);
580 
585 
590 
595 
600 
604  bool DrawBox;
605 
611 
616 
621 
628 
632  bool AutoAxes;
633 
638 
644 
651 
659 
665 
670  bool AxisZoom[4];
671 
677 
683 
684 private:
685  vtkChartXY(const vtkChartXY&) = delete;
686  void operator=(const vtkChartXY&) = delete;
687 
688  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
689 
694  bool DragPoint;
695 
699  void CalculateBarPlots();
700 
706  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
707 
708  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
709  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
710 
714  bool RemovePlotFromCorners(vtkPlot* plot);
715 
716  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
717 
722  void ReleasePlotSelections();
723 
727  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
728  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
729  vtkContextPolygon& polygon);
730 };
731 
733 
739 {
743  int Index;
744 };
746 
747 VTK_ABI_NAMESPACE_END
748 #endif // vtkChartXY_h
takes care of drawing 2D axes
Definition: vtkAxis.h:170
draw the chart legend
Factory class for drawing XY charts.
Definition: vtkChartXY.h:157
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition: vtkChartXY.h:620
virtual vtkIdType StackPlotUnder(vtkPlot *plot, vtkPlot *above)
Lowers the plot under the above plot.
vtkIdType AddPlot(vtkPlot *plot) override
Adds a plot to the chart.
vtkPlot * AddPlot(int type) override
Add a plot to the chart, defaults to using the name of the y column.
vtkChartLegend * GetLegend() override
Get the vtkChartLegend object that will be displayed by the chart.
bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override
Mouse button release event.
static void MakeSelection(vtkAnnotationLink *link, vtkIdTypeArray *selectionIds, vtkPlot *plot)
Populate the annotation link with the supplied selectionIds array, and set the appropriate node prope...
virtual vtkIdType AddPlot(vtkPlot *plot, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
vtkIdType GetNumberOfPlots() override
Get the number of plots the chart contains.
vtkIdType GetNumberOfAxes() override
Get the number of axes in the current chart.
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:604
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:584
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
Definition: vtkChartXY.h:658
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition: vtkChartXY.h:610
virtual void SetTooltipInfo(const vtkContextMouseEvent &, const vtkVector2d &, vtkIdType, vtkPlot *, vtkIdType segmentIndex=-1)
Set the information passed to the tooltip.
void RecalculatePlotTransforms()
Recalculate the necessary transforms.
bool RemovePlot(vtkIdType index) override
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
void Update() override
Perform any updates to the item that may be necessary before rendering.
const std::vector< vtkContextTransform * > & GetTransforms() const
Get the vector of vtkContextTransform.
virtual int GetLegendBorder(vtkContext2D *painter, int axisPosition)
Layout for the legend if it is visible.
virtual vtkIdType GetPlotIndex(vtkPlot *)
Get the index of the specified plot, returns -1 if the plot does not belong to the chart.
virtual vtkPlot * AddPlot(int type, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
bool DragPointAlongY
Definition: vtkChartXY.h:682
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
vtkIdType RaisePlot(vtkPlot *plot)
Raises the plot to the top of the plot's stack.
bool DrawAxesAtOrigin
Keep the axes drawn at the origin? This will attempt to keep the axes drawn at the origin,...
Definition: vtkChartXY.h:627
static void AddSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Add the supplied selection from the oldSelection.
static void BuildSelection(int selectionMode, MapIndexToIds &selection, const MapIndexToIds &oldSelection)
Build a selection based on the supplied selectionMode using the new plotSelection and combining it wi...
vtkAxis * GetAxis(int axisIndex) override
Get the axis specified by axisIndex.
static void MakeSelection(vtkAnnotationLink *link, const MapIndexToIds &selection)
Populate the selection node in the annotation link coressponding to the give node with the supplied s...
static vtkChartXY * New()
Creates a 2D Chart object.
vtkPlot * GetPlot(vtkIdType index) override
Get the plot at the specified index, returns null if the index is invalid.
bool MouseEnterEvent(const vtkContextMouseEvent &mouse) override
Mouse enter event.
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Key press event.
void SetSelectionMethod(int method) override
Set the selection method, which controls how selections are handled by the chart.
static void BuildSelection(vtkAnnotationLink *link, int selectionMode, vtkIdTypeArray *plotSelection, vtkIdTypeArray *oldSelection, vtkPlot *plot)
Build a selection based on the supplied selectionMode using the new plotSelection and combining it wi...
void RecalculateBounds() override
Request that the chart recalculates the range of its axes.
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:632
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition: vtkChartXY.h:676
~vtkChartXY() override
void RemovePlotSelections()
Remove all the selection from Plots.
virtual bool UpdateLayout(vtkContext2D *painter)
Update the layout of the chart, this may require the vtkContext2D in order to get font metrics etc.
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:594
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:643
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse move event.
void SetAxisZoom(int index, bool v)
Set the behavior of the mouse wheel for individual axes.
virtual vtkIdType StackPlotAbove(vtkPlot *plot, vtkPlot *under)
Raises the plot above the under plot.
bool ZoomWithMouseWheel
Property to enable zooming the chart with the mouse wheel.
Definition: vtkChartXY.h:664
void ClearPlots() override
Remove all plots from the chart.
static void ToggleSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Toggle the supplied selection from the oldSelection.
bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta) override
Mouse wheel event, positive delta indicates forward movement of the wheel.
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse button down event.
bool DragPointAlongX
Properties to enable the drag of a point for the ClickAndDrag Action.
Definition: vtkChartXY.h:681
int GetPlotCorner(vtkPlot *plot)
Figure out which quadrant the plot is in.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetShowLegend(bool visible) override
Set whether the chart should draw a legend.
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:615
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:599
void SetPlotCorner(vtkPlot *plot, int corner)
Figure out which quadrant the plot is in.
virtual void SetLegendPosition(const vtkRectf &rect)
Called after the edges of the chart are decided, set the position of the legend, depends upon its ali...
void SetAxis(int axisIndex, vtkAxis *) override
Set the axis specified by axisIndex.
virtual void SetTooltip(vtkTooltipItem *tooltip)
Set the vtkTooltipItem object that will be displayed by the chart.
bool Paint(vtkContext2D *painter) override
Paint event for the chart, called whenever the chart needs to be drawn.
std::map< unsigned int, vtkSmartPointer< vtkIdTypeArray > > MapIndexToIds
Definition: vtkChartXY.h:488
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition: vtkChartXY.h:589
vtkIdType LowerPlot(vtkPlot *plot)
Lowers the plot to the bottom of the plot's stack.
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:637
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition: vtkChartXY.h:650
void RecalculatePlotBounds()
Calculate the optimal zoom level such that all of the points to be plotted will fit into the plot are...
static void MinusSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Subtract the supplied selection from the oldSelection.
static int GetMouseSelectionMode(const vtkContextMouseEvent &mouse, int selectionMode)
Combine the SelectionMode with any mouse modifiers to get an effective selection mode for this click ...
bool MouseLeaveEvent(const vtkContextMouseEvent &mouse) override
Mouse leave event.
virtual vtkTooltipItem * GetTooltip()
Get the vtkTooltipItem object that will be displayed by the chart.
bool GetAxisZoom(int index)
Set the behavior of the mouse wheel for individual axes.
Factory class for drawing 2D charts.
Definition: vtkChart.h:150
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:69
data structure to represent key events.
data structure to represent mouse events.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:108
Composite dataset that organizes datasets into blocks.
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:27
Abstract class for 2D plots.
Definition: vtkPlot.h:153
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
takes care of drawing 2D axes
describes linear transformations via a 3x3 matrix
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:470
@ key
Definition: vtkX3D.h:257
@ type
Definition: vtkX3D.h:516
@ position
Definition: vtkX3D.h:261
@ index
Definition: vtkX3D.h:246
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition: vtkChartXY.h:739
vtkVector2f Position
Definition: vtkChartXY.h:741
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:742
vtkStdString SeriesName
Definition: vtkChartXY.h:740
int vtkIdType
Definition: vtkType.h:315
#define max(a, b)