Panda3D
pStatStripChart.I
1 // Filename: pStatStripChart.I
2 // Created by: drose (15Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: PStatStripChart::get_view
18 // Access: Public
19 // Description: Returns the View this chart represents.
20 ////////////////////////////////////////////////////////////////////
22 get_view() const {
23  return _view;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: PStatStripChart::get_collector_index
28 // Access: Public
29 // Description: Returns the particular collector whose data this
30 // strip chart reflects.
31 ////////////////////////////////////////////////////////////////////
32 INLINE int PStatStripChart::
34  return _collector_index;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: PStatStripChart::set_horizontal_scale
39 // Access: Public
40 // Description: Changes the amount of time the width of the
41 // horizontal axis represents. This may force a redraw.
42 ////////////////////////////////////////////////////////////////////
43 INLINE void PStatStripChart::
44 set_horizontal_scale(double time_width) {
45  if (_time_width != time_width) {
46  if (_scroll_mode) {
47  _start_time += _time_width - time_width;
48  } else {
49  force_reset();
50  }
51  _time_width = time_width;
52  }
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: PStatStripChart::get_horizontal_scale
57 // Access: Public
58 // Description: Returns the amount of total time the width of the
59 // horizontal axis represents.
60 ////////////////////////////////////////////////////////////////////
61 INLINE double PStatStripChart::
63  return _time_width;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PStatStripChart::set_vertical_scale
68 // Access: Public
69 // Description: Changes the value the height of the vertical axis
70 // represents. This may force a redraw.
71 ////////////////////////////////////////////////////////////////////
72 INLINE void PStatStripChart::
73 set_vertical_scale(double value_height) {
74  if (_value_height != value_height) {
75  _value_height = value_height;
76  normal_guide_bars();
77  force_redraw();
78  }
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: PStatStripChart::get_vertical_scale
83 // Access: Public
84 // Description: Returns total value the height of the vertical axis
85 // represents.
86 ////////////////////////////////////////////////////////////////////
87 INLINE double PStatStripChart::
89  return _value_height;
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: PStatStripChart::set_scroll_mode
94 // Access: Public
95 // Description: Changes the scroll_mode flag. When true, the strip
96 // chart will update itself by scrolling to the left;
97 // when false, the strip chart will wrap around at the
98 // right and restart at the left end without scrolling.
99 ////////////////////////////////////////////////////////////////////
100 INLINE void PStatStripChart::
101 set_scroll_mode(bool scroll_mode) {
102  if (_scroll_mode != scroll_mode) {
103  _scroll_mode = scroll_mode;
104  _first_data = true;
105  }
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: PStatStripChart::get_scroll_mode
110 // Access: Public
111 // Description: Returns the current state of the scroll_mode flag.
112 // When true, the strip chart will update itself by
113 // scrolling to the left; when false, the strip chart
114 // will wrap around at the right and restart at the left
115 // end without scrolling.
116 ////////////////////////////////////////////////////////////////////
117 INLINE bool PStatStripChart::
119  return _scroll_mode;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: PStatStripChart::set_average_mode
124 // Access: Public
125 // Description: Changes the average_mode flag. When true, the strip
126 // chart will average out the color values over
127 // pstats_average_time seconds, which hides spikes and
128 // makes the overall trends easier to read. When false,
129 // the strip chart shows the actual data as it is
130 // happening.
131 ////////////////////////////////////////////////////////////////////
132 INLINE void PStatStripChart::
133 set_average_mode(bool average_mode) {
134  if (_average_mode != average_mode) {
135  _average_mode = average_mode;
136  force_redraw();
137  }
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: PStatStripChart::get_average_mode
142 // Access: Public
143 // Description: Returns the current state of the average_mode flag.
144 // When true, the strip chart will average out the color
145 // values over pstats_average_time seconds, which hides
146 // spikes and makes the overall trends easier to read.
147 // When false, the strip chart shows the actual data as
148 // it is happening.
149 ////////////////////////////////////////////////////////////////////
150 INLINE bool PStatStripChart::
152  return _average_mode;
153 }
154 
155 ////////////////////////////////////////////////////////////////////
156 // Function: PStatStripChart::timestamp_to_pixel
157 // Access: Public
158 // Description: Converts a timestamp to a horizontal pixel offset.
159 ////////////////////////////////////////////////////////////////////
160 INLINE int PStatStripChart::
161 timestamp_to_pixel(double time) const {
162  return (int)((double)get_xsize() * (time - _start_time) / _time_width);
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: PStatStripChart::pixel_to_timestamp
167 // Access: Public
168 // Description: Converts a horizontal pixel offset to a timestamp.
169 ////////////////////////////////////////////////////////////////////
170 INLINE double PStatStripChart::
171 pixel_to_timestamp(int x) const {
172  return _time_width * (double)x / (double)get_xsize() + _start_time;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: PStatStripChart::height_to_pixel
177 // Access: Public
178 // Description: Converts a value (i.e. a "height" in the strip chart)
179 // to a vertical pixel offset.
180 ////////////////////////////////////////////////////////////////////
181 INLINE int PStatStripChart::
182 height_to_pixel(double value) const {
183  return get_ysize() - (int)((double)get_ysize() * value / _value_height);
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: PStatStripChart::pixel_to_height
188 // Access: Public
189 // Description: Converts a vertical pixel offset to a value (a
190 // "height" in the strip chart).
191 ////////////////////////////////////////////////////////////////////
192 INLINE double PStatStripChart::
193 pixel_to_height(int x) const {
194  return _value_height * (double)(get_ysize() - x) / (double)get_ysize();
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: PStatStripChart::is_label_used
199 // Access: Protected
200 // Description: Returns true if the indicated collector appears
201 // anywhere on the chart at the current time, false
202 // otherwise.
203 ////////////////////////////////////////////////////////////////////
204 INLINE bool PStatStripChart::
205 is_label_used(int collector_index) const {
206  if (collector_index < (int)_label_usage.size()) {
207  return _label_usage[collector_index] > 0;
208  }
209  return false;
210 }
void set_horizontal_scale(double time_width)
Changes the amount of time the width of the horizontal axis represents.
int get_xsize() const
Returns the width of the chart in pixels.
Definition: pStatGraph.I:103
double get_horizontal_scale() const
Returns the amount of total time the width of the horizontal axis represents.
int get_ysize() const
Returns the height of the chart in pixels.
Definition: pStatGraph.I:113
int timestamp_to_pixel(double time) const
Converts a timestamp to a horizontal pixel offset.
void set_vertical_scale(double value_height)
Changes the value the height of the vertical axis represents.
double pixel_to_height(int y) const
Converts a vertical pixel offset to a value (a "height" in the strip chart).
int get_collector_index() const
Returns the particular collector whose data this strip chart reflects.
PStatView & get_view() const
Returns the View this chart represents.
int height_to_pixel(double value) const
Converts a value (i.e.
A View boils down the frame data to a linear list of times spent in a number of different Collectors...
Definition: pStatView.h:34
bool get_average_mode() const
Returns the current state of the average_mode flag.
double pixel_to_timestamp(int x) const
Converts a horizontal pixel offset to a timestamp.
void set_average_mode(bool average_mode)
Changes the average_mode flag.
double get_vertical_scale() const
Returns total value the height of the vertical axis represents.
bool get_scroll_mode() const
Returns the current state of the scroll_mode flag.
void set_scroll_mode(bool scroll_mode)
Changes the scroll_mode flag.