<commit_before>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/plotUI/CopasiPlot.cpp,v $
//   $Revision: 1.49 $
//   $Name:  $
//   $Author: shoops $
//   $Date: 2007/07/24 18:40:25 $
// End CVS Header

// Copyright (C) 2007 by <NAME>, Virginia Tech Intellectual
// Properties, Inc. and EML Research, gGmbH.
// All rights reserved.

#include <qstring.h>
#include <qcolor.h>   //might need to go to the header file
#include <qcursor.h>

#include <qwt_symbol.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include <qwt_scale_engine.h>

#include <float.h>
#include <limits>
#include <algorithm>

#include "scrollzoomer.h"

#include "CopasiPlot.h"
#include "plot/CPlotSpecification.h"
#include "UI/qtUtilities.h"

#define ActivitySize 8

//********************  data  *********************************************
MyQwtCPointerData::MyQwtCPointerData(const double *x, const double *y, size_t size):
    QwtCPointerData(x, y, size)
{}

MyQwtCPointerData & MyQwtCPointerData::operator=(const MyQwtCPointerData & rhs)
{
  *static_cast<QwtCPointerData *>(this) = *static_cast<const QwtCPointerData *>(&rhs);
  return * this;
}

QwtData * MyQwtCPointerData::copy() const
  {return new MyQwtCPointerData(xData(), yData(), size());}

QwtDoubleRect MyQwtCPointerData::boundingRect() const
  {
    const size_t sz = size();

    if (sz <= 0)
      return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    double minX, maxX, minY, maxY;

    const double *xIt = xData();
    const double *yIt = yData();
    const double *end = xIt + sz;

    minX = maxX = *xIt++;
    minY = maxY = *yIt++;

    while (xIt < end)
      {
        const double xv = *xIt++;
        if (!isnan(xv))
          {
            if (xv < minX)
              minX = xv;
            if (xv > maxX)
              maxX = xv;
          }

        const double yv = *yIt++;
        if (!isnan(yv))
          {
            if (yv < minY)
              minY = yv;
            if (yv > maxY)
              maxY = yv;
          }
      }

    if (isnan(minX + maxX + minY + maxY))
      return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
  }
//********************  curve  ********************************************

//draw the several curves, separated by NaNs.
void MyQwtPlotCurve::myDrawLines(QPainter *painter,
                                 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                                 int from, int to) const
  {
    int to2;
    do
      {
        int i;
        for (i = from; i <= to; ++i)
          if (isnan(x(i))) //NaN
            break;

        if (i == from)
          {
            ++from;
            continue;
          }

        to2 = i - 1;

        QwtPlotCurve::drawLines(painter, xMap, yMap, from, to2);

        from = to2 + 2;
      }
    while (from < to);
  }

//virtual
void MyQwtPlotCurve::drawCurve(QPainter *painter, int style,
                               const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                               int from, int to) const
  {
    if (style == Lines)
      myDrawLines(painter, xMap, yMap, from, to);
    else
      QwtPlotCurve::drawCurve(painter, style, xMap, yMap, from, to);
  }

//************************************
C_FLOAT64 CopasiPlot::MissingValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();

CopasiPlot::CopasiPlot(QWidget* parent):
    QwtPlot(parent),
    mCurveMap(),
    mpPlotSpecification(NULL),
    mpZoomer(NULL)
{}

CopasiPlot::CopasiPlot(const CPlotSpecification* plotspec, QWidget* parent):
    QwtPlot(parent),
    mCurveMap(),
    mpPlotSpecification(NULL),
    mpZoomer(NULL)
{
  QwtLegend *legend = new QwtLegend;
  legend->setItemMode(QwtLegend::CheckableItem);
  insertLegend(legend, QwtPlot::BottomLegend);

  // Set up the zoom facility
  mpZoomer = new ScrollZoomer(canvas());
  mpZoomer->setRubberBandPen(QColor(Qt::black));
  mpZoomer->setTrackerPen(QColor(Qt::black));
  mpZoomer->setTrackerMode(QwtPicker::AlwaysOn);
  mpZoomer->setTrackerFont(this->font());

  // white background better for printing...
  setCanvasBackground(white);

  //  setTitle(FROM_UTF8(plotspec->getTitle()));
  setCanvasLineWidth(0);

  canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);

  connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
          SLOT(showCurve(QwtPlotItem *, bool)));

  // Size the vectors to be able to store information for all activities.<commit_msg>Whole legend can not be displayed at bottom on DARWIN. Maybe a Qwt bug.<commit_after>// Begin CVS Header
//   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/plotUI/CopasiPlot.cpp,v $
//   $Revision: 1.50 $
//   $Name:  $
//   $Author: akoenig $
//   $Date: 2007/10/25 13:02:05 $
// End CVS Header

// Copyright (C) 2007 by <NAME>, Virginia Tech Intellectual
// Properties, Inc. and EML Research, gGmbH.
// All rights reserved.

#include <qstring.h>
#include <qcolor.h>   //might need to go to the header file
#include <qcursor.h>

#include <qwt_symbol.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include <qwt_scale_engine.h>

#include <float.h>
#include <limits>
#include <algorithm>

#include "scrollzoomer.h"

#include "CopasiPlot.h"
#include "plot/CPlotSpecification.h"
#include "UI/qtUtilities.h"

#define ActivitySize 8

//********************  data  *********************************************
MyQwtCPointerData::MyQwtCPointerData(const double *x, const double *y, size_t size):
    QwtCPointerData(x, y, size)
{}

MyQwtCPointerData & MyQwtCPointerData::operator=(const MyQwtCPointerData & rhs)
{
  *static_cast<QwtCPointerData *>(this) = *static_cast<const QwtCPointerData *>(&rhs);
  return * this;
}

QwtData * MyQwtCPointerData::copy() const
  {return new MyQwtCPointerData(xData(), yData(), size());}

QwtDoubleRect MyQwtCPointerData::boundingRect() const
  {
    const size_t sz = size();

    if (sz <= 0)
      return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    double minX, maxX, minY, maxY;

    const double *xIt = xData();
    const double *yIt = yData();
    const double *end = xIt + sz;

    minX = maxX = *xIt++;
    minY = maxY = *yIt++;

    while (xIt < end)
      {
        const double xv = *xIt++;
        if (!isnan(xv))
          {
            if (xv < minX)
              minX = xv;
            if (xv > maxX)
              maxX = xv;
          }

        const double yv = *yIt++;
        if (!isnan(yv))
          {
            if (yv < minY)
              minY = yv;
            if (yv > maxY)
              maxY = yv;
          }
      }

    if (isnan(minX + maxX + minY + maxY))
      return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
  }
//********************  curve  ********************************************

//draw the several curves, separated by NaNs.
void MyQwtPlotCurve::myDrawLines(QPainter *painter,
                                 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                                 int from, int to) const
  {
    int to2;
    do
      {
        int i;
        for (i = from; i <= to; ++i)
          if (isnan(x(i))) //NaN
            break;

        if (i == from)
          {
            ++from;
            continue;
          }

        to2 = i - 1;

        QwtPlotCurve::drawLines(painter, xMap, yMap, from, to2);

        from = to2 + 2;
      }
    while (from < to);
  }

//virtual
void MyQwtPlotCurve::drawCurve(QPainter *painter, int style,
                               const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                               int from, int to) const
  {
    if (style == Lines)
      myDrawLines(painter, xMap, yMap, from, to);
    else
      QwtPlotCurve::drawCurve(painter, style, xMap, yMap, from, to);
  }

//************************************
C_FLOAT64 CopasiPlot::MissingValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();

CopasiPlot::CopasiPlot(QWidget* parent):
    QwtPlot(parent),
    mCurveMap(),
    mpPlotSpecification(NULL),
    mpZoomer(NULL)
{}

CopasiPlot::CopasiPlot(const CPlotSpecification* plotspec, QWidget* parent):
    QwtPlot(parent),
    mCurveMap(),
    mpPlotSpecification(NULL),
    mpZoomer(NULL)
{
  QwtLegend *legend = new QwtLegend;
  legend->setItemMode(QwtLegend::CheckableItem);

  // whole legend can not be displayed at bottom on DARWIN
  // maybe a Qwt bug ?!?
#ifdef Darwin
  insertLegend(legend, QwtPlot::TopLegend);
#else
  insertLegend(legend, QwtPlot::BottomLegend);
#endif

  // Set up the zoom facility
  mpZoomer = new ScrollZoomer(canvas());
  mpZoomer->setRubberBandPen(QColor(Qt::black));
  mpZoomer->setTrackerPen(QColor(Qt::black));
  mpZoomer->setTrackerMode(QwtPicker::AlwaysOn);
  mpZoomer->setTrackerFont(this->font());

  // white background better for printing...
  setCanvasBackground(white);

  //  setTitle(FROM_UTF8(plotspec->getTitle()));
  setCanvasLineWidth(0);

  canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);

  connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
          SLOT(showCurve(QwtPlotItem *, bool)));

  // Size the vectors to be able to store information for all activities.
{'fraction_non_alphanumeric': 0.16603281538628709, 'fraction_numerical': 0.011083342388351625, 'mean_word_length': 2.693418940609952, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7121801', 'n_tokens_mistral': 3336, 'n_tokens_neox': 3175, 'n_words': 730}