Пример #1
0
/*!
  \brief Draw dots
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::drawPolyline, QwtCurve::drawLine, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps
      QwtCurve::drawPolyline, QwtCurve::drawPolygon
*/
void QwtCurve::drawDots(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    const bool doFill = painter->brush().style() != Qt::NoBrush;

    QPointArray polyline;
    if ( doFill )
        polyline.resize(to - from + 1);

    for (int i = from; i <= to; i++)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));
        QwtPainter::drawPoint(painter, xi, yi);

        if ( doFill )
            polyline.setPoint(i - from, xi, yi);
    }

    if ( doFill )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
Пример #2
0
/*!
  \brief Draw step function
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSticks
*/
void QwtCurve::drawSteps(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    QPointArray polyline(2 * (to - from) + 1);

    bool inverted = d_options & Yfx;
    if ( d_options & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline.setPoint(ip - 1, polyline[ip-2].x(), yi);
            else
                polyline.setPoint(ip - 1, xi, polyline[ip-2].y());
        }

        polyline.setPoint(ip, xi, yi);
    }

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
/*!
    Translate a point from plot into pixel coordinates
    \return Point in pixel coordinates
    \sa QwtPlotPicker::invTransform()
*/
QPoint QwtPlotPicker::transform(const QwtDoublePoint &pos) const
{
    QwtDiMap xMap = plot()->canvasMap(d_xAxis);
    QwtDiMap yMap = plot()->canvasMap(d_yAxis);

    return QPoint(
        xMap.transform(pos.x()),
        yMap.transform(pos.y())
    );
}
/*!
    Translate a rectangle from plot into pixel coordinates
    \return Rectangle in pixel coordinates
    \sa QwtPlotPicker::invTransform()
*/
QRect QwtPlotPicker::transform(const QwtDoubleRect &rect) const
{
    QwtDiMap xMap = plot()->canvasMap(d_xAxis);
    QwtDiMap yMap = plot()->canvasMap(d_yAxis);

    const int x1 = xMap.transform(rect.x1());
    const int x2 = xMap.transform(rect.x2());
    const int y1 = yMap.transform(rect.y1());
    const int y2 = yMap.transform(rect.y2());

    return QRect(x1, y1, x2 - x1, y2 - y1);
}
Пример #5
0
/*!
  \brief Draw sticks
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps
*/
void QwtCurve::drawSticks(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    int x0 = xMap.transform(d_ref);
    int y0 = yMap.transform(d_ref);

    for (int i = from; i <= to; i++)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));

        if (d_options & Xfy)
            QwtPainter::drawLine(painter, x0, yi, xi, yi);
        else
            QwtPainter::drawLine(painter, xi, y0, xi, yi);
    }
}
Пример #6
0
/*!
  \brief Draw symbols
  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
*/
void QwtCurve::drawSymbols(QPainter *painter, QwtSymbol &symbol,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    painter->setBrush(symbol.brush());
    painter->setPen(symbol.pen());

    QRect rect;
    rect.setSize(QwtPainter::metricsMap().screenToLayout(symbol.size()));

    for (int i = from; i <= to; i++)
    {
        const int xi = xMap.transform(x(i));
        const int yi = yMap.transform(y(i));

        rect.moveCenter(QPoint(xi, yi));
        symbol.draw(painter, rect);
    }
}
Пример #7
0
void QwtCurve::closePolyline(const QwtDiMap &xMap, const QwtDiMap &yMap,
    QPointArray &pa) const
{
    const int sz = pa.size();
    if ( sz < 2 )
        return;

    pa.resize(sz + 2);

    if ( d_options & QwtCurve::Xfy )
    {
        pa.setPoint(sz,
            xMap.transform(d_ref), pa.point(sz - 1).y());
        pa.setPoint(sz + 1,
            xMap.transform(d_ref), pa.point(0).y());
    }
    else
    {
        pa.setPoint(sz,
            pa.point(sz - 1).x(), yMap.transform(d_ref));
        pa.setPoint(pa.size() - 1,
            pa.point(0).x(), yMap.transform(d_ref));
    }
}
Пример #8
0
void BoxCurve::drawSymbols(QPainter *painter, const QwtDiMap &xMap, const QwtDiMap &yMap, double *dat, int size)
{
const int px = xMap.transform(x(0));

QwtSymbol s = this->symbol();
if (min_style != QwtSymbol::None)
	{
	const int py_min = yMap.transform(y(0));
	s.setStyle(min_style);
	s.draw(painter, px, py_min);
	}
if (max_style != QwtSymbol::None)
	{
	const int py_max = yMap.transform(y(size - 1));
	s.setStyle(max_style);
	s.draw(painter, px, py_max);
	}
if (p1_style != QwtSymbol::None)
	{
	const int p1 = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.01));
	s.setStyle(p1_style);
	s.draw(painter, px, p1);
	}
if (p99_style != QwtSymbol::None)
	{
	const int p99 = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.99));
	s.setStyle(p99_style);
	s.draw(painter, px, p99);
	}
if (mean_style != QwtSymbol::None)
	{
	const int mean = yMap.transform(gsl_stats_mean(dat, 1, size));
	s.setStyle(mean_style);
	s.draw(painter, px, mean);
	}
}
Пример #9
0
void BoxCurve::drawBox(QPainter *painter, const QwtDiMap &xMap, const QwtDiMap &yMap, double *dat, int size)
{
const int px = xMap.transform(x(0));
const int px_min = xMap.transform(x(0) - 0.5);
const int px_max = xMap.transform(x(0) + 0.5);
const int box_width = 1+(px_max - px_min)*b_width/100;
const int hbw = box_width/2;
const int median = yMap.transform(gsl_stats_median_from_sorted_data (dat, 1, size));
int b_lowerq, b_upperq;
double sd, se, mean;
if(w_range == SD || w_range == SE || b_range == SD || b_range == SE)
	{
	sd = gsl_stats_sd(dat, 1, size);
	se = sd/sqrt((double)size);
	mean = gsl_stats_mean(dat, 1, size);
	}

if(b_range == SD)
	{
	b_lowerq = yMap.transform(mean - sd*b_coeff);
	b_upperq = yMap.transform(mean + sd*b_coeff);
	}
else if(b_range == SE)
	{
	b_lowerq = yMap.transform(mean - se*b_coeff);
	b_upperq = yMap.transform(mean + se*b_coeff);
	}
else
	{
	b_lowerq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 1-0.01*b_coeff));
	b_upperq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.01*b_coeff));
	}

//draw box
if (b_style == Rect)
	{
	const QRect r = QRect(px - hbw, b_upperq, box_width, b_lowerq - b_upperq + 1);
	painter->fillRect(r, QwtPlotCurve::brush());
	painter->drawRect(r);
	}
else if (b_style == Diamond)
	{
	const QPointArray pa(4);	
	pa[0] = QPoint(px, b_upperq);	
	pa[1] = QPoint(px + hbw, median);
	pa[2] = QPoint(px, b_lowerq);
	pa[3] = QPoint(px - hbw, median);

	painter->setBrush(QwtPlotCurve::brush());
	painter->drawPolygon(pa);
	}
else if (b_style == WindBox)
	{
	const int lowerq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.25));
	const int upperq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.75));
	const QPointArray pa(8);	
	pa[0] = QPoint(px + hbw, b_upperq);	
	pa[1] = QPoint(int(px + 0.4*box_width), upperq);
	pa[2] = QPoint(int(px + 0.4*box_width), lowerq);
	pa[3] = QPoint(px + hbw, b_lowerq);
	pa[4] = QPoint(px - hbw, b_lowerq);
	pa[5] = QPoint(int(px - 0.4*box_width), lowerq);
	pa[6] = QPoint(int(px - 0.4*box_width), upperq);
	pa[7] = QPoint(px - hbw, b_upperq);	

	painter->setBrush(QwtPlotCurve::brush());
	painter->drawPolygon(pa);
	}
else if (b_style == Notch)
	{
	int j = (int)ceil(0.5*(size - 1.96*sqrt((double)size)));
	int k = (int)ceil(0.5*(size + 1.96*sqrt((double)size)));
	const int lowerCI = yMap.transform(dat[j]);
	const int upperCI = yMap.transform(dat[k]);

	const QPointArray pa(10);	
	pa[0] = QPoint(px + hbw, b_upperq);	
	pa[1] = QPoint(px + hbw, upperCI);
	pa[2] = QPoint(int(px + 0.25*hbw), median);
	pa[3] = QPoint(px + hbw, lowerCI);
	pa[4] = QPoint(px + hbw, b_lowerq);
	pa[5] = QPoint(px - hbw, b_lowerq);
	pa[6] = QPoint(px - hbw, lowerCI);
	pa[7] = QPoint(int(px - 0.25*hbw), median);
	pa[8] = QPoint(px - hbw, upperCI);
	pa[9] = QPoint(px - hbw, b_upperq);	

	painter->setBrush(QwtPlotCurve::brush());
	painter->drawPolygon(pa);
	}

if (w_range)
	{//draw whiskers
	const int l = int(0.1*box_width);
	int w_upperq, w_lowerq;
	if(w_range == SD)
		{
		w_lowerq = yMap.transform(mean - sd*w_coeff);
		w_upperq = yMap.transform(mean + sd*w_coeff);
		}
	else if(w_range == SE)
		{
		w_lowerq = yMap.transform(mean - se*w_coeff);
		w_upperq = yMap.transform(mean + se*w_coeff);
		}
	else
		{
		w_lowerq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 1-0.01*w_coeff));
		w_upperq = yMap.transform(gsl_stats_quantile_from_sorted_data (dat, 1, size, 0.01*w_coeff));
		}

	painter->drawLine(px - l, w_lowerq, px + l, w_lowerq);
	painter->drawLine(px - l, w_upperq, px + l, w_upperq);

	if (b_style)
		{
		if (w_upperq != b_upperq)
			painter->drawLine(px, w_upperq, px, b_upperq);
		if (w_lowerq != b_lowerq)
			painter->drawLine(px, w_lowerq, px, b_lowerq);
		}
	else
		painter->drawLine(px, w_upperq, px, w_lowerq);
	}

//draw median line
if (b_style == Notch || b_style == NoBox)
	return;
if (b_style == WindBox)
	painter->drawLine(int(px - 0.4*box_width), median, int(px + 0.4*box_width), median);
else
	painter->drawLine(px - hbw, median, px + hbw, median);
}
Пример #10
0
void QwtBarCurve::draw(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
   if ( !painter || dataSize() <= 0 )
        return;

    if (to < 0)
        to = dataSize() - 1;

    if ( verifyRange(from, to) > 0 )
		{
        painter->save();
        painter->setPen(QwtPlotCurve::pen());
        painter->setBrush(QwtPlotCurve::brush());
			
		int dx,dy,ref,bar_width;
			
		if (bar_style == Vertical)
			ref= yMap.transform(1e-100); //smalest positive value for log scales
		else
			ref= xMap.transform(1e-100);	
				
		int i;
		if (bar_style == Vertical)
			{
			dx = abs(xMap.transform(x(from+1))-xMap.transform(x(from)));
			for (i=from+2; i<to; i++)
				{
				int min = abs(xMap.transform(x(i+1))-xMap.transform(x(i)));
				if (min <= dx)
					dx=min;
				}
			bar_width=int(dx*(1-bar_gap*0.01));
			}
		else
			{
			dy = abs(yMap.transform(y(from+1))-yMap.transform(y(from)));
			for (i=from+2; i<to; i++)
				{
				int min = abs(yMap.transform(y(i+1))-yMap.transform(y(i)));
				if (min <= dy)
					dy=min;
				}
			bar_width=int(dy*(1-bar_gap*0.01));
			}
		
		const int half_width = int((0.5-bar_offset*0.01)*bar_width);
		const int bw1 = bar_width+1;
        for (i=from; i<=to; i++)
			{
            const int px = xMap.transform(x(i));
            const int py = yMap.transform(y(i));
			
			if (bar_style == Vertical)
				{
				if (y(i) < 0)
					painter->drawRect(px-half_width, ref, bw1, (py-ref));
				else
					painter->drawRect(px-half_width, py, bw1, (ref-py+1));	
				}
			else
				{
				if (x(i) < 0)
					painter->drawRect(px, py-half_width, (ref-px), bw1);
				else
					painter->drawRect(ref, py-half_width,(px-ref), bw1);
				}	
			}
		painter->restore();
		}
}
Пример #11
0
void Plot::drawInwardMinorTicks(QPainter *painter, const QRect &rect,
                                const QwtDiMap &map, int axis) const
{
    QwtScale *scale=(QwtScale *) QwtPlot::axis (axis);
    if (!scale)
        return;

    int x1=rect.left();
    int x2=rect.right();
    int y1=rect.top();
    int y2=rect.bottom();

    QPalette pal=scale->palette();
    QColor color=pal.color(QPalette::Active, QColorGroup::Foreground);

    painter->save();
    painter->setPen(QPen(color, d_lineWidth, QPainter::SolidLine));

    QwtScaleDiv *scDiv=(QwtScaleDiv *)axisScale(axis);
    int minTicks=scDiv->minCnt();

    int j, x, y, low,high;
    switch (axis)
    {
    case QwtPlot::yLeft:
        x=x1;
        low=y1+majTickLength;
        high=y2-majTickLength;
        for (j = 0; j < minTicks; j++)
        {
            y = map.transform(scDiv->minMark(j));
            if (y>low && y< high)
                QwtPainter::drawLine(painter, x, y, x+minTickLength, y);
        }
        break;

    case QwtPlot::yRight:
    {
        x=x2;
        low=y1+majTickLength;
        high=y2-majTickLength;
        for (j = 0; j < minTicks; j++)
        {
            y = map.transform(scDiv->minMark(j));
            if (y>low && y< high)
                QwtPainter::drawLine(painter, x+1, y, x-minTickLength, y);
        }
    }
    break;

    case QwtPlot::xBottom:
        y=y2;
        low=x1+majTickLength;
        high=x2-majTickLength;
        for (j = 0; j < minTicks; j++)
        {
            x = map.transform(scDiv->minMark(j));
            if (x>low && x<high)
                QwtPainter::drawLine(painter, x, y+1, x, y-minTickLength);
        }
        break;

    case QwtPlot::xTop:
        y=y1;
        low=x1+majTickLength;
        high=x2-majTickLength;
        for (j = 0; j < minTicks; j++)
        {
            x = map.transform(scDiv->minMark(j));
            if (x>low && x<high)
                QwtPainter::drawLine(painter, x, y, x, y + minTickLength);
        }
        break;
    }
    painter->restore();
}