VTK  9.3.1
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 
42 #ifndef vtkAxis_h
43 #define vtkAxis_h
44 
45 #include "vtkChartsCoreModule.h" // For export macro
46 #include "vtkContextItem.h"
47 #include "vtkPen.h" // For vtkPen
48 #include "vtkRect.h" // For bounding rect
49 #include "vtkSmartPointer.h" // For vtkSmartPointer
50 #include "vtkStdString.h" // For vtkStdString ivars
51 #include "vtkVector.h" // For position variables
52 
53 VTK_ABI_NAMESPACE_BEGIN
54 class vtkContext2D;
55 class vtkFloatArray;
56 class vtkDoubleArray;
57 class vtkStringArray;
58 class vtkTextProperty;
59 
60 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
61 {
62 public:
63  vtkTypeMacro(vtkAxis, vtkContextItem);
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65 
70  enum Location
71  {
72  LEFT = 0,
75  TOP,
76  PARALLEL
77  };
78 
79  enum
80  {
81  TICK_SIMPLE = 0,
82  TICK_WILKINSON_EXTENDED
83  };
84 
88  static vtkAxis* New();
89 
91 
94  virtual void SetPosition(int position);
95  vtkGetMacro(Position, int);
97 
99 
102  void SetPoint1(const vtkVector2f& pos);
103  void SetPoint1(float x, float y);
105 
107 
110  vtkGetVector2Macro(Point1, float);
111  vtkVector2f GetPosition1();
113 
115 
118  void SetPoint2(const vtkVector2f& pos);
119  void SetPoint2(float x, float y);
121 
123 
126  vtkGetVector2Macro(Point2, float);
127  vtkVector2f GetPosition2();
129 
134  virtual void SetNumberOfTicks(int numberOfTicks);
135 
137 
140  vtkGetMacro(NumberOfTicks, int);
142 
144 
147  vtkSetMacro(TickLength, float);
148  vtkGetMacro(TickLength, float);
150 
152 
156  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
158 
164  virtual void SetMinimum(double minimum);
165 
167 
172  vtkGetMacro(Minimum, double);
174 
180  virtual void SetMaximum(double maximum);
181 
183 
188  vtkGetMacro(Maximum, double);
190 
196  virtual void SetUnscaledMinimum(double minimum);
197 
199 
202  vtkGetMacro(UnscaledMinimum, double);
204 
208  virtual void SetUnscaledMaximum(double maximum);
209 
211 
214  vtkGetMacro(UnscaledMaximum, double);
216 
218 
227  virtual void SetRange(double minimum, double maximum);
228  virtual void SetRange(double range[2]);
229  virtual void SetUnscaledRange(double minimum, double maximum);
230  virtual void SetUnscaledRange(double range[2]);
232 
234 
241  virtual void GetRange(double* range);
242  virtual void GetUnscaledRange(double* range);
244 
248  virtual void SetMinimumLimit(double lowest);
249 
251 
254  vtkGetMacro(MinimumLimit, double);
256 
260  virtual void SetMaximumLimit(double highest);
261 
263 
266  vtkGetMacro(MaximumLimit, double);
268 
272  virtual void SetUnscaledMinimumLimit(double lowest);
273 
275 
278  vtkGetMacro(UnscaledMinimumLimit, double);
280 
284  virtual void SetUnscaledMaximumLimit(double highest);
285 
287 
290  vtkGetMacro(UnscaledMaximumLimit, double);
292 
294 
297  vtkGetVector2Macro(Margins, int);
299 
301 
304  vtkSetVector2Macro(Margins, int);
306 
308 
311  virtual void SetTitle(const vtkStdString& title);
312  virtual vtkStdString GetTitle();
314 
316 
319  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
321 
323 
335  vtkGetMacro(LogScaleActive, bool);
337 
339 
345  vtkGetMacro(LogScale, bool);
346  virtual void SetLogScale(bool logScale);
347  vtkBooleanMacro(LogScale, bool);
349 
351 
354  vtkSetMacro(GridVisible, bool);
355  vtkGetMacro(GridVisible, bool);
357 
359 
362  vtkSetMacro(LabelsVisible, bool);
363  vtkGetMacro(LabelsVisible, bool);
365 
367 
370  vtkSetMacro(RangeLabelsVisible, bool);
371  vtkGetMacro(RangeLabelsVisible, bool);
373 
375 
378  vtkSetMacro(LabelOffset, float);
379  vtkGetMacro(LabelOffset, float);
381 
383 
386  vtkSetMacro(TicksVisible, bool);
387  vtkGetMacro(TicksVisible, bool);
389 
391 
394  vtkSetMacro(AxisVisible, bool);
395  vtkGetMacro(AxisVisible, bool);
397 
399 
402  vtkSetMacro(TitleVisible, bool);
403  vtkGetMacro(TitleVisible, bool);
405 
407 
411  virtual void SetPrecision(int precision);
412  vtkGetMacro(Precision, int);
414 
418  enum
419  {
420  STANDARD_NOTATION = 0,
423  PRINTF_NOTATION
424  };
425 
427 
431  virtual void SetLabelFormat(const std::string& fmt);
432  vtkGetMacro(LabelFormat, std::string);
434 
436 
441  vtkSetMacro(RangeLabelFormat, std::string);
442  vtkGetMacro(RangeLabelFormat, std::string);
444 
446 
451  virtual void SetNotation(int notation);
452  vtkGetMacro(Notation, int);
454 
458  enum
459  {
460  AUTO = 0, // Automatically scale the axis to view all data that is visible.
461  FIXED, // Use a fixed axis range and make no attempt to rescale.
462  CUSTOM // Deprecated, use the tick label settings instead.
463  };
464 
466 
469  vtkSetMacro(Behavior, int);
470  vtkGetMacro(Behavior, int);
472 
474 
477  vtkSetSmartPointerMacro(Pen, vtkPen);
478  vtkGetObjectMacro(Pen, vtkPen);
480 
482 
485  vtkSetSmartPointerMacro(GridPen, vtkPen);
486  vtkGetObjectMacro(GridPen, vtkPen);
488 
490 
497  vtkSetMacro(TickLabelAlgorithm, int);
498  vtkGetMacro(TickLabelAlgorithm, int);
500 
502 
506  vtkSetMacro(ScalingFactor, double);
507  vtkGetMacro(ScalingFactor, double);
508  vtkSetMacro(Shift, double);
509  vtkGetMacro(Shift, double);
511 
516  void Update() override;
517 
521  bool Paint(vtkContext2D* painter) override;
522 
529  virtual void AutoScale();
530 
535  virtual void RecalculateTickSpacing();
536 
541  virtual vtkDoubleArray* GetTickPositions();
542 
547  virtual vtkFloatArray* GetTickScenePositions();
548 
552  virtual vtkStringArray* GetTickLabels();
553 
561  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
562 
569  vtkRectf GetBoundingRect(vtkContext2D* painter);
570 
576  static double NiceNumber(double number, bool roundUp);
577 
582  static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
583 
588  virtual vtkStdString GenerateSimpleLabel(double val);
589 
593  bool Hit(const vtkContextMouseEvent& mouse) override;
594 
595 protected:
596  vtkAxis();
597  ~vtkAxis() override;
598 
607  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
608 
612  virtual void GenerateTickLabels(double min, double max);
613 
617  virtual void GenerateTickLabels();
618 
619  virtual void GenerateLabelFormat(int notation, double n);
620 
624  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
625 
630  double CalculateNiceMinMax(double& min, double& max);
631 
641  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
642 
654  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
655 
666  void GenerateLogScaleTickMarks(
667  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
668 
672  void CalculateTitlePosition(vtkVector2f& out);
673 
674  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
675  float* Point1; // The position of point 1 (usually the origin)
676  float* Point2; // The position of point 2 (usually the terminus)
677  vtkVector2f Position1, Position2;
678  double TickInterval; // Interval between tick marks in plot space
679  int NumberOfTicks; // The number of tick marks to draw
680  float TickLength; // The length of the tick marks
681  vtkTextProperty* LabelProperties; // Text properties for the labels.
682  double Minimum; // Minimum value of the axis
683  double Maximum; // Maximum values of the axis
684  double MinimumLimit; // Lowest possible value for Minimum
685  double MaximumLimit; // Highest possible value for Maximum
686  double UnscaledMinimum; // UnscaledMinimum value of the axis
687  double UnscaledMaximum; // UnscaledMaximum values of the axis
688  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
689  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
690  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
691  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
692  int Margins[2]; // Horizontal/vertical margins for the axis
693  vtkStdString Title; // The text label drawn on the axis
694  vtkTextProperty* TitleProperties; // Text properties for the axis title
695  bool LogScale; // *Should* the axis use a log scale?
696  bool LogScaleActive; // *Is* the axis using a log scale?
697  bool GridVisible; // Whether the grid for the axis should be drawn
698  bool LabelsVisible; // Should the axis labels be visible
699  bool RangeLabelsVisible; // Should range labels be visible?
700  float LabelOffset; // Offset of label from the tick mark
701  bool TicksVisible; // Should the tick marks be visible.
702  bool AxisVisible; // Should the axis line be visible.
703  bool TitleVisible; // Should the title be visible.
704  int Precision; // Numerical precision to use, defaults to 2.
705  int Notation; // The notation to use (standard, scientific, mixed)
706  std::string LabelFormat; // The printf-style format string used for labels.
707  std::string RangeLabelFormat; // The printf-style format string used for range labels.
708  int Behavior; // The behaviour of the axis (auto, fixed, custom).
709  float MaxLabel[2]; // The widest/tallest axis label.
710  bool TitleAppended; // Track if the title is updated when the label formats
711  // are changed in the Extended Axis Labeling algorithm
712 
714 
720  double Shift;
722 
727 
732 
737 
742 
747 
752 
758 
763 
767  bool Resized;
768 
773 
778 
779 private:
780  vtkAxis(const vtkAxis&) = delete;
781  void operator=(const vtkAxis&) = delete;
782 
786  bool InRange(double value);
787 };
788 
789 VTK_ABI_NAMESPACE_END
790 #endif // vtkAxis_h
double MaximumLimit
Definition: vtkAxis.h:685
double TickInterval
Definition: vtkAxis.h:678
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:681
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:70
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
bool LabelsVisible
Definition: vtkAxis.h:698
float * Point1
Definition: vtkAxis.h:675
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:690
bool LogScale
Definition: vtkAxis.h:695
base class for items that are part of a vtkContextScene.
int Notation
Definition: vtkAxis.h:705
double MinimumLimit
Definition: vtkAxis.h:684
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
std::string RangeLabelFormat
Definition: vtkAxis.h:707
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:720
record modification and/or execution time
Definition: vtkTimeStamp.h:24
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:30
a vtkAbstractArray subclass for strings
vtkStdString Title
Definition: vtkAxis.h:693
float TickLength
Definition: vtkAxis.h:680
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:772
bool GridVisible
Definition: vtkAxis.h:697
int Precision
Definition: vtkAxis.h:704
float * Point2
Definition: vtkAxis.h:676
dynamic, self-adjusting array of double
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:777
double UnscaledMinimumLimit
Definition: vtkAxis.h:688
double UnscaledMaximumLimit
Definition: vtkAxis.h:689
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:767
bool RangeLabelsVisible
Definition: vtkAxis.h:699
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
bool AxisVisible
Definition: vtkAxis.h:702
bool LogScaleActive
Definition: vtkAxis.h:696
takes care of drawing 2D axes
Definition: vtkAxis.h:60
double Maximum
Definition: vtkAxis.h:683
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:751
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Position
Definition: vtkAxis.h:674
int Behavior
Definition: vtkAxis.h:708
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:28
float LabelOffset
Definition: vtkAxis.h:700
represent text properties.
bool TitleAppended
Definition: vtkAxis.h:710
double Minimum
Definition: vtkAxis.h:682
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:719
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:736
std::string LabelFormat
Definition: vtkAxis.h:706
bool TitleVisible
Definition: vtkAxis.h:703
vtkVector2f Position2
Definition: vtkAxis.h:677
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:694
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:726
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:741
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
bool TicksVisible
Definition: vtkAxis.h:701
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:757
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:691
int NumberOfTicks
Definition: vtkAxis.h:679
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
double UnscaledMaximum
Definition: vtkAxis.h:687
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:731
#define max(a, b)
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:746
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:762
double UnscaledMinimum
Definition: vtkAxis.h:686