VTK  9.7.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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
53 
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkContext2D;
56 class vtkFloatArray;
57 class vtkDoubleArray;
58 class vtkStringArray;
59 class vtkTextProperty;
60 
61 class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkAxis : public vtkContextItem
62 {
63 public:
64  vtkTypeMacro(vtkAxis, vtkContextItem);
65  void PrintSelf(ostream& os, vtkIndent indent) override;
66 
71  enum Location
72  {
73  LEFT = 0,
76  TOP,
77  PARALLEL
78  };
79 
80  enum
81  {
82  TICK_SIMPLE = 0,
83  TICK_WILKINSON_EXTENDED
84  };
85 
89  static vtkAxis* New();
90 
92 
95  virtual void SetPosition(int position);
96  vtkGetMacro(Position, int);
98 
100 
103  void SetPoint1(const vtkVector2f& pos);
104  void SetPoint1(float x, float y);
106 
108 
111  vtkGetVector2Macro(Point1, float);
112  vtkVector2f GetPosition1();
114 
116 
119  void SetPoint2(const vtkVector2f& pos);
120  void SetPoint2(float x, float y);
122 
124 
127  vtkGetVector2Macro(Point2, float);
128  vtkVector2f GetPosition2();
130 
135  virtual void SetNumberOfTicks(int numberOfTicks);
136 
138 
141  vtkGetMacro(NumberOfTicks, int);
143 
145 
148  vtkSetMacro(TickLength, float);
149  vtkGetMacro(TickLength, float);
151 
153 
157  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
159 
165  virtual void SetMinimum(double minimum);
166 
168 
173  vtkGetMacro(Minimum, double);
175 
181  virtual void SetMaximum(double maximum);
182 
184 
189  vtkGetMacro(Maximum, double);
191 
197  virtual void SetUnscaledMinimum(double minimum);
198 
200 
203  vtkGetMacro(UnscaledMinimum, double);
205 
209  virtual void SetUnscaledMaximum(double maximum);
210 
212 
215  vtkGetMacro(UnscaledMaximum, double);
217 
219 
228  virtual void SetRange(double minimum, double maximum);
229  virtual void SetRange(double range[2]);
230  virtual void SetUnscaledRange(double minimum, double maximum);
231  virtual void SetUnscaledRange(double range[2]);
233 
235 
242  virtual void GetRange(double* range);
243  virtual void GetUnscaledRange(double* range);
245 
249  virtual void SetMinimumLimit(double lowest);
250 
252 
255  vtkGetMacro(MinimumLimit, double);
257 
261  virtual void SetMaximumLimit(double highest);
262 
264 
267  vtkGetMacro(MaximumLimit, double);
269 
273  virtual void SetUnscaledMinimumLimit(double lowest);
274 
276 
279  vtkGetMacro(UnscaledMinimumLimit, double);
281 
285  virtual void SetUnscaledMaximumLimit(double highest);
286 
288 
291  vtkGetMacro(UnscaledMaximumLimit, double);
293 
295 
298  vtkGetVector2Macro(Margins, int);
300 
302 
305  vtkSetVector2Macro(Margins, int);
307 
309 
312  virtual void SetTitle(const vtkStdString& title);
313  virtual vtkStdString GetTitle();
315 
317 
320  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
322 
324 
336  vtkGetMacro(LogScaleActive, bool);
338 
340 
346  vtkGetMacro(LogScale, bool);
347  virtual void SetLogScale(bool logScale);
348  vtkBooleanMacro(LogScale, bool);
350 
352 
355  vtkSetMacro(GridVisible, bool);
356  vtkGetMacro(GridVisible, bool);
358 
360 
363  vtkSetMacro(LabelsVisible, bool);
364  vtkGetMacro(LabelsVisible, bool);
366 
368 
371  vtkSetMacro(RangeLabelsVisible, bool);
372  vtkGetMacro(RangeLabelsVisible, bool);
374 
376 
379  virtual void SetVerticalLabels(bool verticalLabels);
380  vtkGetMacro(VerticalLabels, bool);
382 
384 
387  vtkSetMacro(LabelOffset, float);
388  vtkGetMacro(LabelOffset, float);
390 
392 
395  vtkSetMacro(OverlappingLabels, bool);
396  vtkGetMacro(OverlappingLabels, bool);
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 
436  {
437  STANDARD_NOTATION = 0,
441  STD_FORMAT_NOTATION
442  };
443 
445 
449  virtual void SetLabelFormat(const std::string& format);
450  vtkGetMacro(LabelFormat, std::string);
452 
454 
459  vtkSetMacro(RangeLabelFormat, std::string);
460  vtkGetMacro(RangeLabelFormat, std::string);
462 
464 
469  virtual void SetNotation(int notation);
470  vtkGetMacro(Notation, int);
472 
476  enum
477  {
478  AUTO = 0, // Automatically scale the axis to view all data that is visible.
479  FIXED, // Use a fixed axis range and make no attempt to rescale.
480  CUSTOM // Deprecated, use the tick label settings instead.
481  };
482 
484 
487  vtkSetMacro(Behavior, int);
488  vtkGetMacro(Behavior, int);
490 
492 
495  vtkSetSmartPointerMacro(Pen, vtkPen);
496  vtkGetObjectMacro(Pen, vtkPen);
498 
500 
503  vtkSetSmartPointerMacro(GridPen, vtkPen);
504  vtkGetObjectMacro(GridPen, vtkPen);
506 
508 
515  vtkSetMacro(TickLabelAlgorithm, int);
516  vtkGetMacro(TickLabelAlgorithm, int);
518 
520 
524  vtkSetMacro(ScalingFactor, double);
525  vtkGetMacro(ScalingFactor, double);
526  vtkSetMacro(Shift, double);
527  vtkGetMacro(Shift, double);
529 
534  void Update() override;
535 
539  bool Paint(vtkContext2D* painter) override;
540 
547  virtual void AutoScale();
548 
553  virtual void RecalculateTickSpacing();
554 
559  virtual vtkDoubleArray* GetTickPositions();
560 
565  virtual vtkFloatArray* GetTickScenePositions();
566 
570  virtual vtkStringArray* GetTickLabels();
571 
579  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
580 
587  vtkRectf GetBoundingRect(vtkContext2D* painter);
588 
594  static double NiceNumber(double number, bool roundUp);
595 
600  static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
601 
606  virtual vtkStdString GenerateSimpleLabel(double val);
607 
611  bool Hit(const vtkContextMouseEvent& mouse) override;
612 
613 protected:
614  vtkAxis();
615  ~vtkAxis() override;
616 
625  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
626 
630  virtual void GenerateTickLabels(double min, double max);
631 
635  virtual void GenerateTickLabels();
636 
637  virtual void GenerateLabelFormat(int notation, double n);
638 
642  virtual vtkStdString GenerateStdFormatLabel(double value, const std::string& format);
643 
647  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
648 
653  double CalculateNiceMinMax(double& min, double& max);
654 
664  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
665 
677  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
678 
689  void GenerateLogScaleTickMarks(
690  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
691 
695  void CalculateTitlePosition(vtkVector2f& out);
696 
697  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
698  float* Point1; // The position of point 1 (usually the origin)
699  float* Point2; // The position of point 2 (usually the terminus)
700  vtkVector2f Position1, Position2;
701  double TickInterval; // Interval between tick marks in plot space
702  int NumberOfTicks; // The number of tick marks to draw
703  float TickLength; // The length of the tick marks
704  vtkTextProperty* LabelProperties; // Text properties for the labels.
705  double Minimum; // Minimum value of the axis
706  double Maximum; // Maximum values of the axis
707  double MinimumLimit; // Lowest possible value for Minimum
708  double MaximumLimit; // Highest possible value for Maximum
709  double UnscaledMinimum; // UnscaledMinimum value of the axis
710  double UnscaledMaximum; // UnscaledMaximum values of the axis
711  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
712  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
713  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
714  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
715  int Margins[2]; // Horizontal/vertical margins for the axis
716  vtkStdString Title; // The text label drawn on the axis
717  vtkTextProperty* TitleProperties; // Text properties for the axis title
718  bool LogScale; // *Should* the axis use a log scale?
719  bool LogScaleActive; // *Is* the axis using a log scale?
720  bool GridVisible; // Whether the grid for the axis should be drawn
721  bool LabelsVisible; // Should the axis labels be visible
722  bool RangeLabelsVisible; // Should range labels be visible?
723  bool VerticalLabels; // Draw labels vertically
724  float LabelOffset; // Offset of label from the tick mark
725  bool OverlappingLabels; // Allow labels to overlap
726  bool TicksVisible; // Should the tick marks be visible.
727  bool AxisVisible; // Should the axis line be visible.
728  bool TitleVisible; // Should the title be visible.
729  int Precision; // Numerical precision to use, defaults to 2.
730  int Notation; // The notation to use (standard, scientific, mixed)
731  std::string LabelFormat; // The std::format/printf style format string used for labels.
732  std::string RangeLabelFormat; // The std::format/printf style format string used for range labels.
733  int Behavior; // The behaviour of the axis (auto, fixed, custom).
734  float MaxLabel[2]; // The widest/tallest axis label.
735  bool TitleAppended; // Track if the title is updated when the label formats
736  // are changed in the Extended Axis Labeling algorithm
737 
739 
745  double Shift;
747 
752 
757 
762 
767 
772 
777 
783 
788 
792  bool Resized;
793 
798 
803 
804 private:
805  vtkAxis(const vtkAxis&) = delete;
806  void operator=(const vtkAxis&) = delete;
807 
811  bool InRange(double value);
812 
816  void UpdateOrientation();
817 };
818 
819 VTK_ABI_NAMESPACE_END
820 #endif // vtkAxis_h
double MaximumLimit
Definition: vtkAxis.h:708
double TickInterval
Definition: vtkAxis.h:701
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:704
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:71
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
bool LabelsVisible
Definition: vtkAxis.h:721
float * Point1
Definition: vtkAxis.h:698
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:713
bool LogScale
Definition: vtkAxis.h:718
base class for items that are part of a vtkContextScene.
int Notation
Definition: vtkAxis.h:730
double MinimumLimit
Definition: vtkAxis.h:707
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
std::string RangeLabelFormat
Definition: vtkAxis.h:732
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:745
record modification and/or execution time
Definition: vtkTimeStamp.h:24
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:31
a vtkAbstractArray subclass for strings
vtkStdString Title
Definition: vtkAxis.h:716
float TickLength
Definition: vtkAxis.h:703
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:797
bool GridVisible
Definition: vtkAxis.h:720
int Precision
Definition: vtkAxis.h:729
float * Point2
Definition: vtkAxis.h:699
bool VerticalLabels
Definition: vtkAxis.h:723
dynamic, self-adjusting array of double
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:802
double UnscaledMinimumLimit
Definition: vtkAxis.h:711
Notations
Enumeration of the axis notations available.
Definition: vtkAxis.h:435
double UnscaledMaximumLimit
Definition: vtkAxis.h:712
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:792
bool RangeLabelsVisible
Definition: vtkAxis.h:722
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
bool AxisVisible
Definition: vtkAxis.h:727
bool LogScaleActive
Definition: vtkAxis.h:719
takes care of drawing 2D axes
Definition: vtkAxis.h:61
double Maximum
Definition: vtkAxis.h:706
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:776
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Position
Definition: vtkAxis.h:697
int Behavior
Definition: vtkAxis.h:733
bool OverlappingLabels
Definition: vtkAxis.h:725
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:29
float LabelOffset
Definition: vtkAxis.h:724
represent text properties.
bool TitleAppended
Definition: vtkAxis.h:735
double Minimum
Definition: vtkAxis.h:705
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:744
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:761
std::string LabelFormat
Definition: vtkAxis.h:731
bool TitleVisible
Definition: vtkAxis.h:728
vtkVector2f Position2
Definition: vtkAxis.h:700
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:717
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:751
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:766
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
bool TicksVisible
Definition: vtkAxis.h:726
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:782
#define VTK_MARSHALAUTO
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:714
int NumberOfTicks
Definition: vtkAxis.h:702
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
double UnscaledMaximum
Definition: vtkAxis.h:710
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:756
#define max(a, b)
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:771
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:787
double UnscaledMinimum
Definition: vtkAxis.h:709