Logo Search packages:      
Sourcecode: kcollectd version File versions  Download package

void Graph::drawGraph ( QPainter &  paint,
const QRect &  rect,
const GraphInfo ginfo,
double  min,
double  max 
) [private]

draw the graph itself

Definition at line 540 of file graph.cc.

Referenced by drawAll().

{
  const linMap ymap(min, rect.bottom(), max, rect.top());
  // define once use many
  QPolygon points;
  
  paint.save();
  //paint.setRenderHint(QPainter::Antialiasing);

  // draw all min/max backshadows
  int color_nr = 0;
  for(GraphInfo::const_iterator gi = ginfo.begin(); gi != ginfo.end(); ++gi) {
    const std::vector<double> &min_data = gi->min_data;
    const std::vector<double> &max_data = gi->max_data;

    if (min_data.empty() || max_data.empty())
      continue;
    const int size = gi->min_data.size();

    // setting up linear mappings
    const linMap xmap(0, rect.left(), size-1, rect.right());
   
    if (!min_data.empty() && !max_data.empty()) {  
      paint.setPen(Qt::NoPen);
      paint.setBrush(QBrush(color_minmax[color_nr++ % 8]));
      for(int i=0; i<size; ++i) {
      while (i<size && (isnan(min_data[i]) || isnan(max_data[i]))) ++i;
      int l = i;
      while (i<size && !isnan(min_data[i]) && !isnan(max_data[i])) ++i;
      const int asize = i-l;
      points.resize(asize*2);
      int k;
      for(k=0; k<asize; ++k, ++l) {
        points.setPoint(k, xmap(l), ymap(min_data[l]));
      }
      --l;
      for(; k<2*asize; ++k, --l) {
        points.setPoint(k, xmap(l), ymap(max_data[l]));
      }
      paint.drawPolygon(points);
      }
    }
  }

  // draw all averages
  color_nr = 0;
  for(GraphInfo::const_iterator gi = ginfo.begin(); gi != ginfo.end(); ++gi) {
    const std::vector<double> &avg_data = gi->avg_data;

    if (avg_data.empty()) continue;
    const int size = avg_data.size();
    
    // setting up linear mappings
    const linMap xmap(0, rect.left(), size-1, rect.right());
   
    // draw ing
    if (!avg_data.empty()) {
      paint.setPen(color_line[color_nr++ % 8]);
      for(int i=0; i<size; ++i) {
      while (i<size && isnan(avg_data[i])) ++i;
      int l = i;
      while (i<size && !isnan(avg_data[i])) ++i;
      const int asize = i-l;
      points.resize(asize);
      for(int k=0; k<asize; ++k, ++l) {
        points.setPoint(k, xmap(l), ymap(avg_data[l]));
      }
      paint.drawPolyline(points);
      }
    }
  }
  paint.restore();
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index