VTK  9.1.0
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 
27 #ifndef vtkChartXY_h
28 #define vtkChartXY_h
29 
30 #include "vtkChart.h"
31 #include "vtkChartsCoreModule.h" // For export macro
32 #include "vtkContextPolygon.h" // For vtkContextPolygon
33 #include "vtkSmartPointer.h" // For SP ivars
34 #include "vtkVector.h" // For vtkVector2f in struct
35 
36 #include <vector> // for std::vector
37 
38 class vtkAxis;
39 class vtkChartLegend;
40 class vtkIdTypeArray;
42 class vtkPlot;
43 class vtkPlotGrid;
44 class vtkTooltipItem;
45 
46 class vtkChartXYPrivate; // Private class to keep my STL vector in...
47 
48 #include <map> // for std::map
49 
50 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
51 {
52 public:
53  vtkTypeMacro(vtkChartXY, vtkChart);
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
59  static vtkChartXY* New();
60 
66  void Update() override;
67 
71  bool Paint(vtkContext2D* painter) override;
72 
76  vtkPlot* AddPlot(int type) override;
77 
81  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
82 
86  vtkIdType AddPlot(vtkPlot* plot) override;
87 
91  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
92 
97  bool RemovePlot(vtkIdType index) override;
98 
102  void ClearPlots() override;
103 
108 
114 
121 
128  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
129 
136 
143  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
144 
149 
153  int GetPlotCorner(vtkPlot* plot);
154 
158  void SetPlotCorner(vtkPlot* plot, int corner);
159 
165  vtkAxis* GetAxis(int axisIndex) override;
166 
172  void SetAxis(int axisIndex, vtkAxis*) override;
173 
177  void SetShowLegend(bool visible) override;
178 
183 
187  virtual void SetTooltip(vtkTooltipItem* tooltip);
188 
193 
198 
203  void RecalculateBounds() override;
204 
212  void SetSelectionMethod(int method) override;
213 
218 
220 
223  vtkSetMacro(DrawAxesAtOrigin, bool);
224  vtkGetMacro(DrawAxesAtOrigin, bool);
225  vtkBooleanMacro(DrawAxesAtOrigin, bool);
227 
229 
233  vtkSetMacro(AutoAxes, bool);
234  vtkGetMacro(AutoAxes, bool);
235  vtkBooleanMacro(AutoAxes, bool);
237 
239 
242  vtkSetMacro(HiddenAxisBorder, int);
243  vtkGetMacro(HiddenAxisBorder, int);
245 
247 
252  vtkSetMacro(ForceAxesToBounds, bool);
253  vtkGetMacro(ForceAxesToBounds, bool);
254  vtkBooleanMacro(ForceAxesToBounds, bool);
256 
258 
264  vtkSetMacro(IgnoreNanInBounds, bool);
265  vtkGetMacro(IgnoreNanInBounds, bool);
266  vtkBooleanMacro(IgnoreNanInBounds, bool);
268 
270 
277  vtkSetMacro(BarWidthFraction, float);
278  vtkGetMacro(BarWidthFraction, float);
280 
282 
288  vtkSetMacro(ZoomWithMouseWheel, bool);
289  vtkGetMacro(ZoomWithMouseWheel, bool);
290  vtkBooleanMacro(ZoomWithMouseWheel, bool);
292 
294 
299  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
300  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
301  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
303 
305 
310  vtkSetMacro(DragPointAlongX, bool);
311  vtkGetMacro(DragPointAlongX, bool);
312  vtkBooleanMacro(DragPointAlongX, bool);
314 
316 
321  vtkSetMacro(DragPointAlongY, bool);
322  vtkGetMacro(DragPointAlongY, bool);
323  vtkBooleanMacro(DragPointAlongY, bool);
325 
330  vtkIdType segmentIndex = -1);
331 
335  bool Hit(const vtkContextMouseEvent& mouse) override;
336 
340  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
341 
345  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
346 
350  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
351 
355  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
356 
360  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
361 
365  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
366 
370  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
371 
372  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
373 
378  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
379 
383  const std::vector<vtkContextTransform*>& GetTransforms() const;
384 
389  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
390 
394  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
395 
399  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
400 
404  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
405 
412  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
413  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
414 
421  static void BuildSelection(
422  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
423 
428  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
429 
430 protected:
432  ~vtkChartXY() override;
433 
438 
444 
450  virtual bool UpdateLayout(vtkContext2D* painter);
451 
457  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
458 
463  virtual void SetLegendPosition(const vtkRectf& rect);
464 
469 
474 
479 
484 
488  bool DrawBox;
489 
495 
500 
505 
512 
516  bool AutoAxes;
517 
522 
528 
535 
543 
549 
555 
561 
562 private:
563  vtkChartXY(const vtkChartXY&) = delete;
564  void operator=(const vtkChartXY&) = delete;
565 
566  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
567 
572  bool DragPoint;
573 
577  void CalculateBarPlots();
578 
584  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
585 
586  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
587  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
588 
592  bool RemovePlotFromCorners(vtkPlot* plot);
593 
594  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
595 
600  void ReleasePlotSelections();
601 
605  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
606  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
607  vtkContextPolygon& polygon);
608 };
609 
611 
617 {
621  int Index;
622 };
624 
625 #endif // vtkChartXY_h
takes care of drawing 2D axes
Definition: vtkAxis.h:69
draw the chart legend
Factory class for drawing XY charts.
Definition: vtkChartXY.h:51
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition: vtkChartXY.h:504
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:488
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:468
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
Definition: vtkChartXY.h:542
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition: vtkChartXY.h:494
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:560
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:511
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:516
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition: vtkChartXY.h:554
~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:478
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:527
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse move event.
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:548
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:559
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:499
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:483
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:372
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition: vtkChartXY.h:473
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:521
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition: vtkChartXY.h:534
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.
Factory class for drawing 2D charts.
Definition: vtkChart.h:45
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:54
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:34
Composite dataset that organizes datasets into blocks.
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:39
Abstract class for 2D plots.
Definition: vtkPlot.h:48
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
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:419
@ key
Definition: vtkX3D.h:263
@ type
Definition: vtkX3D.h:522
@ position
Definition: vtkX3D.h:267
@ index
Definition: vtkX3D.h:252
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition: vtkChartXY.h:617
vtkVector2f Position
Definition: vtkChartXY.h:619
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:620
vtkStdString SeriesName
Definition: vtkChartXY.h:618
int vtkIdType
Definition: vtkType.h:332
#define max(a, b)