Panda3D
Classes | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
PStatStripChart Class Reference

This is an abstract class that presents the interface for drawing a basic strip-chart, showing the relative value over an interval of time for several different collectors, differentiated by bands of color. More...

#include "pStatStripChart.h"

Inheritance diagram for PStatStripChart:
PStatGraph GtkStatsStripChart WinStatsStripChart

List of all members.

Classes

class  ColorData

Public Member Functions

 PStatStripChart (PStatMonitor *monitor, PStatView &view, int thread_index, int collector_index, int xsize, int ysize)
bool first_data () const
 Returns true if the chart has seen its first data appear on it, false if it is still a virgin chart.
bool get_average_mode () const
 Returns the current state of the average_mode flag.
int get_collector_index () const
 Returns the particular collector whose data this strip chart reflects.
int get_collector_under_pixel (int xpoint, int ypoint)
 Return the collector index associated with the particular band of color at the indicated pixel location, or -1 if no band of color was at the pixel.
double get_horizontal_scale () const
 Returns the amount of total time the width of the horizontal axis represents.
bool get_scroll_mode () const
 Returns the current state of the scroll_mode flag.
string get_title_text ()
 Returns the text suitable for the title label on the top line.
double get_vertical_scale () const
 Returns total value the height of the vertical axis represents.
PStatViewget_view () const
 Returns the View this chart represents.
int height_to_pixel (double value) const
 Converts a value (i.e.
bool is_title_unknown () const
 Returns true if get_title_text() has never yet returned an answer, false if it has.
void new_data (int frame_number)
 Indicates that new data has become available.
double pixel_to_height (int y) const
 Converts a vertical pixel offset to a value (a "height" in the strip chart).
double pixel_to_timestamp (int x) const
 Converts a horizontal pixel offset to a timestamp.
void set_auto_vertical_scale ()
 Sets the vertical scale to make all the data visible.
void set_average_mode (bool average_mode)
 Changes the average_mode flag.
void set_collector_index (int collector_index)
 Changes the collector represented by this strip chart.
void set_default_vertical_scale ()
 Sets the vertical scale according to the suggested scale of the base collector, if any, or to center the target frame rate bar otherwise.
void set_horizontal_scale (double time_width)
 Changes the amount of time the width of the horizontal axis represents.
void set_scroll_mode (bool scroll_mode)
 Changes the scroll_mode flag.
void set_vertical_scale (double value_height)
 Changes the value the height of the vertical axis represents.
int timestamp_to_pixel (double time) const
 Converts a timestamp to a horizontal pixel offset.
void update ()
 Updates the chart with the latest data.

Protected Types

typedef pmap< int, FrameData > Data
typedef pvector< ColorDataFrameData

Protected Member Functions

virtual void begin_draw (int from_x, int to_x)
 Should be overridden by the user class.
void changed_size (int xsize, int ysize)
 To be called by the user class when the widget size has changed.
virtual void clear_region ()
 Should be overridden by the user class to wipe out the entire strip chart region.
void compute_average_pixel_data (PStatStripChart::FrameData &result, int &then_i, int &now_i, double now)
 Fills the indicated FrameData structure with the color data for the indicated pixel, averaged over the past pstats_average_time seconds.
virtual void copy_region (int start_x, int end_x, int dest_x)
 Should be overridden by the user class to copy a region of the chart from one part of the chart to another.
virtual void draw_cursor (int x)
 This is similar to draw_slice(), except that it should draw the black vertical stripe that represents the current position when not in scrolling mode.
virtual void draw_empty (int x, int w)
 This is similar to draw_slice(), except it should draw a vertical line of the background color to represent a portion of the chart that has no data.
virtual void draw_slice (int x, int w, const FrameData &fdata)
 Should be overridden by the user class to draw a single vertical slice in the strip chart at the indicated pixel, with the data for the indicated frame.
virtual void end_draw (int from_x, int to_x)
 Should be overridden by the user class.
void force_redraw ()
 To be called by the user class when the whole thing needs to be redrawn for some reason.
void force_reset ()
 To be called by the user class to cause the chart to reset to empty and start filling again.
double get_average_net_value () const
 Computes the average value of the chart's collector over the past pstats_average_time number of seconds.
const FrameData & get_frame_data (int frame_number)
 Returns the cached FrameData associated with the given frame number.
double get_net_value (int frame_number) const
 Returns the net value of the chart's collector for the indicated frame number.
virtual void idle ()
 Should be overridden by the user class to perform any other updates might be necessary after the color bars have been redrawn.
bool is_label_used (int collector_index) const
 Returns true if the indicated collector appears anywhere on the chart at the current time, false otherwise.
virtual void normal_guide_bars ()
 Calls update_guide_bars with parameters suitable to this kind of graph.
virtual void update_labels ()
 Resets the list of labels.

Static Protected Member Functions

static void accumulate_frame_data (FrameData &fdata, const FrameData &additional, double weight)
 Adds the data from additional into the data from fdata, after applying the scale weight.
static void scale_frame_data (FrameData &fdata, double factor)
 Applies the indicated scale to all collector values in data.

Protected Attributes

int _thread_index

Detailed Description

This is an abstract class that presents the interface for drawing a basic strip-chart, showing the relative value over an interval of time for several different collectors, differentiated by bands of color.

This class just manages all the strip-chart logic; the actual nuts and bolts of drawing pixels is left to a user-derived class.

Definition at line 42 of file pStatStripChart.h.


Member Function Documentation

void PStatStripChart::accumulate_frame_data ( FrameData &  fdata,
const FrameData &  additional,
double  weight 
) [static, protected]

Adds the data from additional into the data from fdata, after applying the scale weight.

Definition at line 325 of file pStatStripChart.cxx.

Referenced by compute_average_pixel_data().

void PStatStripChart::begin_draw ( int  from_x,
int  to_x 
) [protected, virtual]

Should be overridden by the user class.

This hook will be called before drawing any color bars in the strip chart; it gives the pixel range that's about to be redrawn.

Definition at line 719 of file pStatStripChart.cxx.

void PStatStripChart::changed_size ( int  xsize,
int  ysize 
) [protected]

To be called by the user class when the widget size has changed.

This updates the chart's internal data and causes it to issue redraw commands to reflect the new size.

Definition at line 635 of file pStatStripChart.cxx.

Referenced by GtkStatsStripChart::changed_graph_size(), and WinStatsStripChart::changed_graph_size().

void PStatStripChart::clear_region ( ) [protected, virtual]

Should be overridden by the user class to wipe out the entire strip chart region.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 696 of file pStatStripChart.cxx.

Referenced by force_reset().

void PStatStripChart::compute_average_pixel_data ( PStatStripChart::FrameData &  result,
int &  then_i,
int &  now_i,
double  now 
) [protected]

Fills the indicated FrameData structure with the color data for the indicated pixel, averaged over the past pstats_average_time seconds.

now is the timestamp for which we are computing the data; then_i and now_i are the frame numbers that bound (now - pstats_average_time) and now. At function initialization time, these should be at or below the actual values; they will be incremented as needed by this function. This allows the function to be called repeatedly for successive pixels.

Definition at line 493 of file pStatStripChart.cxx.

References accumulate_frame_data(), PStatFrameData::get_end(), PStatThreadData::get_frame(), get_frame_data(), PStatThreadData::get_latest_frame_number(), PStatThreadData::get_oldest_time(), PStatFrameData::get_start(), PStatView::get_thread_data(), PStatThreadData::is_empty(), and scale_frame_data().

Referenced by get_collector_under_pixel().

void PStatStripChart::copy_region ( int  start_x,
int  end_x,
int  dest_x 
) [protected, virtual]

Should be overridden by the user class to copy a region of the chart from one part of the chart to another.

This is used to implement scrolling.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 707 of file pStatStripChart.cxx.

void PStatStripChart::draw_cursor ( int  x) [protected, virtual]

This is similar to draw_slice(), except that it should draw the black vertical stripe that represents the current position when not in scrolling mode.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 753 of file pStatStripChart.cxx.

void PStatStripChart::draw_empty ( int  x,
int  w 
) [protected, virtual]

This is similar to draw_slice(), except it should draw a vertical line of the background color to represent a portion of the chart that has no data.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 742 of file pStatStripChart.cxx.

void PStatStripChart::draw_slice ( int  x,
int  w,
const FrameData &  fdata 
) [protected, virtual]

Should be overridden by the user class to draw a single vertical slice in the strip chart at the indicated pixel, with the data for the indicated frame.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 731 of file pStatStripChart.cxx.

void PStatStripChart::end_draw ( int  from_x,
int  to_x 
) [protected, virtual]

Should be overridden by the user class.

This hook will be called after drawing a series of color bars in the strip chart; it gives the pixel range that was just redrawn.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 765 of file pStatStripChart.cxx.

Returns true if the chart has seen its first data appear on it, false if it is still a virgin chart.

Definition at line 135 of file pStatStripChart.cxx.

void PStatStripChart::force_redraw ( ) [protected]

To be called by the user class when the whole thing needs to be redrawn for some reason.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 670 of file pStatStripChart.cxx.

Referenced by set_average_mode(), set_collector_index(), and set_vertical_scale().

void PStatStripChart::force_reset ( ) [protected]

To be called by the user class to cause the chart to reset to empty and start filling again.

Definition at line 683 of file pStatStripChart.cxx.

References clear_region().

Referenced by set_horizontal_scale().

bool PStatStripChart::get_average_mode ( ) const [inline]

Returns the current state of the average_mode flag.

When true, the strip chart will average out the color values over pstats_average_time seconds, which hides spikes and makes the overall trends easier to read. When false, the strip chart shows the actual data as it is happening.

Definition at line 151 of file pStatStripChart.I.

double PStatStripChart::get_average_net_value ( ) const [protected]
int PStatStripChart::get_collector_index ( ) const [inline]

Returns the particular collector whose data this strip chart reflects.

Definition at line 33 of file pStatStripChart.I.

Referenced by GtkStatsStripChart::clicked_label(), and WinStatsStripChart::clicked_label().

int PStatStripChart::get_collector_under_pixel ( int  xpoint,
int  ypoint 
)

Return the collector index associated with the particular band of color at the indicated pixel location, or -1 if no band of color was at the pixel.

Definition at line 219 of file pStatStripChart.cxx.

References compute_average_pixel_data(), get_frame_data(), PStatThreadData::get_frame_number_at_time(), PStatView::get_thread_data(), PStatGraph::get_ysize(), height_to_pixel(), and pixel_to_timestamp().

Referenced by GtkStatsStripChart::handle_button_press(), and GtkStatsStripChart::handle_motion().

const PStatStripChart::FrameData & PStatStripChart::get_frame_data ( int  frame_number) [protected]

Returns the cached FrameData associated with the given frame number.

This describes the lengths of the color bands for a single vertical stripe in the chart.

Definition at line 437 of file pStatStripChart.cxx.

References PStatViewLevel::get_child(), PStatViewLevel::get_collector(), PStatThreadData::get_frame(), PStatView::get_level(), PStatViewLevel::get_net_value(), PStatViewLevel::get_num_children(), PStatView::get_thread_data(), PStatViewLevel::get_value_alone(), and PStatView::set_to_frame().

Referenced by compute_average_pixel_data(), and get_collector_under_pixel().

double PStatStripChart::get_horizontal_scale ( ) const [inline]

Returns the amount of total time the width of the horizontal axis represents.

Definition at line 62 of file pStatStripChart.I.

double PStatStripChart::get_net_value ( int  frame_number) const [protected]

Returns the net value of the chart's collector for the indicated frame number.

Definition at line 550 of file pStatStripChart.cxx.

Referenced by get_average_net_value(), and set_auto_vertical_scale().

bool PStatStripChart::get_scroll_mode ( ) const [inline]

Returns the current state of the scroll_mode flag.

When true, the strip chart will update itself by scrolling to the left; when false, the strip chart will wrap around at the right and restart at the left end without scrolling.

Definition at line 118 of file pStatStripChart.I.

double PStatStripChart::get_vertical_scale ( ) const [inline]

Returns total value the height of the vertical axis represents.

Definition at line 88 of file pStatStripChart.I.

Referenced by WinStatsStripChart::additional_window_paint(), GtkStatsStripChart::draw_slice(), and WinStatsStripChart::draw_slice().

PStatView & PStatStripChart::get_view ( ) const [inline]

Returns the View this chart represents.

Definition at line 22 of file pStatStripChart.I.

Referenced by GtkStatsStripChart::clicked_label(), and WinStatsStripChart::clicked_label().

int PStatStripChart::height_to_pixel ( double  value) const [inline]

Converts a value (i.e.

a "height" in the strip chart) to a vertical pixel offset.

Definition at line 182 of file pStatStripChart.I.

References PStatGraph::get_ysize().

Referenced by GtkStatsStripChart::draw_slice(), WinStatsStripChart::draw_slice(), and get_collector_under_pixel().

void PStatStripChart::idle ( ) [protected, virtual]

Should be overridden by the user class to perform any other updates might be necessary after the color bars have been redrawn.

For instance, it could check the state of _labels_changed, and redraw the labels if it is true.

Definition at line 778 of file pStatStripChart.cxx.

Referenced by update().

bool PStatStripChart::is_label_used ( int  collector_index) const [inline, protected]

Returns true if the indicated collector appears anywhere on the chart at the current time, false otherwise.

Definition at line 205 of file pStatStripChart.I.

Referenced by update_labels().

Returns true if get_title_text() has never yet returned an answer, false if it has.

Definition at line 314 of file pStatStripChart.cxx.

Referenced by GtkStatsStripChart::new_data(), and WinStatsStripChart::new_data().

void PStatStripChart::new_data ( int  frame_number)

Indicates that new data has become available.

Definition at line 77 of file pStatStripChart.cxx.

void PStatStripChart::normal_guide_bars ( ) [protected, virtual]

Calls update_guide_bars with parameters suitable to this kind of graph.

Implements PStatGraph.

Definition at line 833 of file pStatStripChart.cxx.

References PStatGraph::update_guide_bars().

Referenced by set_vertical_scale().

double PStatStripChart::pixel_to_height ( int  y) const [inline]
double PStatStripChart::pixel_to_timestamp ( int  x) const [inline]

Converts a horizontal pixel offset to a timestamp.

Definition at line 171 of file pStatStripChart.I.

References PStatGraph::get_xsize().

Referenced by get_collector_under_pixel(), and set_auto_vertical_scale().

void PStatStripChart::scale_frame_data ( FrameData &  fdata,
double  factor 
) [static, protected]

Applies the indicated scale to all collector values in data.

Definition at line 420 of file pStatStripChart.cxx.

Referenced by compute_average_pixel_data().

void PStatStripChart::set_average_mode ( bool  average_mode) [inline]

Changes the average_mode flag.

When true, the strip chart will average out the color values over pstats_average_time seconds, which hides spikes and makes the overall trends easier to read. When false, the strip chart shows the actual data as it is happening.

Definition at line 133 of file pStatStripChart.I.

References force_redraw().

Referenced by GtkStatsStripChart::set_drag_mode(), WinStatsStripChart::set_drag_mode(), and WinStatsStripChart::window_proc().

void PStatStripChart::set_collector_index ( int  collector_index)

Changes the collector represented by this strip chart.

This may force a redraw.

Definition at line 146 of file pStatStripChart.cxx.

References force_redraw(), and update_labels().

Referenced by GtkStatsStripChart::clicked_label(), and WinStatsStripChart::clicked_label().

Sets the vertical scale according to the suggested scale of the base collector, if any, or to center the target frame rate bar otherwise.

Definition at line 165 of file pStatStripChart.cxx.

References PStatClientData::get_collector_def(), PStatGraph::get_target_frame_rate(), PStatClientData::has_collector(), and set_vertical_scale().

void PStatStripChart::set_horizontal_scale ( double  time_width) [inline]

Changes the amount of time the width of the horizontal axis represents.

This may force a redraw.

Definition at line 44 of file pStatStripChart.I.

References force_reset().

Referenced by GtkStatsStripChart::set_scroll_speed(), and WinStatsStripChart::set_scroll_speed().

void PStatStripChart::set_scroll_mode ( bool  scroll_mode) [inline]

Changes the scroll_mode flag.

When true, the strip chart will update itself by scrolling to the left; when false, the strip chart will wrap around at the right and restart at the left end without scrolling.

Definition at line 101 of file pStatStripChart.I.

void PStatStripChart::set_vertical_scale ( double  value_height) [inline]

Changes the value the height of the vertical axis represents.

This may force a redraw.

Reimplemented in GtkStatsStripChart, and WinStatsStripChart.

Definition at line 73 of file pStatStripChart.I.

References force_redraw(), and normal_guide_bars().

Referenced by set_auto_vertical_scale(), and set_default_vertical_scale().

int PStatStripChart::timestamp_to_pixel ( double  time) const [inline]

Converts a timestamp to a horizontal pixel offset.

Definition at line 161 of file pStatStripChart.I.

References PStatGraph::get_xsize().

void PStatStripChart::update_labels ( ) [protected, virtual]

The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations