VTK  9.1.0
vtkChart.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkChart.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
33#ifndef vtkChart_h
34#define vtkChart_h
35
36#include "vtkChartsCoreModule.h" // For export macro
37#include "vtkContextItem.h"
38#include "vtkRect.h" // For vtkRectf
39#include "vtkSmartPointer.h" // For SP ivars
40#include "vtkStdString.h" // For vtkStdString ivars
41
42class vtkTransform2D;
43class vtkContextScene;
44class vtkPlot;
45class vtkAxis;
46class vtkBrush;
47class vtkTextProperty;
48class vtkChartLegend;
49
52
53class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem
54{
55public:
56 vtkTypeMacro(vtkChart, vtkContextItem);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
62 enum
63 {
70 AREA
71 };
72
85 enum
86 {
87 PAN = 0,
91 SELECT_RECTANGLE = SELECT,
94 NOTIFY
95 };
96
101 {
102 UpdateRange = 1002
103 };
104
108 bool Paint(vtkContext2D* painter) override = 0;
109
113 virtual vtkPlot* AddPlot(int type);
114
118 virtual vtkIdType AddPlot(vtkPlot* plot);
119
125
131 virtual bool RemovePlotInstance(vtkPlot* plot);
132
136 virtual void ClearPlots();
137
142
147
152 virtual vtkAxis* GetAxis(int axisIndex);
153
158 virtual void SetAxis(int axisIndex, vtkAxis*);
159
164
169 virtual void RecalculateBounds();
170
178 enum
179 {
182 SELECTION_COLUMNS
183 };
184
186
194 virtual void SetSelectionMethod(int method);
195 virtual int GetSelectionMethod();
197
202
204
207 vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
209
211
214 vtkSetVector2Macro(Geometry, int);
215 vtkGetVector2Macro(Geometry, int);
217
219
222 vtkSetVector2Macro(Point1, int);
223 vtkGetVector2Macro(Point1, int);
225
227
230 vtkSetVector2Macro(Point2, int);
231 vtkGetVector2Macro(Point2, int);
233
235
238 virtual void SetShowLegend(bool visible);
239 virtual bool GetShowLegend();
241
247
249
252 virtual void SetTitle(const vtkStdString& title);
255
257
260 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
262
264
267 void SetBottomBorder(int border);
268 void SetTopBorder(int border);
269 void SetLeftBorder(int border);
270 void SetRightBorder(int border);
272
276 void SetBorders(int left, int bottom, int right, int top);
277
283 void SetSize(const vtkRectf& rect);
284
289
293 enum
294 {
295 FILL_SCENE, // Attempt to fill the entire scene.
296 FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
297 AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
298 };
299
301
306 vtkSetMacro(LayoutStrategy, int);
307 vtkGetMacro(LayoutStrategy, int);
309
311
315 virtual void SetAutoSize(bool isAutoSized)
316 {
317 this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
318 }
319 virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
321
323
331 vtkSetMacro(RenderEmpty, bool);
332 vtkGetMacro(RenderEmpty, bool);
334
345 virtual void SetActionToButton(int action, int button);
346
351 virtual int GetActionToButton(int action);
352
358 virtual void SetClickActionToButton(int action, int button);
359
365 virtual int GetClickActionToButton(int action);
366
368
374
376
381 virtual void SetSelectionMode(int);
382 vtkGetMacro(SelectionMode, int);
384
385protected:
387 ~vtkChart() override;
388
396
401
406
407 void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
408
413
417 int Geometry[2];
418
422 int Point1[2];
423
427 int Point2[2];
428
433
438
443
445 // The layout strategy to employ when fitting the chart into the space.
448
453
454 // The mode when the chart is doing selection.
456
457 // How plot selections are handled, SELECTION_ROWS (default) or
458 // SELECTION_PLOTS - based on the plot that created the selection.
460
462
466 {
467 public:
469 enum
470 {
471 MaxAction = 6
472 };
473 short& Pan() { return Data[0]; }
474 short& Zoom() { return Data[1]; }
475 short& ZoomAxis() { return Data[2]; }
476 short& Select() { return Data[3]; }
477 short& SelectPolygon() { return Data[4]; }
478 short& ClickAndDrag() { return Data[5]; }
479 short& operator[](int index) { return Data[index]; }
480 short Data[MaxAction];
481 };
483 {
484 public:
486 short& Notify() { return Data[0]; }
487 short& Select() { return Data[1]; }
488 short& operator[](int index) { return Data[index]; }
489 short Data[2];
490 };
492
495
496private:
497 vtkChart(const vtkChart&) = delete;
498 void operator=(const vtkChart&) = delete;
499};
500
501#endif // vtkChart_h
takes care of drawing 2D axes
Definition: vtkAxis.h:78
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:47
draw the chart legend
Hold mouse action mappings.
Definition: vtkChart.h:466
short & operator[](int index)
Definition: vtkChart.h:479
short & ClickAndDrag()
Definition: vtkChart.h:478
short & SelectPolygon()
Definition: vtkChart.h:477
short & operator[](int index)
Definition: vtkChart.h:488
Factory class for drawing 2D charts.
Definition: vtkChart.h:54
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:494
void AxisRangeForwarderCallback(vtkObject *, unsigned long, void *)
virtual void SetAutoSize(bool isAutoSized)
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:315
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:446
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:437
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:442
@ SELECT_POLYGON
Definition: vtkChart.h:92
@ CLICK_AND_DRAG
Definition: vtkChart.h:93
@ ZOOM_AXIS
Definition: vtkChart.h:89
@ SELECT
Definition: vtkChart.h:90
@ ZOOM
Definition: vtkChart.h:88
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:319
int SelectionMethod
Definition: vtkChart.h:459
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.
MouseActions Actions
Definition: vtkChart.h:493
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:412
vtkRectf GetSize()
Get the current size of the chart.
@ FUNCTIONALBAG
Definition: vtkChart.h:69
@ LINE
Definition: vtkChart.h:64
@ STACKED
Definition: vtkChart.h:67
@ POINTS
Definition: vtkChart.h:65
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
@ SELECTION_PLOTS
Definition: vtkChart.h:181
@ SELECTION_ROWS
Definition: vtkChart.h:180
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition: vtkChart.h:444
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:452
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
@ FILL_SCENE
Definition: vtkChart.h:295
@ FILL_RECT
Definition: vtkChart.h:296
EventIds
Enum of event type that are triggered by the charts.
Definition: vtkChart.h:101
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition: vtkChart.h:455
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition: vtkChart.h:447
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.
void SetSize(const vtkRectf &rect)
Set the size of the chart.
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.
virtual void SetSelectionMode(int)
Set/get the Selection Mode that will be used by the chart while doing selection.
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.
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.
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:432
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.
Definition: vtkContext2D.h:63
base class for items that are part of a vtkContextScene.
Provides a 2D scene for vtkContextItem objects.
a simple class to control print indentation
Definition: vtkIndent.h:43
provide event-driven interface to the rendering window (defines trackball mode)
abstract base class for most VTK objects
Definition: vtkObject.h:63
Abstract class for 2D plots.
Definition: vtkPlot.h:57
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:45
represent text properties.
describes linear transformations via a 3x3 matrix
@ top
Definition: vtkX3D.h:508
@ type
Definition: vtkX3D.h:522
@ bottom
Definition: vtkX3D.h:296
@ index
Definition: vtkX3D.h:252
@ title
Definition: vtkX3D.h:506
int vtkIdType
Definition: vtkType.h:332