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 
136 #ifndef vtkChartXY_h
137 #define vtkChartXY_h
138 
139 #include "vtkChart.h"
140 #include "vtkChartsCoreModule.h" // For export macro
141 #include "vtkContextPolygon.h" // For vtkContextPolygon
142 #include "vtkSmartPointer.h" // For SP ivars
143 #include "vtkVector.h" // For vtkVector2f in struct
144 
145 #include <vector> // for std::vector
146 
147 class vtkAxis;
148 class vtkChartLegend;
149 class vtkIdTypeArray;
151 class vtkPlot;
152 class vtkPlotGrid;
153 class vtkTooltipItem;
154 
155 class vtkChartXYPrivate; // Private class to keep my STL vector in...
156 
157 #include <map> // for std::map
158 
159 class VTKCHARTSCORE_EXPORT vtkChartXY : public vtkChart
160 {
161 public:
162  vtkTypeMacro(vtkChartXY, vtkChart);
163  void PrintSelf(ostream& os, vtkIndent indent) override;
164 
168  static vtkChartXY* New();
169 
175  void Update() override;
176 
180  bool Paint(vtkContext2D* painter) override;
181 
185  vtkPlot* AddPlot(int type) override;
186 
190  virtual vtkPlot* AddPlot(int type, unsigned int blockIndex);
191 
195  vtkIdType AddPlot(vtkPlot* plot) override;
196 
200  virtual vtkIdType AddPlot(vtkPlot* plot, unsigned int blockIndex);
201 
206  bool RemovePlot(vtkIdType index) override;
207 
211  void ClearPlots() override;
212 
217 
223 
230 
237  virtual vtkIdType StackPlotAbove(vtkPlot* plot, vtkPlot* under);
238 
245 
252  virtual vtkIdType StackPlotUnder(vtkPlot* plot, vtkPlot* above);
253 
258 
262  int GetPlotCorner(vtkPlot* plot);
263 
267  void SetPlotCorner(vtkPlot* plot, int corner);
268 
274  vtkAxis* GetAxis(int axisIndex) override;
275 
281  void SetAxis(int axisIndex, vtkAxis*) override;
282 
286  void SetShowLegend(bool visible) override;
287 
292 
296  virtual void SetTooltip(vtkTooltipItem* tooltip);
297 
302 
307 
312  void RecalculateBounds() override;
313 
321  void SetSelectionMethod(int method) override;
322 
327 
329 
332  vtkSetMacro(DrawAxesAtOrigin, bool);
333  vtkGetMacro(DrawAxesAtOrigin, bool);
334  vtkBooleanMacro(DrawAxesAtOrigin, bool);
336 
338 
342  vtkSetMacro(AutoAxes, bool);
343  vtkGetMacro(AutoAxes, bool);
344  vtkBooleanMacro(AutoAxes, bool);
346 
348 
351  vtkSetMacro(HiddenAxisBorder, int);
352  vtkGetMacro(HiddenAxisBorder, int);
354 
356 
361  vtkSetMacro(ForceAxesToBounds, bool);
362  vtkGetMacro(ForceAxesToBounds, bool);
363  vtkBooleanMacro(ForceAxesToBounds, bool);
365 
367 
373  vtkSetMacro(IgnoreNanInBounds, bool);
374  vtkGetMacro(IgnoreNanInBounds, bool);
375  vtkBooleanMacro(IgnoreNanInBounds, bool);
377 
379 
386  vtkSetMacro(BarWidthFraction, float);
387  vtkGetMacro(BarWidthFraction, float);
389 
391 
397  vtkSetMacro(ZoomWithMouseWheel, bool);
398  vtkGetMacro(ZoomWithMouseWheel, bool);
399  vtkBooleanMacro(ZoomWithMouseWheel, bool);
401 
403 
408  vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
409  vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
410  vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
412 
414 
419  vtkSetMacro(DragPointAlongX, bool);
420  vtkGetMacro(DragPointAlongX, bool);
421  vtkBooleanMacro(DragPointAlongX, bool);
423 
425 
430  vtkSetMacro(DragPointAlongY, bool);
431  vtkGetMacro(DragPointAlongY, bool);
432  vtkBooleanMacro(DragPointAlongY, bool);
434 
439  vtkIdType segmentIndex = -1);
440 
444  bool Hit(const vtkContextMouseEvent& mouse) override;
445 
449  bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
450 
454  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
455 
459  bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
460 
464  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
465 
469  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
470 
474  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
475 
479  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
480 
481  typedef std::map<unsigned int, vtkSmartPointer<vtkIdTypeArray>> MapIndexToIds;
482 
487  static void MakeSelection(vtkAnnotationLink* link, const MapIndexToIds& selection);
488 
492  const std::vector<vtkContextTransform*>& GetTransforms() const;
493 
498  static void MakeSelection(vtkAnnotationLink* link, vtkIdTypeArray* selectionIds, vtkPlot* plot);
499 
503  static void MinusSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
504 
508  static void AddSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
509 
513  static void ToggleSelection(vtkIdTypeArray* selection, vtkIdTypeArray* oldSelection);
514 
521  static void BuildSelection(vtkAnnotationLink* link, int selectionMode,
522  vtkIdTypeArray* plotSelection, vtkIdTypeArray* oldSelection, vtkPlot* plot);
523 
530  static void BuildSelection(
531  int selectionMode, MapIndexToIds& selection, const MapIndexToIds& oldSelection);
532 
537  static int GetMouseSelectionMode(const vtkContextMouseEvent& mouse, int selectionMode);
538 
539 protected:
541  ~vtkChartXY() override;
542 
547 
553 
559  virtual bool UpdateLayout(vtkContext2D* painter);
560 
566  virtual int GetLegendBorder(vtkContext2D* painter, int axisPosition);
567 
572  virtual void SetLegendPosition(const vtkRectf& rect);
573 
578 
583 
588 
593 
597  bool DrawBox;
598 
604 
609 
614 
621 
625  bool AutoAxes;
626 
631 
637 
644 
652 
658 
664 
670 
671 private:
672  vtkChartXY(const vtkChartXY&) = delete;
673  void operator=(const vtkChartXY&) = delete;
674 
675  vtkChartXYPrivate* ChartPrivate; // Private class where I hide my STL containers
676 
681  bool DragPoint;
682 
686  void CalculateBarPlots();
687 
693  bool LocatePointInPlots(const vtkContextMouseEvent& mouse, int invokeEvent = -1);
694 
695  int LocatePointInPlot(const vtkVector2f& position, const vtkVector2f& tolerance,
696  vtkVector2f& plotPos, vtkPlot* plot, vtkIdType& segmentIndex);
697 
701  bool RemovePlotFromCorners(vtkPlot* plot);
702 
703  void ZoomInAxes(vtkAxis* x, vtkAxis* y, float* originf, float* max);
704 
709  void ReleasePlotSelections();
710 
714  void TransformBoxOrPolygon(bool polygonMode, vtkTransform2D* transform,
715  const vtkVector2f& mousePosition, vtkVector2f& min, vtkVector2f& max,
716  vtkContextPolygon& polygon);
717 };
718 
720 
726 {
730  int Index;
731 };
733 
734 #endif // vtkChartXY_h
vtkChart
Factory class for drawing 2D charts.
Definition: vtkChart.h:45
vtkChartXY::MouseBox
vtkRectf MouseBox
The box created as the mouse is dragged around the screen.
Definition: vtkChartXY.h:592
vtkContextPolygon.h
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:54
vtkChartXY::MouseLeaveEvent
bool MouseLeaveEvent(const vtkContextMouseEvent &mouse) override
Mouse leave event.
vtkChartXY::GetPlotIndex
virtual vtkIdType GetPlotIndex(vtkPlot *)
Get the index of the specified plot, returns -1 if the plot does not belong to the chart.
vtkContextKeyEvent
data structure to represent key events.
Definition: vtkContextKeyEvent.h:35
vtkChartXY::StackPlotAbove
virtual vtkIdType StackPlotAbove(vtkPlot *plot, vtkPlot *under)
Raises the plot above the under plot.
vtkChartXY::Legend
vtkSmartPointer< vtkChartLegend > Legend
The legend for the chart.
Definition: vtkChartXY.h:577
vtkChartXY::MouseButtonReleaseEvent
bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override
Mouse button release event.
vtkChartXY::IgnoreNanInBounds
bool IgnoreNanInBounds
Property to ignore NaN in RecalculateBounds().
Definition: vtkChartXY.h:651
vtkChartXY::GetNumberOfAxes
vtkIdType GetNumberOfAxes() override
Get the number of axes in the current chart.
vtkChartXY::AddSelection
static void AddSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Add the supplied selection from the oldSelection.
vtkChartXY::~vtkChartXY
~vtkChartXY() override
vtkChartXY::SetShowLegend
void SetShowLegend(bool visible) override
Set whether the chart should draw a legend.
vtkX3D::type
@ type
Definition: vtkX3D.h:522
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkChartPlotData
Small struct used by InvokeEvent to send some information about the point that was clicked on.
Definition: vtkChartXY.h:726
vtkChartXY::RaisePlot
vtkIdType RaisePlot(vtkPlot *plot)
Raises the plot to the top of the plot's stack.
vtkChartXY::GetMouseSelectionMode
static int GetMouseSelectionMode(const vtkContextMouseEvent &mouse, int selectionMode)
Combine the SelectionMode with any mouse modifiers to get an effective selection mode for this click ...
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:46
vtkChartXY::MouseWheelEvent
bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta) override
Mouse wheel event, positive delta indicates forward movement of the wheel.
vtkX3D::key
@ key
Definition: vtkX3D.h:263
vtkChartLegend
draw the chart legend
Definition: vtkChartLegend.h:69
vtkChart.h
vtkChartXY::Hit
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
vtkChartPlotData::SeriesName
vtkStdString SeriesName
Definition: vtkChartXY.h:727
vtkChartXY::Tooltip
vtkSmartPointer< vtkTooltipItem > Tooltip
The tooltip item for the chart - can be used to display extra information.
Definition: vtkChartXY.h:582
vtkSmartPointer< vtkChartLegend >
vtkVector.h
vtkChartXY::SetLegendPosition
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...
vtkChartXY::LowerPlot
vtkIdType LowerPlot(vtkPlot *plot)
Lowers the plot to the bottom of the plot's stack.
vtkTooltipItem
takes care of drawing 2D axes
Definition: vtkTooltipItem.h:40
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:73
vtkChartXY::DragPointAlongX
bool DragPointAlongX
Properties to enable the drag of a point for the ClickAndDrag Action.
Definition: vtkChartXY.h:668
vtkChartXY::MouseEnterEvent
bool MouseEnterEvent(const vtkContextMouseEvent &mouse) override
Mouse enter event.
vtkPlot
Abstract class for 2D plots.
Definition: vtkPlot.h:157
vtkChartXY::AutoAxes
bool AutoAxes
Should axes be turned on and off automatically - defaults to on.
Definition: vtkChartXY.h:625
vtkMultiBlockDataSet
Composite dataset that organizes datasets into blocks.
Definition: vtkMultiBlockDataSet.h:155
vtkChartXY::BarWidthFraction
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:636
vtkChartXY::DrawNearestPoint
bool DrawNearestPoint
Should we draw the location of the nearest point on the plot?
Definition: vtkChartXY.h:613
vtkChartXY::GetPlot
vtkPlot * GetPlot(vtkIdType index) override
Get the plot at the specified index, returns null if the index is invalid.
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkVector2d
Definition: vtkVector.h:503
vtkChartXY::Update
void Update() override
Perform any updates to the item that may be necessary before rendering.
vtkChartXY::ZoomWithMouseWheel
bool ZoomWithMouseWheel
Property to enable zooming the chart with the mouse wheel.
Definition: vtkChartXY.h:657
vtkX3D::position
@ position
Definition: vtkX3D.h:267
vtkChartXY::KeyPressEvent
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Key press event.
vtkChartXY::MakeSelection
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...
vtkChartXY::DragPointAlongY
bool DragPointAlongY
Definition: vtkChartXY.h:669
vtkChartXY::MinusSelection
static void MinusSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Subtract the supplied selection from the oldSelection.
vtkChartXY::DrawAxesAtOrigin
bool DrawAxesAtOrigin
Keep the axes drawn at the origin? This will attempt to keep the axes drawn at the origin,...
Definition: vtkChartXY.h:620
vtkChartXY::GetNumberOfPlots
vtkIdType GetNumberOfPlots() override
Get the number of plots the chart contains.
vtkChartXY::RecalculatePlotBounds
void RecalculatePlotBounds()
Calculate the optimal zoom level such that all of the points to be plotted will fit into the plot are...
vtkChartXY::MakeSelection
static void MakeSelection(vtkAnnotationLink *link, vtkIdTypeArray *selectionIds, vtkPlot *plot)
Populate the annotation link with the supplied selectionIds array, and set the appropriate node prope...
vtkChartXY::New
static vtkChartXY * New()
Creates a 2D Chart object.
vtkChartXY::SetSelectionMethod
void SetSelectionMethod(int method) override
Set the selection method, which controls how selections are handled by the chart.
vtkChartXY::AddPlot
virtual vtkPlot * AddPlot(int type, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
vtkChartXY::GetLegend
vtkChartLegend * GetLegend() override
Get the vtkChartLegend object that will be displayed by the chart.
vtkPlotGrid
takes care of drawing the plot grid
Definition: vtkPlotGrid.h:39
vtkChartXY::AdjustLowerBoundForLogPlot
bool AdjustLowerBoundForLogPlot
Property to adjust the minimum of a logarithmic axis to be greater than 0, regardless of the minimum ...
Definition: vtkChartXY.h:663
vtkChartXY::ForceAxesToBounds
bool ForceAxesToBounds
Property to force the axes to have their Minimum and Maximum properties inside the plot boundaries.
Definition: vtkChartXY.h:643
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkChartXY::PlotTransformValid
bool PlotTransformValid
Does the plot area transform need to be recalculated?
Definition: vtkChartXY.h:587
vtkChartXY::GetTooltip
virtual vtkTooltipItem * GetTooltip()
Get the vtkTooltipItem object that will be displayed by the chart.
vtkChartXY::MouseButtonPressEvent
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse button down event.
vtkChartXY::AddPlot
vtkIdType AddPlot(vtkPlot *plot) override
Adds a plot to the chart.
vtkChartXY::SetAxis
void SetAxis(int axisIndex, vtkAxis *) override
Set the axis specified by axisIndex.
vtkChartXY::RecalculatePlotTransforms
void RecalculatePlotTransforms()
Recalculate the necessary transforms.
vtkSmartPointer.h
vtkChartXY::BuildSelection
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...
vtkChartXY::GetAxis
vtkAxis * GetAxis(int axisIndex) override
Get the axis specified by axisIndex.
vtkChartXY::RemovePlot
bool RemovePlot(vtkIdType index) override
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
vtkChartXY::MouseMoveEvent
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse move event.
vtkContextPolygon
Definition: vtkContextPolygon.h:27
vtkChartXY::GetLegendBorder
virtual int GetLegendBorder(vtkContext2D *painter, int axisPosition)
Layout for the legend if it is visible.
vtkChartXY::ClearPlots
void ClearPlots() override
Remove all plots from the chart.
vtkChartPlotData::ScreenPosition
vtkVector2i ScreenPosition
Definition: vtkChartXY.h:729
vtkChartXY::HiddenAxisBorder
int HiddenAxisBorder
Size of the border when an axis is hidden.
Definition: vtkChartXY.h:630
vtkChartXY::RemovePlotSelections
void RemovePlotSelections()
Remove all the selection from Plots.
vtkChartXY::AddPlot
virtual vtkIdType AddPlot(vtkPlot *plot, unsigned int blockIndex)
Adds a plot to the chart holding data specific to a block in a vtkMultiBlockDataSet.
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:145
vtkChartXY::GetTransforms
const std::vector< vtkContextTransform * > & GetTransforms() const
Get the vector of vtkContextTransform.
vtkAxis
takes care of drawing 2D axes
Definition: vtkAxis.h:178
vtkChartXY::SetTooltipInfo
virtual void SetTooltipInfo(const vtkContextMouseEvent &, const vtkVector2d &, vtkIdType, vtkPlot *, vtkIdType segmentIndex=-1)
Set the information passed to the tooltip.
vtkChartPlotData::Position
vtkVector2f Position
Definition: vtkChartXY.h:728
vtkChartXY::SelectionPolygon
vtkContextPolygon SelectionPolygon
The polygon created as the mouse is dragged around the screen when in polygonal selection mode.
Definition: vtkChartXY.h:603
vtkChartXY::BuildSelection
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...
vtkChartXY::UpdateLayout
virtual bool UpdateLayout(vtkContext2D *painter)
Update the layout of the chart, this may require the vtkContext2D in order to get font metrics etc.
vtkVector2i
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:478
vtkChartPlotData::Index
int Index
Definition: vtkChartXY.h:730
vtkChartXY
Factory class for drawing XY charts.
Definition: vtkChartXY.h:160
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkChartXY::GetPlotCorner
int GetPlotCorner(vtkPlot *plot)
Figure out which quadrant the plot is in.
vtkChartXY::DrawSelectionPolygon
bool DrawSelectionPolygon
Should the selection polygon be drawn.
Definition: vtkChartXY.h:608
vtkChartXY::AddPlot
vtkPlot * AddPlot(int type) override
Add a plot to the chart, defaults to using the name of the y column.
vtkChartXY::RecalculateBounds
void RecalculateBounds() override
Request that the chart recalculates the range of its axes.
vtkChartXY::DrawBox
bool DrawBox
Should the box be drawn (could be selection, zoom etc).
Definition: vtkChartXY.h:597
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkChartXY::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkRectf
Definition: vtkRect.h:336
vtkVector2f
Definition: vtkVector.h:491
vtkChartXY::StackPlotUnder
virtual vtkIdType StackPlotUnder(vtkPlot *plot, vtkPlot *above)
Lowers the plot under the above plot.
vtkChartXY::SetPlotCorner
void SetPlotCorner(vtkPlot *plot, int corner)
Figure out which quadrant the plot is in.
vtkChartXY::MapIndexToIds
std::map< unsigned int, vtkSmartPointer< vtkIdTypeArray > > MapIndexToIds
Definition: vtkChartXY.h:481
vtkChartXY::ToggleSelection
static void ToggleSelection(vtkIdTypeArray *selection, vtkIdTypeArray *oldSelection)
Toggle the supplied selection from the oldSelection.
vtkChartXY::vtkChartXY
vtkChartXY()
vtkChartXY::Paint
bool Paint(vtkContext2D *painter) override
Paint event for the chart, called whenever the chart needs to be drawn.
vtkChartXY::SetTooltip
virtual void SetTooltip(vtkTooltipItem *tooltip)
Set the vtkTooltipItem object that will be displayed by the chart.