VTK  9.3.0
vtkAxis.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 
51 #ifndef vtkAxis_h
52 #define vtkAxis_h
53 
54 #include "vtkChartsCoreModule.h" // For export macro
55 #include "vtkContextItem.h"
56 #include "vtkPen.h" // For vtkPen
57 #include "vtkRect.h" // For bounding rect
58 #include "vtkSmartPointer.h" // For vtkSmartPointer
59 #include "vtkStdString.h" // For vtkStdString ivars
60 #include "vtkVector.h" // For position variables
61 
62 VTK_ABI_NAMESPACE_BEGIN
63 class vtkContext2D;
64 class vtkFloatArray;
65 class vtkDoubleArray;
66 class vtkStringArray;
67 class vtkTextProperty;
68 
69 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
70 {
71 public:
72  vtkTypeMacro(vtkAxis, vtkContextItem);
73  void PrintSelf(ostream& os, vtkIndent indent) override;
74 
79  enum Location
80  {
81  LEFT = 0,
84  TOP,
85  PARALLEL
86  };
87 
88  enum
89  {
90  TICK_SIMPLE = 0,
91  TICK_WILKINSON_EXTENDED
92  };
93 
97  static vtkAxis* New();
98 
100 
103  virtual void SetPosition(int position);
104  vtkGetMacro(Position, int);
106 
108 
111  void SetPoint1(const vtkVector2f& pos);
112  void SetPoint1(float x, float y);
114 
116 
119  vtkGetVector2Macro(Point1, float);
122 
124 
127  void SetPoint2(const vtkVector2f& pos);
128  void SetPoint2(float x, float y);
130 
132 
135  vtkGetVector2Macro(Point2, float);
138 
143  virtual void SetNumberOfTicks(int numberOfTicks);
144 
146 
149  vtkGetMacro(NumberOfTicks, int);
151 
153 
156  vtkSetMacro(TickLength, float);
157  vtkGetMacro(TickLength, float);
159 
161 
165  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
167 
173  virtual void SetMinimum(double minimum);
174 
176 
181  vtkGetMacro(Minimum, double);
183 
189  virtual void SetMaximum(double maximum);
190 
192 
197  vtkGetMacro(Maximum, double);
199 
205  virtual void SetUnscaledMinimum(double minimum);
206 
208 
211  vtkGetMacro(UnscaledMinimum, double);
213 
217  virtual void SetUnscaledMaximum(double maximum);
218 
220 
223  vtkGetMacro(UnscaledMaximum, double);
225 
227 
236  virtual void SetRange(double minimum, double maximum);
237  virtual void SetRange(double range[2]);
238  virtual void SetUnscaledRange(double minimum, double maximum);
239  virtual void SetUnscaledRange(double range[2]);
241 
243 
250  virtual void GetRange(double* range);
251  virtual void GetUnscaledRange(double* range);
253 
257  virtual void SetMinimumLimit(double lowest);
258 
260 
263  vtkGetMacro(MinimumLimit, double);
265 
269  virtual void SetMaximumLimit(double highest);
270 
272 
275  vtkGetMacro(MaximumLimit, double);
277 
281  virtual void SetUnscaledMinimumLimit(double lowest);
282 
284 
287  vtkGetMacro(UnscaledMinimumLimit, double);
289 
293  virtual void SetUnscaledMaximumLimit(double highest);
294 
296 
299  vtkGetMacro(UnscaledMaximumLimit, double);
301 
303 
306  vtkGetVector2Macro(Margins, int);
308 
310 
313  vtkSetVector2Macro(Margins, int);
315 
317 
320  virtual void SetTitle(const vtkStdString& title);
323 
325 
328  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
330 
332 
344  vtkGetMacro(LogScaleActive, bool);
346 
348 
354  vtkGetMacro(LogScale, bool);
355  virtual void SetLogScale(bool logScale);
356  vtkBooleanMacro(LogScale, bool);
358 
360 
363  vtkSetMacro(GridVisible, bool);
364  vtkGetMacro(GridVisible, bool);
366 
368 
371  vtkSetMacro(LabelsVisible, bool);
372  vtkGetMacro(LabelsVisible, bool);
374 
376 
379  vtkSetMacro(RangeLabelsVisible, bool);
380  vtkGetMacro(RangeLabelsVisible, bool);
382 
384 
387  vtkSetMacro(LabelOffset, float);
388  vtkGetMacro(LabelOffset, float);
390 
392 
395  vtkSetMacro(TicksVisible, bool);
396  vtkGetMacro(TicksVisible, bool);
398 
400 
403  vtkSetMacro(AxisVisible, bool);
404  vtkGetMacro(AxisVisible, bool);
406 
408 
411  vtkSetMacro(TitleVisible, bool);
412  vtkGetMacro(TitleVisible, bool);
414 
416 
420  virtual void SetPrecision(int precision);
421  vtkGetMacro(Precision, int);
423 
427  enum
428  {
429  STANDARD_NOTATION = 0,
432  PRINTF_NOTATION
433  };
434 
436 
440  virtual void SetLabelFormat(const std::string& fmt);
441  vtkGetMacro(LabelFormat, std::string);
443 
445 
450  vtkSetMacro(RangeLabelFormat, std::string);
451  vtkGetMacro(RangeLabelFormat, std::string);
453 
455 
460  virtual void SetNotation(int notation);
461  vtkGetMacro(Notation, int);
463 
467  enum
468  {
469  AUTO = 0, // Automatically scale the axis to view all data that is visible.
470  FIXED, // Use a fixed axis range and make no attempt to rescale.
471  CUSTOM // Deprecated, use the tick label settings instead.
472  };
473 
475 
478  vtkSetMacro(Behavior, int);
479  vtkGetMacro(Behavior, int);
481 
483 
487  vtkGetObjectMacro(Pen, vtkPen);
489 
491 
495  vtkGetObjectMacro(GridPen, vtkPen);
497 
499 
506  vtkSetMacro(TickLabelAlgorithm, int);
507  vtkGetMacro(TickLabelAlgorithm, int);
509 
511 
515  vtkSetMacro(ScalingFactor, double);
516  vtkGetMacro(ScalingFactor, double);
517  vtkSetMacro(Shift, double);
518  vtkGetMacro(Shift, double);
520 
525  void Update() override;
526 
530  bool Paint(vtkContext2D* painter) override;
531 
538  virtual void AutoScale();
539 
544  virtual void RecalculateTickSpacing();
545 
551 
557 
562 
570  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
571 
579 
585  static double NiceNumber(double number, bool roundUp);
586 
591  static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
592 
597  virtual vtkStdString GenerateSimpleLabel(double val);
598 
602  bool Hit(const vtkContextMouseEvent& mouse) override;
603 
604 protected:
606  ~vtkAxis() override;
607 
616  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
617 
621  virtual void GenerateTickLabels(double min, double max);
622 
626  virtual void GenerateTickLabels();
627 
628  virtual void GenerateLabelFormat(int notation, double n);
629 
633  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
634 
639  double CalculateNiceMinMax(double& min, double& max);
640 
650  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
651 
663  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
664 
676  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
677 
682 
683  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
684  float* Point1; // The position of point 1 (usually the origin)
685  float* Point2; // The position of point 2 (usually the terminus)
686  vtkVector2f Position1, Position2;
687  double TickInterval; // Interval between tick marks in plot space
688  int NumberOfTicks; // The number of tick marks to draw
689  float TickLength; // The length of the tick marks
690  vtkTextProperty* LabelProperties; // Text properties for the labels.
691  double Minimum; // Minimum value of the axis
692  double Maximum; // Maximum values of the axis
693  double MinimumLimit; // Lowest possible value for Minimum
694  double MaximumLimit; // Highest possible value for Maximum
695  double UnscaledMinimum; // UnscaledMinimum value of the axis
696  double UnscaledMaximum; // UnscaledMaximum values of the axis
697  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
698  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
699  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
700  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
701  int Margins[2]; // Horizontal/vertical margins for the axis
702  vtkStdString Title; // The text label drawn on the axis
703  vtkTextProperty* TitleProperties; // Text properties for the axis title
704  bool LogScale; // *Should* the axis use a log scale?
705  bool LogScaleActive; // *Is* the axis using a log scale?
706  bool GridVisible; // Whether the grid for the axis should be drawn
707  bool LabelsVisible; // Should the axis labels be visible
708  bool RangeLabelsVisible; // Should range labels be visible?
709  float LabelOffset; // Offset of label from the tick mark
710  bool TicksVisible; // Should the tick marks be visible.
711  bool AxisVisible; // Should the axis line be visible.
712  bool TitleVisible; // Should the title be visible.
713  int Precision; // Numerical precision to use, defaults to 2.
714  int Notation; // The notation to use (standard, scientific, mixed)
715  std::string LabelFormat; // The printf-style format string used for labels.
716  std::string RangeLabelFormat; // The printf-style format string used for range labels.
717  int Behavior; // The behaviour of the axis (auto, fixed, custom).
718  float MaxLabel[2]; // The widest/tallest axis label.
719  bool TitleAppended; // Track if the title is updated when the label formats
720  // are changed in the Extended Axis Labeling algorithm
721 
723 
729  double Shift;
731 
736 
741 
746 
751 
756 
761 
767 
772 
776  bool Resized;
777 
782 
787 
788 private:
789  vtkAxis(const vtkAxis&) = delete;
790  void operator=(const vtkAxis&) = delete;
791 
795  bool InRange(double value);
796 };
797 
798 VTK_ABI_NAMESPACE_END
799 #endif // vtkAxis_h
takes care of drawing 2D axes
Definition: vtkAxis.h:70
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:686
vtkSetSmartPointerMacro(GridPen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
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:712
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
double UnscaledMaximumLimit
Definition: vtkAxis.h:698
bool TitleAppended
Definition: vtkAxis.h:719
int Behavior
Definition: vtkAxis.h:717
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:716
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a printf-style format string.
int Precision
Definition: vtkAxis.h:713
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:699
int Position
Definition: vtkAxis.h:683
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:766
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 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:781
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:706
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:729
double UnscaledMinimumLimit
Definition: vtkAxis.h:697
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:690
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:685
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
int NumberOfTicks
Definition: vtkAxis.h:688
vtkStdString Title
Definition: vtkAxis.h:702
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
@ FIXED
Definition: vtkAxis.h:470
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:776
double MinimumLimit
Definition: vtkAxis.h:693
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
double UnscaledMinimum
Definition: vtkAxis.h:695
float TickLength
Definition: vtkAxis.h:689
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
bool RangeLabelsVisible
Definition: vtkAxis.h:708
vtkSetSmartPointerMacro(Pen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
virtual vtkStringArray * GetTickLabels()
A string array containing the tick labels for the axis.
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
double TickInterval
Definition: vtkAxis.h:687
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:755
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.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:740
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
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:707
void CalculateTitlePosition(vtkVector2f &out)
Calculate the position where the title of the axis would be drawn.
~vtkAxis() override
bool TicksVisible
Definition: vtkAxis.h:710
@ FIXED_NOTATION
Definition: vtkAxis.h:431
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:430
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:80
@ TOP
Definition: vtkAxis.h:84
@ BOTTOM
Definition: vtkAxis.h:82
@ RIGHT
Definition: vtkAxis.h:83
double Maximum
Definition: vtkAxis.h:692
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
double Minimum
Definition: vtkAxis.h:691
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
int Notation
Definition: vtkAxis.h:714
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 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:728
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:745
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:700
float * Point1
Definition: vtkAxis.h:684
double MaximumLimit
Definition: vtkAxis.h:694
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:703
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:735
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:715
static vtkAxis * New()
Creates a 2D Chart object.
double LogScaleTickMark(double number, bool roundUp, bool &niceValue, int &order)
Return a tick mark for a logarithmic axis.
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:771
float LabelOffset
Definition: vtkAxis.h:709
bool AxisVisible
Definition: vtkAxis.h:711
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:760
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
double UnscaledMaximum
Definition: vtkAxis.h:696
bool LogScale
Definition: vtkAxis.h:704
virtual void SetMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual vtkFloatArray * GetTickScenePositions()
An array with the positions of the tick marks along the axis line.
virtual void SetLogScale(bool logScale)
Get/set whether the axis should attempt to use a log scale.
bool LogScaleActive
Definition: vtkAxis.h:705
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:786
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:750
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:59
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:40
a simple class to control print indentation
Definition: vtkIndent.h:38
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:38
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
a vtkAbstractArray subclass for strings
represent text properties.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
@ order
Definition: vtkX3D.h:440
@ value
Definition: vtkX3D.h:220
@ range
Definition: vtkX3D.h:238
@ position
Definition: vtkX3D.h:261
@ title
Definition: vtkX3D.h:500
@ string
Definition: vtkX3D.h:490
#define max(a, b)