VTK  9.6.1
vtkChart.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
17
18#ifndef vtkChart_h
19#define vtkChart_h
20
21#include "vtkChartsCoreModule.h" // For export macro
22#include "vtkContextItem.h"
23#include "vtkContextScene.h" // For SelectionModifier
24#include "vtkRect.h" // For vtkRectf
25#include "vtkSmartPointer.h" // For SP ivars
26#include "vtkStdString.h" // For vtkStdString ivars
27#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
28
29VTK_ABI_NAMESPACE_BEGIN
30class vtkTransform2D;
31class vtkContextScene;
32class vtkPlot;
33class vtkAxis;
34class vtkBrush;
35class vtkTextProperty;
36class vtkChartLegend;
37
40
41class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChart : public vtkContextItem
42{
43public:
44 vtkTypeMacro(vtkChart, vtkContextItem);
45 void PrintSelf(ostream& os, vtkIndent indent) override;
46
50 enum
51 {
59 };
60
75 enum
76 {
77 PAN = 0,
78 ZOOM = 1,
80 SELECT = 3,
84 NOTIFY = 6,
86 };
87
92 {
94 };
95
99 bool Paint(vtkContext2D* painter) override = 0;
100
104 virtual vtkPlot* AddPlot(int type);
105
109 virtual vtkIdType AddPlot(vtkPlot* plot);
110
115 virtual bool RemovePlot(vtkIdType index);
116
122 virtual bool RemovePlotInstance(vtkPlot* plot);
123 bool RemovePlot(vtkPlot* plot) { return this->RemovePlotInstance(plot); }
124
128 virtual void ClearPlots();
129 void RemoveAllPlots() { this->ClearPlots(); }
130
134 virtual vtkPlot* GetPlot(vtkIdType index);
135
140
145 virtual vtkAxis* GetAxis(int axisIndex);
146
151 virtual void SetAxis(int axisIndex, vtkAxis*);
152
157
162 virtual void RecalculateBounds();
163
171 enum
172 {
176 };
177
179
187 virtual void SetSelectionMethod(int method);
188 virtual int GetSelectionMethod();
190
195
197
202
204
207 vtkSetVector2Macro(Geometry, int);
208 vtkGetVector2Macro(Geometry, int);
210
212
215 vtkSetVector2Macro(Point1, int);
216 vtkGetVector2Macro(Point1, int);
218
220
223 vtkSetVector2Macro(Point2, int);
224 vtkGetVector2Macro(Point2, int);
226
228
231 virtual void SetShowLegend(bool visible);
232 virtual bool GetShowLegend();
234
240
242
245 virtual void SetTitle(const vtkStdString& title);
248
250
253 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
255
257
260 void SetBottomBorder(int border);
261 void SetTopBorder(int border);
262 void SetLeftBorder(int border);
263 void SetRightBorder(int border);
265
269 void SetBorders(int left, int bottom, int right, int top);
270
276 virtual void SetSize(const vtkRectf& rect);
277
282
286 enum
287 {
288 FILL_SCENE, // Attempt to fill the entire scene.
289 FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
290 AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
291 };
292
294
299 vtkSetMacro(LayoutStrategy, int);
300 vtkGetMacro(LayoutStrategy, int);
302
304
308 virtual void SetAutoSize(bool isAutoSized)
309 {
311 }
312 virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
314
316
324 vtkSetMacro(RenderEmpty, bool);
325 vtkGetMacro(RenderEmpty, bool);
327
338 virtual void SetActionToButton(int action, int button);
339
344 virtual int GetActionToButton(int action);
345
351 virtual void SetClickActionToButton(int action, int button);
352
358 virtual int GetClickActionToButton(int action);
359
361
367
369
373 vtkSetClampMacro(
375 vtkGetMacro(SelectionMode, int);
377
379
387 const vtkContextMouseEvent& mouseEvent, int currentSelectionMode);
389
390protected:
392 ~vtkChart() override;
393
401
406
411
412 void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
413
418
422 int Geometry[2];
423
427 int Point1[2];
428
432 int Point2[2];
433
437 int Borders[4];
438
443
448
453
455 // The layout strategy to employ when fitting the chart into the space.
458
463
464 // The mode when the chart is doing selection.
466
467 // How plot selections are handled, SELECTION_ROWS (default) or
468 // SELECTION_PLOTS - based on the plot that created the selection.
470
472
476 {
477 public:
479 enum
480 {
482 };
483 short& Pan() { return Data[0]; }
484 short& Zoom() { return Data[1]; }
485 short& ZoomAxis() { return Data[2]; }
486 short& Select() { return Data[3]; }
487 short& SelectPolygon() { return Data[4]; }
488 short& ClickAndDrag() { return Data[5]; }
489 short& operator[](int index) { return Data[index]; }
491 };
493 {
494 public:
496 short& Notify() { return Data[0]; }
497 short& Select() { return Data[1]; }
498 short& operator[](int index) { return Data[index]; }
499 short Data[2];
500 };
501
502
505
506private:
507 vtkChart(const vtkChart&) = delete;
508 void operator=(const vtkChart&) = delete;
509};
510
511VTK_ABI_NAMESPACE_END
512#endif // vtkChart_h
takes care of drawing 2D axes
Definition vtkAxis.h:62
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:31
draw the chart legend
Hold mouse action mappings.
Definition vtkChart.h:476
short Data[MaxAction]
Definition vtkChart.h:490
short & operator[](int index)
Definition vtkChart.h:489
short & SelectPolygon()
Definition vtkChart.h:487
short & operator[](int index)
Definition vtkChart.h:498
virtual vtkPlot * AddPlot(int type)
Add a plot to the chart, defaults to using the name of the y column.
MouseClickActions ActionsClick
Definition vtkChart.h:504
void AxisRangeForwarderCallback(vtkObject *, unsigned long, void *)
bool RemovePlot(vtkPlot *plot)
Definition vtkChart.h:123
virtual void SetSize(const vtkRectf &rect)
Set the size of the chart.
virtual void SetAutoSize(bool isAutoSized)
Set/get whether the chart should automatically resize to fill the current render window.
Definition vtkChart.h:308
@ FUNCTIONALBAG
Definition vtkChart.h:57
@ STACKED
Definition vtkChart.h:55
int Point2[2]
The position of the upper right corner of the chart.
Definition vtkChart.h:432
virtual bool GetShowLegend()
Set/get whether the chart should draw a legend.
virtual vtkStdString GetTitle()
Get/set the title text of the chart.
virtual void ClearPlots()
Remove all plots from the chart.
int LayoutStrategy
Definition vtkChart.h:456
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the chart.
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
vtkStdString Title
The title of the chart.
Definition vtkChart.h:447
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition vtkChart.h:452
static int GetSelectionModeFromMouseModifiers(const vtkContextMouseEvent &mouseEvent, int currentSelectionMode)
Return the selection mode associated to the mouse event modifiers for a specific mouse event.
bool CalculateUnscaledPlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform)
Calculate the unshifted, and unscaled plot transform for the x and y axis.
virtual bool GetAutoSize()
Set/get whether the chart should automatically resize to fill the current render window.
Definition vtkChart.h:312
int SelectionMethod
Definition vtkChart.h:469
virtual void SetAnnotationLink(vtkAnnotationLink *link)
Set the vtkAnnotationLink for the chart.
virtual int GetActionToButton(int action)
Get the mouse button associated with the supplied action.
@ SELECT_RECTANGLE
Definition vtkChart.h:81
@ ACTION_TYPES_COUNT
Definition vtkChart.h:85
@ SELECT_POLYGON
Definition vtkChart.h:82
@ CLICK_AND_DRAG
Definition vtkChart.h:83
@ ZOOM_AXIS
Definition vtkChart.h:79
@ SELECTION_COLUMNS
Definition vtkChart.h:175
@ SELECTION_PLOTS
Definition vtkChart.h:174
@ SELECTION_ROWS
Definition vtkChart.h:173
MouseActions Actions
Definition vtkChart.h:503
void SetRightBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
vtkAnnotationLink * AnnotationLink
Our annotation link, used for sharing selections etc.
Definition vtkChart.h:417
vtkRectf GetSize()
Get the current size of the chart.
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
int GetSelectionModeFromMouseModifiers(const vtkContextMouseEvent &mouseEvent)
Return the selection mode associated to the mouse event modifiers for a specific mouse event.
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition vtkChart.h:454
virtual void SetSelectionMethod(int method)
Set the selection method, which controls how selections are handled by the chart.
vtkSmartPointer< vtkBrush > BackgroundBrush
Brush to use for drawing the background.
Definition vtkChart.h:462
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
EventIds
Enum of event type that are triggered by the charts.
Definition vtkChart.h:92
@ UpdateRange
Definition vtkChart.h:93
int Point1[2]
The position of the lower left corner of the chart.
Definition vtkChart.h:427
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition vtkChart.h:465
int Geometry[2]
The width and the height of the chart.
Definition vtkChart.h:422
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition vtkChart.h:457
void SetBackgroundBrush(vtkBrush *brush)
Set/Get the brush to use for the background color.
bool Paint(vtkContext2D *painter) override=0
Paint event for the chart, called whenever the chart needs to be drawn.
virtual void SetShowLegend(bool visible)
Set/get whether the chart should draw a legend.
virtual vtkIdType GetNumberOfPlots()
Get the number of plots the chart contains.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void RecalculateBounds()
Request that the chart recalculates the range of its axes.
virtual void SetAxis(int axisIndex, vtkAxis *)
Set the axis specified by axisIndex.
int Borders[4]
The borders around the chart.
Definition vtkChart.h:437
virtual bool RemovePlot(vtkIdType index)
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
virtual vtkAxis * GetAxis(int axisIndex)
Get the axis specified by axisIndex.
virtual vtkIdType GetNumberOfAxes()
Get the number of axes in the current chart.
virtual void SetActionToButton(int action, int button)
Assign action types to mouse buttons.
void AttachAxisRangeListener(vtkAxis *)
Attach axis range listener so we can forward those events at the chart level.
virtual vtkIdType AddPlot(vtkPlot *plot)
Add a plot to the chart.
void RemoveAllPlots()
Definition vtkChart.h:129
virtual vtkPlot * GetPlot(vtkIdType index)
Get the plot at the specified index, returns null if the index is invalid.
virtual int GetSelectionMethod()
Set the selection method, which controls how selections are handled by the chart.
bool CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform)
Given the x and y vtkAxis, and a transform, calculate the transform that the points in a chart would ...
vtkBrush * GetBackgroundBrush()
Set/Get the brush to use for the background color.
@ FILL_SCENE
Definition vtkChart.h:288
@ FILL_RECT
Definition vtkChart.h:289
@ AXES_TO_RECT
Definition vtkChart.h:290
void SetLeftBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
~vtkChart() override
bool ShowLegend
Display the legend?
Definition vtkChart.h:442
void SetBorders(int left, int bottom, int right, int top)
Set/get the borders of the chart (space in pixels around the chart).
Class for drawing 2D primitives to a graphical context.
vtkContextItem()=default
data structure to represent mouse events.
Provides a 2D scene for vtkContextItem objects.
a simple class to control print indentation
Definition vtkIndent.h:29
provide event-driven interface to the rendering window (defines trackball mode)
Abstract class for 2D plots.
Definition vtkPlot.h:44
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
represent text properties.
describes linear transformations via a 3x3 matrix
int vtkIdType
Definition vtkType.h:368
#define VTK_MARSHALAUTO