15 #include "pStatGraph.h" 16 #include "pStatServer.h" 17 #include "pStatFrameData.h" 18 #include "pStatCollectorDef.h" 19 #include "string_utils.h" 20 #include "config_pstats.h" 29 PStatGraph::GuideBar::
30 GuideBar(
double height,
const string &label, PStatGraph::GuideBarStyle style) :
42 PStatGraph::GuideBar::
44 _height(copy._height),
56 PStatGraph(
PStatMonitor *monitor,
int xsize,
int ysize) :
61 _target_frame_rate = pstats_target_frame_rate;
62 _labels_changed =
false;
63 _guide_bars_changed =
false;
64 _guide_bar_units = GBU_ms;
87 return _guide_bars.size();
103 static GuideBar bogus_bar(0.0,
"bogus", GBS_normal);
104 nassertr(n >= 0 && n < (
int)_guide_bars.size(), bogus_bar);
106 return _guide_bars[n];
117 return _monitor->get_server()->get_num_user_guide_bars();
127 double height = _monitor->get_server()->get_user_guide_bar_height(n);
128 return make_guide_bar(height, GBS_user);
138 _monitor->get_server()->move_user_guide_bar(n, height);
149 return _monitor->get_server()->add_user_guide_bar(height);
161 _monitor->get_server()->remove_user_guide_bar(n);
173 return _monitor->get_server()->find_user_guide_bar(from_height, to_height);
188 sprintf(buffer,
"%0.4f", value);
189 }
else if (value < 0.1) {
190 sprintf(buffer,
"%0.3f", value);
191 }
else if (value < 1.0) {
192 sprintf(buffer,
"%0.2f", value);
193 }
else if (value < 10.0) {
194 sprintf(buffer,
"%0.1f", value);
196 sprintf(buffer,
"%0.0f", value);
213 if ((guide_bar_units & GBU_named) != 0) {
217 if ((guide_bar_units & GBU_show_units) != 0 && !unit_name.empty()) {
224 if ((guide_bar_units & GBU_ms) != 0) {
225 double ms = value * 1000.0;
227 if ((guide_bar_units & GBU_show_units) != 0) {
232 if ((guide_bar_units & GBU_hz) != 0) {
233 double hz = 1.0 / value;
235 if ((guide_bar_units & GBU_ms) != 0) {
239 if ((guide_bar_units & GBU_show_units) != 0) {
242 if ((guide_bar_units & GBU_ms) != 0) {
257 update_guide_bars(
int num_bars,
double scale) {
268 double bottom = (double)num_bars / scale;
271 if (_target_frame_rate < bottom) {
273 harmonic = floor(bottom / _target_frame_rate + 0.5) * _target_frame_rate;
277 harmonic = _target_frame_rate / floor(_target_frame_rate / bottom + 0.5);
281 for (
int k = 1; k / harmonic <= scale; k++) {
282 _guide_bars.push_back(make_guide_bar(k / harmonic));
285 _guide_bars_changed =
true;
295 make_guide_bar(
double value, PStatGraph::GuideBarStyle style)
const {
296 string label =
format_number(value, _guide_bar_units, _unit_name);
298 if ((style == GBS_normal) &&
299 (_guide_bar_units & GBU_named) == 0) {
302 double hz = 1.0 / value;
303 if (IS_THRESHOLD_EQUAL(hz, _target_frame_rate, 0.001)) {
308 return GuideBar(value, label, style);
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
int find_user_guide_bar(double from_height, double to_height) const
Returns the index number of the first user guide bar found whose height is within the indicated range...
This is an abstract class that presents the interface to any number of different front-ends for the s...
const GuideBar & get_guide_bar(int n) const
Returns the nth horizontal guide bar.
int get_num_guide_bars() const
Returns the number of horizontal guide bars that should be drawn, based on the indicated target frame...
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
static string format_number(double value)
Returns a string representing the value nicely formatted for its range.
GuideBar get_user_guide_bar(int n) const
Returns the nth user-defined guide bar.
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.