VTK  9.1.0
vtkAxis.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkAxis.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
60#ifndef vtkAxis_h
61#define vtkAxis_h
62
63#include "vtkChartsCoreModule.h" // For export macro
64#include "vtkContextItem.h"
65#include "vtkRect.h" // For bounding rect
66#include "vtkSmartPointer.h" // For vtkSmartPointer
67#include "vtkStdString.h" // For vtkStdString ivars
68#include "vtkVector.h" // For position variables
69
70class vtkContext2D;
71class vtkPen;
72class vtkFloatArray;
73class vtkDoubleArray;
74class vtkStringArray;
75class vtkTextProperty;
76
77class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
78{
79public:
80 vtkTypeMacro(vtkAxis, vtkContextItem);
81 void PrintSelf(ostream& os, vtkIndent indent) override;
82
88 {
89 LEFT = 0,
93 PARALLEL
94 };
95
96 enum
97 {
98 TICK_SIMPLE = 0,
99 TICK_WILKINSON_EXTENDED
100 };
101
105 static vtkAxis* New();
106
108
111 virtual void SetPosition(int position);
112 vtkGetMacro(Position, int);
114
116
119 void SetPoint1(const vtkVector2f& pos);
120 void SetPoint1(float x, float y);
122
124
127 vtkGetVector2Macro(Point1, float);
130
132
135 void SetPoint2(const vtkVector2f& pos);
136 void SetPoint2(float x, float y);
138
140
143 vtkGetVector2Macro(Point2, float);
146
151 virtual void SetNumberOfTicks(int numberOfTicks);
152
154
157 vtkGetMacro(NumberOfTicks, int);
159
161
164 vtkSetMacro(TickLength, float);
165 vtkGetMacro(TickLength, float);
167
169
173 vtkGetObjectMacro(LabelProperties, vtkTextProperty);
175
181 virtual void SetMinimum(double minimum);
182
184
189 vtkGetMacro(Minimum, double);
191
197 virtual void SetMaximum(double maximum);
198
200
205 vtkGetMacro(Maximum, double);
207
213 virtual void SetUnscaledMinimum(double minimum);
214
216
219 vtkGetMacro(UnscaledMinimum, double);
221
225 virtual void SetUnscaledMaximum(double maximum);
226
228
231 vtkGetMacro(UnscaledMaximum, double);
233
235
244 virtual void SetRange(double minimum, double maximum);
245 virtual void SetRange(double range[2]);
246 virtual void SetUnscaledRange(double minimum, double maximum);
247 virtual void SetUnscaledRange(double range[2]);
249
251
258 virtual void GetRange(double* range);
259 virtual void GetUnscaledRange(double* range);
261
265 virtual void SetMinimumLimit(double lowest);
266
268
271 vtkGetMacro(MinimumLimit, double);
273
277 virtual void SetMaximumLimit(double highest);
278
280
283 vtkGetMacro(MaximumLimit, double);
285
289 virtual void SetUnscaledMinimumLimit(double lowest);
290
292
295 vtkGetMacro(UnscaledMinimumLimit, double);
297
301 virtual void SetUnscaledMaximumLimit(double highest);
302
304
307 vtkGetMacro(UnscaledMaximumLimit, double);
309
311
314 vtkGetVector2Macro(Margins, int);
316
318
321 vtkSetVector2Macro(Margins, int);
323
325
328 virtual void SetTitle(const vtkStdString& title);
331
333
336 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
338
340
352 vtkGetMacro(LogScaleActive, bool);
354
356
362 vtkGetMacro(LogScale, bool);
363 virtual void SetLogScale(bool logScale);
364 vtkBooleanMacro(LogScale, bool);
366
368
371 vtkSetMacro(GridVisible, bool);
372 vtkGetMacro(GridVisible, bool);
374
376
379 vtkSetMacro(LabelsVisible, bool);
380 vtkGetMacro(LabelsVisible, bool);
382
384
387 vtkSetMacro(RangeLabelsVisible, bool);
388 vtkGetMacro(RangeLabelsVisible, bool);
390
392
395 vtkSetMacro(LabelOffset, float);
396 vtkGetMacro(LabelOffset, float);
398
400
403 vtkSetMacro(TicksVisible, bool);
404 vtkGetMacro(TicksVisible, bool);
406
408
411 vtkSetMacro(AxisVisible, bool);
412 vtkGetMacro(AxisVisible, bool);
414
416
419 vtkSetMacro(TitleVisible, bool);
420 vtkGetMacro(TitleVisible, bool);
422
424
428 virtual void SetPrecision(int precision);
429 vtkGetMacro(Precision, int);
431
435 enum
436 {
437 STANDARD_NOTATION = 0,
440 PRINTF_NOTATION
441 };
442
444
448 virtual void SetLabelFormat(const std::string& fmt);
449 vtkGetMacro(LabelFormat, std::string);
451
453
458 vtkSetMacro(RangeLabelFormat, std::string);
459 vtkGetMacro(RangeLabelFormat, std::string);
461
463
468 virtual void SetNotation(int notation);
469 vtkGetMacro(Notation, int);
471
475 enum
476 {
477 AUTO = 0, // Automatically scale the axis to view all data that is visible.
478 FIXED, // Use a fixed axis range and make no attempt to rescale.
479 CUSTOM // Deprecated, use the tick label settings instead.
480 };
481
483
486 vtkSetMacro(Behavior, int);
487 vtkGetMacro(Behavior, int);
489
491
494 vtkGetObjectMacro(Pen, vtkPen);
496
498
501 vtkGetObjectMacro(GridPen, vtkPen);
503
505
512 vtkSetMacro(TickLabelAlgorithm, int);
513 vtkGetMacro(TickLabelAlgorithm, int);
515
517
521 vtkSetMacro(ScalingFactor, double);
522 vtkGetMacro(ScalingFactor, double);
523 vtkSetMacro(Shift, double);
524 vtkGetMacro(Shift, double);
526
531 void Update() override;
532
536 bool Paint(vtkContext2D* painter) override;
537
544 virtual void AutoScale();
545
551
557
563
568
576 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
577
585
591 static double NiceNumber(double number, bool roundUp);
592
597 static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
598
604
608 bool Hit(const vtkContextMouseEvent& mouse) override;
609
610protected:
612 ~vtkAxis() override;
613
622 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
623
627 virtual void GenerateTickLabels(double min, double max);
628
632 virtual void GenerateTickLabels();
633
634 virtual void GenerateLabelFormat(int notation, double n);
635
639 virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
640
645 double CalculateNiceMinMax(double& min, double& max);
646
656 double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
657
669 virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
670
682 int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
683
688
689 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
690 float* Point1; // The position of point 1 (usually the origin)
691 float* Point2; // The position of point 2 (usually the terminus)
693 double TickInterval; // Interval between tick marks in plot space
694 int NumberOfTicks; // The number of tick marks to draw
695 float TickLength; // The length of the tick marks
696 vtkTextProperty* LabelProperties; // Text properties for the labels.
697 double Minimum; // Minimum value of the axis
698 double Maximum; // Maximum values of the axis
699 double MinimumLimit; // Lowest possible value for Minimum
700 double MaximumLimit; // Highest possible value for Maximum
701 double UnscaledMinimum; // UnscaledMinimum value of the axis
702 double UnscaledMaximum; // UnscaledMaximum values of the axis
703 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
704 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
705 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
706 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
707 int Margins[2]; // Horizontal/vertical margins for the axis
708 vtkStdString Title; // The text label drawn on the axis
709 vtkTextProperty* TitleProperties; // Text properties for the axis title
710 bool LogScale; // *Should* the axis use a log scale?
711 bool LogScaleActive; // *Is* the axis using a log scale?
712 bool GridVisible; // Whether the grid for the axis should be drawn
713 bool LabelsVisible; // Should the axis labels be visible
714 bool RangeLabelsVisible; // Should range labels be visible?
715 float LabelOffset; // Offset of label from the tick mark
716 bool TicksVisible; // Should the tick marks be visible.
717 bool AxisVisible; // Should the axis line be visible.
718 bool TitleVisible; // Should the title be visible.
719 int Precision; // Numerical precision to use, defaults to 2.
720 int Notation; // The notation to use (standard, scientific, mixed)
721 std::string LabelFormat; // The printf-style format string used for labels.
722 std::string RangeLabelFormat; // The printf-style format string used for range labels.
723 int Behavior; // The behaviour of the axis (auto, fixed, custom).
724 float MaxLabel[2]; // The widest/tallest axis label.
725 bool TitleAppended; // Track if the title is updated when the label formats
726 // are changed in the Extended Axis Labeling algorithm
727
729
735 double Shift;
737
742
747
752
757
762
767
773
778
783
788
793
794private:
795 vtkAxis(const vtkAxis&) = delete;
796 void operator=(const vtkAxis&) = delete;
797
801 bool InRange(double value);
802};
803
804#endif // vtkAxis_h
takes care of drawing 2D axes
Definition: vtkAxis.h:78
virtual void SetUnscaledMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
bool Paint(vtkContext2D *painter) override
Paint event for the axis, called whenever the axis needs to be drawn.
virtual void SetMinimum(double minimum)
Set the logical minimum value of the axis, in plot coordinates.
vtkVector2f Position1
Definition: vtkAxis.h:692
vtkPen * Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:746
void GenerateLogScaleTickMarks(int order, double min=1.0, double max=9.0, bool detailLabels=true)
Generate tick marks for logarithmic scale for specific order of magnitude.
virtual void SetUnscaledMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual void GenerateTickLabels()
Generate tick labels from the supplied double array of tick positions.
bool TitleVisible
Definition: vtkAxis.h:718
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
double UnscaledMaximumLimit
Definition: vtkAxis.h:704
bool TitleAppended
Definition: vtkAxis.h:725
int Behavior
Definition: vtkAxis.h:723
static double NiceNumber(double number, bool roundUp)
Return a "nice number", often defined as 1, 2 or 5.
void SetPoint2(const vtkVector2f &pos)
Set point 2 of the axis (in pixels), this is usually the terminus.
vtkVector2f GetPosition2()
Get point 2 of the axis (in pixels), this is usually the terminus.
std::string RangeLabelFormat
Definition: vtkAxis.h:722
static vtkAxis * New()
Creates a 2D Chart object.
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a printf-style format string.
int Precision
Definition: vtkAxis.h:719
void Update() override
Update the geometry of the axis.
vtkRectf GetBoundingRect(vtkContext2D *painter)
Request the space the axes require to be drawn.
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:705
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
int Position
Definition: vtkAxis.h:689
bool UsingNiceMinMax
Hint as to whether a nice min/max was set, otherwise labels may not be present at the top/bottom of t...
Definition: vtkAxis.h:772
virtual void SetNumberOfTicks(int numberOfTicks)
Set the number of tick marks for this axis.
virtual void SetLabelFormat(const std::string &fmt)
Get/Set the printf-style format string used when TickLabelAlgorithm is TICK_SIMPLE and Notation is PR...
virtual vtkStringArray * GetTickLabels()
A string array containing the tick labels for the axis.
virtual void GenerateLogSpacedLinearTicks(int order, double min, double max)
Generate logarithmically-spaced tick marks with linear-style labels.
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
double CalculateNiceMinMax(double &min, double &max)
Calculate the next "nicest" numbers above and below the current minimum.
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:787
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the axis.
bool GridVisible
Definition: vtkAxis.h:712
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:735
double UnscaledMinimumLimit
Definition: vtkAxis.h:703
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:696
static double NiceMinMax(double &min, double &max, float pixelRange, float tickPixelSpacing)
Static function to calculate "nice" minimum, maximum, and tick spacing values.
float * Point2
Definition: vtkAxis.h:691
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
int NumberOfTicks
Definition: vtkAxis.h:694
vtkStdString Title
Definition: vtkAxis.h:708
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
@ FIXED
Definition: vtkAxis.h:478
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:782
double MinimumLimit
Definition: vtkAxis.h:699
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
double UnscaledMinimum
Definition: vtkAxis.h:701
float TickLength
Definition: vtkAxis.h:695
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
bool RangeLabelsVisible
Definition: vtkAxis.h:714
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
double TickInterval
Definition: vtkAxis.h:693
virtual void SetMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
void SetPoint2(float x, float y)
Set point 2 of the axis (in pixels), this is usually the terminus.
virtual void SetPrecision(int precision)
Get/set the numerical precision to use, default is 2.
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:761
virtual void SetMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual vtkStdString GenerateSprintfLabel(double value, const std::string &format)
Generate label using a printf-style format string.
virtual void RecalculateTickSpacing()
Recalculate the spacing of the tick marks - typically useful to do after scaling the axis.
virtual void SetUnscaledMinimum(double minimum)
Set the logical, unscaled minimum value of the axis, in plot coordinates.
virtual void SetRange(double range[2])
Set the logical range of the axis, in plot coordinates.
bool LabelsVisible
Definition: vtkAxis.h:713
void CalculateTitlePosition(vtkVector2f &out)
Calculate the position where the title of the axis would be drawn.
~vtkAxis() override
bool TicksVisible
Definition: vtkAxis.h:716
@ FIXED_NOTATION
Definition: vtkAxis.h:439
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:438
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:88
@ TOP
Definition: vtkAxis.h:92
@ BOTTOM
Definition: vtkAxis.h:90
@ RIGHT
Definition: vtkAxis.h:91
double Maximum
Definition: vtkAxis.h:698
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
double Minimum
Definition: vtkAxis.h:697
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
int Notation
Definition: vtkAxis.h:720
virtual bool SetCustomTickPositions(vtkDoubleArray *positions, vtkStringArray *labels=nullptr)
Set the tick positions, and optionally custom tick labels.
virtual void GenerateLabelFormat(int notation, double n)
virtual void AutoScale()
Use this function to autoscale the axes after setting the minimum and maximum values.
virtual vtkFloatArray * GetTickScenePositions()
An array with the positions of the tick marks along the axis line.
virtual void SetUnscaledMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:734
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:706
float * Point1
Definition: vtkAxis.h:690
double MaximumLimit
Definition: vtkAxis.h:700
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:709
virtual void SetRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:741
void UpdateLogScaleActive(bool updateMinMaxFromUnscaled)
Update whether log scaling will be used for layout and rendering.
virtual vtkStdString GetTitle()
Get/set the title text of the axis.
std::string LabelFormat
Definition: vtkAxis.h:721
double LogScaleTickMark(double number, bool roundUp, bool &niceValue, int &order)
Return a tick mark for a logarithmic axis.
vtkPen * GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:751
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:777
float LabelOffset
Definition: vtkAxis.h:715
bool AxisVisible
Definition: vtkAxis.h:717
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:766
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
double UnscaledMaximum
Definition: vtkAxis.h:702
bool LogScale
Definition: vtkAxis.h:710
virtual void SetMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual void SetLogScale(bool logScale)
Get/set whether the axis should attempt to use a log scale.
bool LogScaleActive
Definition: vtkAxis.h:711
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:792
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:756
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:63
base class for items that are part of a vtkContextScene.
data structure to represent mouse events.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:45
a simple class to control print indentation
Definition: vtkIndent.h:43
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:46
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:45
a vtkAbstractArray subclass for strings
represent text properties.
record modification and/or execution time
Definition: vtkTimeStamp.h:42
@ order
Definition: vtkX3D.h:446
@ value
Definition: vtkX3D.h:226
@ range
Definition: vtkX3D.h:244
@ position
Definition: vtkX3D.h:267
@ title
Definition: vtkX3D.h:506
@ string
Definition: vtkX3D.h:496
#define max(a, b)