void CGnuPlotStyleRadar:: drawKey(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotRadarStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotRadarStyleValue>(plot); if (! value) return; //--- CGnuPlotGroup *group = plot->group(); const CGnuPlotKeyP &key = group->key(); const CGnuPlotAxisData &xaxis = group->xaxis(1); if (! key->isDisplayed()) return; if (key->getFont().isValid()) renderer->setFont(key->getFont()); CGnuPlotFill fill(plot); //--- CBBox2D rbbox = (key->isOutside() ? group->getRegionBBox() : renderer->range()); //--- CFontPtr font = renderer->getFont(); double font_size = font->getCharAscent() + font->getCharDescent(); double pw = renderer->pixelWidthToWindowWidth (1); double ph = renderer->pixelHeightToWindowHeight(1); double bx = 8*pw; double by = 8*ph; double bw = font_size - 2; CSize2D size; double textWidth = 0.0, textHeight = 0.0; std::string header; if (key->hasTitle()) { header = key->title(); if (header != "") textHeight += font_size*ph; } int i = 0; for (const auto &point : plot->getPoints2D()) { assert(! point.isDiscontinuity()); std::string label = xaxis.iticLabel(i); //std::string label = point.label(); textWidth = std::max(textWidth, font->getStringWidth(label)*pw); textHeight += font_size*ph; ++i; } size = CSize2D(textWidth + bw*pw + 3*bx, textHeight + 2*by); CHAlignType halign = key->getHAlign(); CVAlignType valign = key->getVAlign(); double x1 = 0, y1 = 0; if (halign == CHALIGN_TYPE_LEFT) x1 = rbbox.getLeft () + bx; else if (halign == CHALIGN_TYPE_RIGHT) x1 = rbbox.getRight() - bx - size.getWidth(); else if (halign == CHALIGN_TYPE_CENTER) x1 = rbbox.getXMid() - size.getWidth()/2; if (valign == CVALIGN_TYPE_TOP) y1 = rbbox.getTop () - by - size.getHeight(); else if (valign == CVALIGN_TYPE_BOTTOM) y1 = rbbox.getBottom() + by; else if (valign == CVALIGN_TYPE_CENTER) y1 = rbbox.getYMid() - size.getHeight()/2; double x2 = x1 + size.getWidth (); double y2 = y1 + size.getHeight(); CBBox2D bbox(x1, y1, x2, y2); if (key->getFillBox()) { renderer->fillRect(bbox, fill.background()); } if (key->getDrawBox()) { CRGBA c(0, 0, 0); if (key->hasLineType()) c = CGnuPlotStyleInst->indexColor(value->palette(), key->getLineType()); renderer->drawRect(bbox, c, 1); } double y = y2 - by; if (header != "") { CRGBA tc = CRGBA(0,0,0); renderer->drawHAlignedText(CPoint2D((x1 + x2)/2, y), HAlignPos(CHALIGN_TYPE_CENTER, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), header, tc); y -= font_size*ph; } int pi = 0; for (const auto &point : plot->getPoints2D()) { assert(! point.isDiscontinuity()); double xx = (key->isReverse() ? x1 + bx : x2 - bw*pw - bx); double yy = y - font_size*ph/2; CPoint2D p1(xx, yy - bw*ph/2), p2(xx + bw*pw, yy + bw*ph/2); CRGBA lc, fc; getPointsColor(value, pi + 1, lc, fc); CBBox2D bbox(p1, p2); renderer->fillRect(bbox, fc); renderer->drawRect(bbox, lc, 1); std::string label = xaxis.iticLabel(pi); //std::string label = point.label(); //double lw = font->getStringWidth(label); CRGBA tc = CRGBA(0,0,0); if (key->isReverse()) renderer->drawHAlignedText(CPoint2D(xx + bw*pw + bx, y), HAlignPos(CHALIGN_TYPE_LEFT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), label, tc); else renderer->drawHAlignedText(CPoint2D(xx - bx, y), HAlignPos(CHALIGN_TYPE_RIGHT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), label, tc); y -= font_size*ph; ++pi; } }
void CGnuPlotStylePieChart:: drawKey(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotPieChartStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotPieChartStyleValue>(plot); if (! value) return; //--- CGnuPlotGroup *group = plot->group(); const CGnuPlotKeyP &key = group->key(); //const CGnuPlotAxisData &xaxis = group->xaxis(1); if (! key->isDisplayed()) return; if (key->getFont().isValid()) renderer->setFont(key->getFont()); CGnuPlotFill fill(plot); //--- CBBox2D rbbox = (key->isOutside() ? group->getRegionBBox() : renderer->range()); //--- CFontPtr font = renderer->getFont(); double font_size = font->getCharAscent() + font->getCharDescent(); double pw = renderer->pixelWidthToWindowWidth (1); double ph = renderer->pixelHeightToWindowHeight(1); double bx = 8*pw; double by = 8*ph; double bw = font_size - 2; CSize2D size; double textWidth = 0.0, textHeight = 0.0; std::string header; if (key->hasTitle()) { header = key->title(); if (header != "") textHeight += font_size*ph; } NameValueColors values = nameValueColors(plot, value->palette(), value->alpha()); for (const auto &v : values) { std::string label = v.first; textWidth = std::max(textWidth, font->getStringWidth(label)*pw); textHeight += font_size*ph; } size = CSize2D(textWidth + bw*pw + 3*bx, textHeight + 2*by); CHAlignType halign = key->getHAlign(); CVAlignType valign = key->getVAlign(); double x1 = 0, y1 = 0; if (halign == CHALIGN_TYPE_LEFT) x1 = rbbox.getLeft () + bx; else if (halign == CHALIGN_TYPE_RIGHT) x1 = rbbox.getRight() - bx - size.getWidth(); else if (halign == CHALIGN_TYPE_CENTER) x1 = rbbox.getXMid() - size.getWidth()/2; if (valign == CVALIGN_TYPE_TOP) y1 = rbbox.getTop () - by - size.getHeight(); else if (valign == CVALIGN_TYPE_BOTTOM) y1 = rbbox.getBottom() + by; else if (valign == CVALIGN_TYPE_CENTER) y1 = rbbox.getYMid() - size.getHeight()/2; double x2 = x1 + size.getWidth (); double y2 = y1 + size.getHeight(); CBBox2D bbox(x1, y1, x2, y2); if (key->getFillBox()) { renderer->fillRect(bbox, fill.background()); } if (key->getDrawBox()) { CRGBA c(0, 0, 0); if (key->hasLineType()) c = CGnuPlotStyleInst->indexColor(key->getLineType()); renderer->drawRect(bbox, c, 1); } double y = y2 - by; if (header != "") { renderer->drawHAlignedText(CPoint2D((x1 + x2)/2, y), HAlignPos(CHALIGN_TYPE_CENTER, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), header, CRGBA(0,0,0)); y -= font_size*ph; } if (! renderer->isPseudo()) plot->updatePieCacheSize(values.size()); int pi = 0; for (const auto &v : values) { CGnuPlotPieObject *pieObject = 0; if (! renderer->isPseudo()) pieObject = plot->pieObjects()[pi]; //--- const std::string &name = v .first; const ValueColor &vc = v .second; const LineFillColor &lfc = vc.second; double xx = (key->isReverse() ? x1 + bx : x2 - bw*pw - bx); double yy = y - font_size*ph/2; CPoint2D p1(xx, yy - bw*ph/2), p2(xx + bw*pw, yy + bw*ph/2); CBBox2D bbox(p1, p2); renderer->fillEllipse(bbox, lfc.second); renderer->drawEllipse(bbox, lfc.first, 1); //double lw = font->getStringWidth(name); CRGBA tc = CRGBA(0,0,0); if (key->isReverse()) renderer->drawHAlignedText(CPoint2D(xx + bw*pw + bx, y), HAlignPos(CHALIGN_TYPE_LEFT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc); else renderer->drawHAlignedText(CPoint2D(xx - bx, y), HAlignPos(CHALIGN_TYPE_RIGHT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc); if (pieObject) { CBBox2D keyRect(x1, y - font_size*ph, x2, y); pieObject->setKeyRect(keyRect); //renderer->drawRect(keyRect, lfc.second, 1); } y -= font_size*ph; ++pi; } }