void
CGnuPlotStyleRadar::
getPointsColor(CGnuPlotRadarStyleValue *value, int pi, CRGBA &lc, CRGBA &fc)
{
  lc = CGnuPlotStyleInst->indexColor(value->palette(), pi);
  fc = lc;

  fc.setAlpha(0.5);
}
Exemple #2
0
CRGBA
CSVGStroke::
getAlphaColor() const
{
  CRGBA rgba;

  if (color_.getValid()) {
    rgba = color_.getValue();

    if (getOpacityValid())
      rgba.setAlpha(getOpacity());
  }
  else
    rgba = CRGBA(0,0,0,0);

  return rgba;
}
void
CGnuPlotStyleRadar::
draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer)
{
  CGnuPlotRadarStyleValue *value =
    CGnuPlotStyleValueMgrInst->getValue<CGnuPlotRadarStyleValue>(plot);

  if (! value) {
    value = plot->app()->device()->createRadarStyleValue(plot);

    CGnuPlotStyleValueMgrInst->setValue<CGnuPlotRadarStyleValue>(plot, value);
  }

  //---

  const CBBox2D &bbox = plot->bbox2D();

  CPoint2D pc = bbox.getCenter();
  double   r  = bbox.getWidth()/2;

  int np = -1;

  for (const auto &point : plot->getPoints2D()) {
    np = std::min(np < 0 ? INT_MAX : np, point.getNumValues());
  }

  if (np < 3)
    return;

  //double pw = renderer->pixelWidthToWindowWidth  (1);
  //double ph = renderer->pixelHeightToWindowHeight(1);

  CGnuPlotGroup *group = plot->group();

  const CGnuPlotKeyData  &keyData = plot->keyData();
  const CGnuPlotAxisData &xaxis   = group->xaxis(1);

  const CGnuPlotKey::Columns &columns = keyData.columns();

  double da = 360/np;

  std::vector<CPoint2D> points = radarPoints(value->angleStart(), pc, r, np);

  double v = getRange(plot);

  //---

  // draw border
  renderer->drawPolygon(points, value->borderColor(), value->borderWidth(), value->borderDash());

  //---

  // draw column labels (how determine indices)
  {
    double a = value->angleStart();

    for (int i = 1; i <= np && i < int(columns.size()); ++i) {
      CPoint2D p = radarPoint(pc, r, a);

      CHAlignType halign = CHALIGN_TYPE_CENTER;
      CVAlignType valign = CVALIGN_TYPE_CENTER;

      double dx = 0;
      double dy = 0;

      if      (p.x < pc.x - v/2) {
        halign = CHALIGN_TYPE_RIGHT;
        dx     = -8;
      }
      else if (p.x > pc.x + v/2) {
        halign = CHALIGN_TYPE_LEFT;
        dx     = 8;
      }

      if      (p.y < pc.y - v/2) {
        valign = CVALIGN_TYPE_TOP;
        dy     = 8;
      }
      else if (p.y > pc.y + v/2) {
        valign = CVALIGN_TYPE_BOTTOM;
        dy     = -8;
      }

      CRGBA tc = CRGBA(0,0,0);

      renderer->drawHAlignedText(p, HAlignPos(halign, dx), VAlignPos(valign, dy), columns[i], tc),

      a -= da;
    }
  }

  //---

  // draw axis if needed
  if (xaxis.isDisplayed()) {
    CRGBA ac = value->axisColor();

    ac.setAlpha(value->axisAlpha());

    double dr = 0.1;
    double ra = 0.1;

    while (ra < v) {
      std::vector<CPoint2D> points1 = radarPoints(value->angleStart(), pc, ra, np);

      renderer->drawPolygon(points1, ac, value->axisWidth(), value->axisDash());

      ra += dr;
    }

    for (const auto &p : points)
      renderer->drawLine(p, pc, ac, value->axisWidth(), value->axisDash());
  }

  //---

  bool cache = false;

  if (! renderer->isPseudo() && plot->isCacheActive()) {
    plot->updatePolygonCacheSize(plot->numPoints2D());

    cache = true;
  }

  int pi = 0;

  for (const auto &point : plot->getPoints2D()) {
    std::vector<CPoint2D> points1;

    double a = value->angleStart();

    for (int i = 0; i < np; ++i) {
      double v1;

      if (! point.getValue(i + 1, v1))
        continue;

      CPoint2D p = radarPoint(pc, v1, a);

      points1.push_back(p);

      a -= da;
    }

    CRGBA lc, fc;

    getPointsColor(value, pi + 1, lc, fc);

    if (cache) {
    //std::string label = (pi < int(columns.size()) ? columns[pi] : "");
      std::string label = xaxis.iticLabel(pi);

      auto polygon = plot->polygonObjects()[pi];

      polygon->setPoints(points1);
      polygon->setTipText(label);

      if (! polygon->testAndSetUsed()) {
        CGnuPlotFillP   fill  (polygon->fill  ()->dup());
        CGnuPlotStrokeP stroke(polygon->stroke()->dup());

        fill->setColor(fc);
        fill->setType (CGnuPlotTypes::FillType::SOLID);

        stroke->setColor   (lc);
        stroke->setWidth   (value->strokeWidth());
        stroke->setLineDash(value->strokeDash());

        polygon->setFill  (fill  );
        polygon->setStroke(stroke);
      }
    }
    else {
      renderer->fillPolygon(points1, fc);

      renderer->drawPolygon(points1, lc, value->strokeWidth(), value->strokeDash());
    }

    ++pi;
  }

  if (cache) {
    for (const auto &polygon : plot->polygonObjects())
      polygon->draw(renderer);
  }
}