VTK  9.5.2
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
20
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
30
31#include <vector> // for std::vector
32
33VTK_ABI_NAMESPACE_BEGIN
34class vtkAxis;
35class vtkChartLegend;
36class vtkIdTypeArray;
38class vtkPlot;
39class vtkPlotGrid;
40class vtkTooltipItem;
41
42class vtkChartXYPrivate; // Private class to keep my STL vector in...
43
44VTK_ABI_NAMESPACE_END
45#include <map> // for std::map
46
47VTK_ABI_NAMESPACE_BEGIN
48class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChartXY : public vtkChart
49{
50public:
51 vtkTypeMacro(vtkChartXY, vtkChart);
52 void PrintSelf(ostream& os, vtkIndent indent) override;
53
57 static vtkChartXY* New();
58
64 void Update() override;
65
69 bool Paint(vtkContext2D* painter) override;
70
74 vtkPlot* AddPlot(int type) override;
75
79 virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
80
84 vtkIdType AddPlot(vtkPlot* plot) override;
85
89 virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
90
95 bool RemovePlot(vtkIdType index) override;
96
100 void ClearPlots() override;
101
105 vtkPlot* GetPlot(vtkIdType index) override;
106
112
119
126 virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
127
134
141 virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
142
147
152
156 void SetPlotCorner(vtkPlot* plot, int corner);
157
163 vtkAxis* GetAxis(int axisIndex) override;
164
170 void SetAxis(int axisIndex, vtkAxis*) override;
171
175 void SetShowLegend(bool visible) override;
176
181
185 virtual void SetTooltip(vtkTooltipItem* tooltip);
186
191
196
201 void RecalculateBounds() override;
202
210 void SetSelectionMethod(int method) override;
211
216
218
221 vtkSetMacro(DrawAxesAtOrigin, bool);
222 vtkGetMacro(DrawAxesAtOrigin, bool);
223 vtkBooleanMacro(DrawAxesAtOrigin, bool);
225
227
231 vtkSetMacro(AutoAxes, bool);
232 vtkGetMacro(AutoAxes, bool);
233 vtkBooleanMacro(AutoAxes, bool);
235
237
240 vtkSetMacro(HiddenAxisBorder, int);
241 vtkGetMacro(HiddenAxisBorder, int);
243
245
250 vtkSetMacro(ForceAxesToBounds, bool);
251 vtkGetMacro(ForceAxesToBounds, bool);
252 vtkBooleanMacro(ForceAxesToBounds, bool);
254
256
262 vtkSetMacro(IgnoreNanInBounds, bool);
263 vtkGetMacro(IgnoreNanInBounds, bool);
264 vtkBooleanMacro(IgnoreNanInBounds, bool);
266
268
275 vtkSetMacro(BarWidthFraction, float);
276 vtkGetMacro(BarWidthFraction, float);
278
280
286 vtkSetMacro(ZoomWithMouseWheel, bool);
287 vtkGetMacro(ZoomWithMouseWheel, bool);
288 vtkBooleanMacro(ZoomWithMouseWheel, bool);
290
292
297 void SetAxisZoom(int index, bool v);
298 bool GetAxisZoom(int index);
300
302
307 vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
308 vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
309 vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
311
313
318 vtkSetMacro(DragPointAlongX, bool);
319 vtkGetMacro(DragPointAlongX, bool);
320 vtkBooleanMacro(DragPointAlongX, bool);
322
324
329 vtkSetMacro(DragPointAlongY, bool);
330 vtkGetMacro(DragPointAlongY, bool);
331 vtkBooleanMacro(DragPointAlongY, bool);
333
338 vtkIdType segmentIndex = -1);
339
343 bool Hit(const vtkContextMouseEvent& mouse) override;
344
348 bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
349
353 bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
354
358 bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
359
363 bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
364
369
373 bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
374
378 bool KeyPressEvent(const vtkContextKeyEvent& key) override;
379
380 typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
381
386 static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
387
391 const std::vector<vtkContextTransform*>& GetTransforms() const;
392
397 static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
398
402 static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
403
407 static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
408
412 static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
413
420 static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
421 vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
422
429 static void BuildSelection(
430 int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
431
436 static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
437
438protected:
440 ~vtkChartXY() override;
441
446
452
458 virtual bool UpdateLayout(vtkContext2D* painter);
459
465 virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
466
471 virtual void SetLegendPosition(const vtkRectf& rect);
472
477
482
487
492
497
503
508
513
520
525
530
536
543
551
557
562 bool AxisZoom[4];
563
569
575
576private:
577 vtkChartXY(const vtkChartXY&) = delete;
578 void operator=(const vtkChartXY&) = delete;
579
580 vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
581
586 bool DragPoint;
587
591 void CalculateBarPlots();
592
598 bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
599
600 int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
601 vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
602
606 bool RemovePlotFromCorners(vtkPlot* plot);
607
608 void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
609
614 void ReleasePlotSelections();
615
619 void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
620 const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
621 vtkContextPolygon& polygon);
622};
623
625
637
638
639VTK_ABI_NAMESPACE_END
640#endif // vtkChartXY_h
takes care of drawing 2D axes
Definition vtkAxis.h:62
draw the chart legend
vtkAxis * GetAxis(int axisIndex) override
Get the axis specified by axisIndex.
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition vtkChartXY.h:512
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.
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:496
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition vtkChartXY.h:476
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
Definition vtkChartXY.h:550
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition vtkChartXY.h:502
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.
vtkChartLegend * GetLegend() override
Get the vtkChartLegend object that will be displayed by the chart.
vtkPlot * AddPlot(int type) override
Add a plot to the chart, defaults to using the name of the y column.
void Update() override
Perform any updates to the item that may be necessary before rendering.
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.
bool DragPointAlongY
Definition vtkChartXY.h:574
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?
Definition vtkChartXY.h:519
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...
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...
vtkPlot * GetPlot(vtkIdType index) override
Get the plot at the specified index, returns null if the index is invalid.
const std::vector< vtkContextTransform * > & GetTransforms() const
Get the vector of vtkContextTransform.
static vtkChartXY * New()
Creates a 2D Chart object.
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:524
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition vtkChartXY.h:568
~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:486
virtual vtkPlot * AddPlot(int type, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
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:535
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.
virtual vtkTooltipItem * GetTooltip()
Get the vtkTooltipItem object that will be displayed by the chart.
bool ZoomWithMouseWheel
Property to enable zooming the chart with the mouse wheel.
Definition vtkChartXY.h:556
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:573
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:507
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition vtkChartXY.h:491
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:380
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition vtkChartXY.h:481
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:529
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition vtkChartXY.h:542
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.
bool GetAxisZoom(int index)
Set the behavior of the mouse wheel for individual axes.
bool AxisZoom[4]
Property to enable zooming of individual axes with the mouse wheel.
Definition vtkChartXY.h:562
Class for drawing 2D primitives to a graphical context.
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:29
Composite dataset that organizes datasets into blocks.
takes care of drawing the plot grid
Definition vtkPlotGrid.h:28
Abstract class for 2D plots.
Definition vtkPlot.h:44
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
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:411
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition vtkChartXY.h:631
vtkVector2f Position
Definition vtkChartXY.h:633
vtkVector2i ScreenPosition
Definition vtkChartXY.h:634
vtkStdString SeriesName
Definition vtkChartXY.h:632
int vtkIdType
Definition vtkType.h:332
#define VTK_MARSHALAUTO
#define max(a, b)