VTK  9.2.6
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
42#ifndef vtkChartXY_h
43#define vtkChartXY_h
44
45#include "vtkChart.h"
46#include "vtkChartsCoreModule.h" // For export macro
47#include "vtkContextPolygon.h" // For vtkContextPolygon
48#include "vtkSmartPointer.h" // For SP ivars
49#include "vtkVector.h" // For vtkVector2f in struct
50
51#include <vector> // for std::vector
52
53class vtkAxis;
54class vtkChartLegend;
55class vtkIdTypeArray;
57class vtkPlot;
58class vtkPlotGrid;
59class vtkTooltipItem;
60
61class vtkChartXYPrivate; // Private class to keep my STL vector in...
62
63#include <map> // for std::map
64
65class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
66{
67public:
68 vtkTypeMacro(vtkChartXY, vtkChart);
69 void PrintSelf(ostream& os, vtkIndent indent) override;
70
74 static vtkChartXY* New();
75
81 void Update() override;
82
86 bool Paint(vtkContext2D* painter) override;
87
91 vtkPlot* AddPlot(int type) override;
92
96 virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
97
101 vtkIdType AddPlot(vtkPlot* plot) override;
102
106 virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
107
112 bool RemovePlot(vtkIdType index) override;
113
117 void ClearPlots() override;
118
122 vtkPlot* GetPlot(vtkIdType index) override;
123
129
136
143 virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
144
151
158 virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
159
164
169
173 void SetPlotCorner(vtkPlot* plot, int corner);
174
180 vtkAxis* GetAxis(int axisIndex) override;
181
187 void SetAxis(int axisIndex, vtkAxis*) override;
188
192 void SetShowLegend(bool visible) override;
193
198
202 virtual void SetTooltip(vtkTooltipItem* tooltip);
203
208
213
218 void RecalculateBounds() override;
219
227 void SetSelectionMethod(int method) override;
228
233
235
238 vtkSetMacro(DrawAxesAtOrigin, bool);
239 vtkGetMacro(DrawAxesAtOrigin, bool);
240 vtkBooleanMacro(DrawAxesAtOrigin, bool);
242
244
248 vtkSetMacro(AutoAxes, bool);
249 vtkGetMacro(AutoAxes, bool);
250 vtkBooleanMacro(AutoAxes, bool);
252
254
257 vtkSetMacro(HiddenAxisBorder, int);
258 vtkGetMacro(HiddenAxisBorder, int);
260
262
267 vtkSetMacro(ForceAxesToBounds, bool);
268 vtkGetMacro(ForceAxesToBounds, bool);
269 vtkBooleanMacro(ForceAxesToBounds, bool);
271
273
279 vtkSetMacro(IgnoreNanInBounds, bool);
280 vtkGetMacro(IgnoreNanInBounds, bool);
281 vtkBooleanMacro(IgnoreNanInBounds, bool);
283
285
292 vtkSetMacro(BarWidthFraction, float);
293 vtkGetMacro(BarWidthFraction, float);
295
297
303 vtkSetMacro(ZoomWithMouseWheel, bool);
304 vtkGetMacro(ZoomWithMouseWheel, bool);
305 vtkBooleanMacro(ZoomWithMouseWheel, bool);
307
309
314 void SetAxisZoom(int index, bool v);
315 bool GetAxisZoom(int index);
317
319
324 vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
325 vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
326 vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
328
330
335 vtkSetMacro(DragPointAlongX, bool);
336 vtkGetMacro(DragPointAlongX, bool);
337 vtkBooleanMacro(DragPointAlongX, bool);
339
341
346 vtkSetMacro(DragPointAlongY, bool);
347 vtkGetMacro(DragPointAlongY, bool);
348 vtkBooleanMacro(DragPointAlongY, bool);
350
355 vtkIdType segmentIndex = -1);
356
360 bool Hit(const vtkContextMouseEvent& mouse) override;
361
365 bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
366
370 bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
371
375 bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
376
380 bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
381
386
390 bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
391
395 bool KeyPressEvent(const vtkContextKeyEvent& key) override;
396
397 typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
398
403 static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
404
408 const std::vector<vtkContextTransform*>& GetTransforms() const;
409
414 static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
415
419 static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
420
424 static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
425
429 static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
430
437 static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
438 vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
439
446 static void BuildSelection(
447 int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
448
453 static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
454
455protected:
457 ~vtkChartXY() override;
458
463
469
475 virtual bool UpdateLayout(vtkContext2D* painter);
476
482 virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
483
488 virtual void SetLegendPosition(const vtkRectf& rect);
489
494
499
504
509
514
520
525
530
537
542
547
553
560
568
574
579 bool AxisZoom[4];
580
586
592
593private:
594 vtkChartXY(const vtkChartXY&) = delete;
595 void operator=(const vtkChartXY&) = delete;
596
597 vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
598
603 bool DragPoint;
604
608 void CalculateBarPlots();
609
615 bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
616
617 int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
618 vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
619
623 bool RemovePlotFromCorners(vtkPlot* plot);
624
625 void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
626
631 void ReleasePlotSelections();
632
636 void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
637 const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
638 vtkContextPolygon& polygon);
639};
640
642
648{
652 int Index;
653};
655
656#endif // vtkChartXY_h
takes care of drawing 2D axes
Definition vtkAxis.h:81
draw the chart legend
Factory class for drawing XY charts.
Definition vtkChartXY.h:66
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:529
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:513
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition vtkChartXY.h:493
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
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:519
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:591
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:536
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:541
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition vtkChartXY.h:585
~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:503
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:552
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:573
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:590
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:524
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition vtkChartXY.h:508
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:397
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition vtkChartXY.h:498
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:546
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition vtkChartXY.h:559
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.
Factory class for drawing 2D charts.
Definition vtkChart.h:61
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:49
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:63
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:431
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition vtkChartXY.h:648
vtkVector2f Position
Definition vtkChartXY.h:650
vtkVector2i ScreenPosition
Definition vtkChartXY.h:651
vtkStdString SeriesName
Definition vtkChartXY.h:649
int vtkIdType
Definition vtkType.h:332
#define max(a, b)