VTK  9.5.20250804
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
137#include "vtkSmartPointer.h" // For SP ivars
138#include "vtkVector.h" // For vtkVector2f in struct
139#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
140
141#include <vector> // for std::vector
142
143VTK_ABI_NAMESPACE_BEGIN
144class vtkAxis;
145class vtkChartLegend;
146class vtkIdTypeArray;
148class vtkPlot;
149class vtkPlotGrid;
150class vtkTooltipItem;
151
152class vtkChartXYPrivate; // Private class to keep my STL vector in...
153
154VTK_ABI_NAMESPACE_END
155#include <map> // for std::map
156
157VTK_ABI_NAMESPACE_BEGIN
158class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChartXY : public vtkChart
159{
160public:
161 vtkTypeMacro(vtkChartXY, vtkChart);
162 void PrintSelf(ostream& os, vtkIndent indent) override;
163
167 static vtkChartXY* New();
168
174 void Update() override;
175
179 bool Paint(vtkContext2D* painter) override;
180
184 vtkPlot* AddPlot(int type) override;
185
189 virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
190
194 vtkIdType AddPlot(vtkPlot* plot) override;
195
199 virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
200
205 bool RemovePlot(vtkIdType index) override;
206
210 void ClearPlots() override;
211
215 vtkPlot* GetPlot(vtkIdType index) override;
216
222
229
236 virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
237
244
251 virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
252
257
262
266 void SetPlotCorner(vtkPlot* plot, int corner);
267
273 vtkAxis* GetAxis(int axisIndex) override;
274
280 void SetAxis(int axisIndex, vtkAxis*) override;
281
285 void SetShowLegend(bool visible) override;
286
291
295 virtual void SetTooltip(vtkTooltipItem* tooltip);
296
301
306
311 void RecalculateBounds() override;
312
320 void SetSelectionMethod(int method) override;
321
326
328
331 vtkSetMacro(DrawAxesAtOrigin, bool);
332 vtkGetMacro(DrawAxesAtOrigin, bool);
333 vtkBooleanMacro(DrawAxesAtOrigin, bool);
335
337
341 vtkSetMacro(AutoAxes, bool);
342 vtkGetMacro(AutoAxes, bool);
343 vtkBooleanMacro(AutoAxes, bool);
345
347
350 vtkSetMacro(HiddenAxisBorder, int);
351 vtkGetMacro(HiddenAxisBorder, int);
353
355
360 vtkSetMacro(ForceAxesToBounds, bool);
361 vtkGetMacro(ForceAxesToBounds, bool);
362 vtkBooleanMacro(ForceAxesToBounds, bool);
364
366
372 vtkSetMacro(IgnoreNanInBounds, bool);
373 vtkGetMacro(IgnoreNanInBounds, bool);
374 vtkBooleanMacro(IgnoreNanInBounds, bool);
376
378
385 vtkSetMacro(BarWidthFraction, float);
386 vtkGetMacro(BarWidthFraction, float);
388
390
396 vtkSetMacro(ZoomWithMouseWheel, bool);
397 vtkGetMacro(ZoomWithMouseWheel, bool);
398 vtkBooleanMacro(ZoomWithMouseWheel, bool);
400
402
407 void SetAxisZoom(int index, bool v);
408 bool GetAxisZoom(int index);
410
412
417 vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
418 vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
419 vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
421
423
428 vtkSetMacro(DragPointAlongX, bool);
429 vtkGetMacro(DragPointAlongX, bool);
430 vtkBooleanMacro(DragPointAlongX, bool);
432
434
439 vtkSetMacro(DragPointAlongY, bool);
440 vtkGetMacro(DragPointAlongY, bool);
441 vtkBooleanMacro(DragPointAlongY, bool);
443
448 vtkIdType segmentIndex = -1);
449
453 bool Hit(const vtkContextMouseEvent& mouse) override;
454
458 bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
459
463 bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
464
468 bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
469
473 bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
474
479
483 bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
484
488 bool KeyPressEvent(const vtkContextKeyEvent& key) override;
489
490 typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
491
496 static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
497
501 const std::vector<vtkContextTransform*>& GetTransforms() const;
502
507 static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
508
512 static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
513
517 static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
518
522 static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
523
530 static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
531 vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
532
539 static void BuildSelection(
540 int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
541
546 VTK_DEPRECATED_IN_9_6_0("Use use vtkChart::GetSelectionModeFromMouseModifiers instead")
547 static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
548
549protected:
551 ~vtkChartXY() override;
552
556 void RecalculatePlotTransforms();
557
562 void RecalculatePlotBounds();
563
569 virtual bool UpdateLayout(vtkContext2D* painter);
570
576 virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
577
582 virtual void SetLegendPosition(const vtkRectf& rect);
583
588
593
597 bool PlotTransformValid;
598
602 vtkRectf MouseBox;
603
607 bool DrawBox;
608
613 vtkContextPolygon SelectionPolygon;
614
618 bool DrawSelectionPolygon;
619
623 bool DrawNearestPoint;
624
630 bool DrawAxesAtOrigin;
631
635 bool AutoAxes;
636
640 int HiddenAxisBorder;
641
646 float BarWidthFraction;
647
653 bool ForceAxesToBounds;
654
661 bool IgnoreNanInBounds;
662
667 bool ZoomWithMouseWheel;
668
673 bool AxisZoom[4];
674
679 bool AdjustLowerBoundForLogPlot;
680
684 bool DragPointAlongX;
685 bool DragPointAlongY;
686
687private:
688 vtkChartXY(const vtkChartXY&) = delete;
689 void operator=(const vtkChartXY&) = delete;
690
691 vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
692
697 bool DragPoint;
698
702 void CalculateBarPlots();
703
709 bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
710
711 int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
712 vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
713
717 bool RemovePlotFromCorners(vtkPlot* plot);
718
719 void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
720
725 void ReleasePlotSelections();
726
730 void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
731 const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
732 vtkContextPolygon& polygon);
733};
734
736
742{
746 int Index;
747};
749
750VTK_ABI_NAMESPACE_END
751#endif // vtkChartXY_h
takes care of drawing 2D axes
Definition vtkAxis.h:171
draw the chart legend
Factory class for drawing XY charts.
Definition vtkChartXY.h:159
vtkAxis * GetAxis(int axisIndex) override
Get the axis specified by axisIndex.
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.
virtual void SetTooltipInfo(const vtkContextMouseEvent &, const vtkVector2d &, vtkIdType, vtkPlot *, vtkIdType segmentIndex=-1)
Set the information passed to the tooltip.
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 vtkIdType GetPlotIndex(vtkPlot *)
Get the index of the specified plot, returns -1 if the plot does not belong to the chart.
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.
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.
void RemovePlotSelections()
Remove all the selection from Plots.
virtual vtkPlot * AddPlot(int type, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
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.
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.
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.
void SetPlotCorner(vtkPlot *plot, int corner)
Figure out which quadrant the plot is in.
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:490
vtkIdType LowerPlot(vtkPlot *plot)
Lowers the plot to the bottom of the plot's stack.
static void MinusSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Subtract the supplied selection from the oldSelection.
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:151
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:108
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:153
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:450
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition vtkChartXY.h:742
vtkVector2f Position
Definition vtkChartXY.h:744
vtkVector2i ScreenPosition
Definition vtkChartXY.h:745
vtkStdString SeriesName
Definition vtkChartXY.h:743
#define VTK_DEPRECATED_IN_9_6_0(reason)
int vtkIdType
Definition vtkType.h:332
#define VTK_MARSHALAUTO
#define max(a, b)