Example #1
0
    Range Range::Intersect(const Range& range) const
    {
        size_t min = std::max(GetMin(), range.GetMin());
        size_t max = std::min(GetMax(), range.GetMax());

        if(min >= max) // No intersection.
        {
            return InvalidRange();
        }

        return Range(min, max);
    }
Example #2
0
 bool Range::Contains(const Range& range) const
 {
     return IsValid() && range.IsValid() &&
         GetMin()<=range.GetMin() && range.GetMax()<=GetMax();
 }
Example #3
0
 bool Range::Intersects(const Range& range) const
 {
     return IsValid() && range.IsValid() &&
         !(range.GetMax()<GetMin() || range.GetMin()>=GetMax());
 }
Example #4
0
 bool Range::EqualsIgnoringDirection(const Range& other) const
 {
     return GetMin()==other.GetMin() && GetMax()==other.GetMax();
 }
Example #5
0
int LineChart::DrawScale(wxMemoryDC &dc){
	int leftOrientationEdge = 0;
	int rightOrientationEdge = _currentWidth - 1;

	int scaleOrientation = LineChart::ORIENTATION_LEFT;

	wxFont labelFont = GetFont();



	int tickLabelWidth = 0;
	for (SeriesMap::iterator it = m_seriesMap.begin(); it != m_seriesMap.end(); ++it){

		int maxLabelWidth = 0;
		Series *series = it->second;
		Range * range = m_rangeArray[series->GetRangeId()];


		double minValue = range->GetMin();
		double maxValue = range->GetMax();
		double rangeSize = maxValue - minValue;
		double stepInterval = (maxValue - minValue) / 10;
		if (stepInterval == 0) stepInterval = 1;

		dc.SetPen(*wxThePenList->FindOrCreatePen(series->GetColor(), 1, wxSOLID));

		dc.SetTextForeground(series->GetColor());

		bool labelOn = false;
		int tickLabelHeight,tickDescent,tickExternalLeading;
		dc.DrawLine(leftOrientationEdge, 0, leftOrientationEdge, _currentHeight);

		for (double tick = minValue; tick <=maxValue; tick += stepInterval){

			int y = _currentHeight - (double)_currentHeight * ((tick - minValue) / rangeSize);
			int nextY = _currentHeight - (double)_currentHeight * ((tick + stepInterval - minValue) / rangeSize);

			if (labelOn){
				wxString numberFormat = "%." + wxString::Format("%df", range->GetPrecision());
				wxString tickLabel = wxString::Format(numberFormat, tick);
				dc.GetTextExtent(tickLabel, &tickLabelHeight, &tickLabelWidth, &tickDescent, &tickExternalLeading, &labelFont);
				if (tickLabelHeight > maxLabelWidth) maxLabelWidth = tickLabelHeight;

				if (tickLabelWidth < y - nextY ){
					switch (scaleOrientation){
						case LineChart::ORIENTATION_LEFT:
						{
							dc.DrawRotatedText(tickLabel, leftOrientationEdge, y, 0);
							break;
						}
						case LineChart::ORIENTATION_RIGHT:
						{
							dc.DrawRotatedText(tickLabel, rightOrientationEdge, y, 0);
							break;
						}
					}
				}
			}
			labelOn = !labelOn;
			dc.DrawLine(leftOrientationEdge, y, leftOrientationEdge + tickLabelWidth, y);
		}

		maxLabelWidth+=(tickLabelWidth / 2);
		switch (scaleOrientation){
			case LineChart::ORIENTATION_LEFT:
			{
				leftOrientationEdge += (maxLabelWidth);
				break;
			}
			case LineChart::ORIENTATION_RIGHT:
			{
				rightOrientationEdge -= (maxLabelWidth);
				break;
			}
		}
	}
	return leftOrientationEdge;
}
Example #6
0
void LineChart::OnPaint(wxPaintEvent &event){

	wxPaintDC old_dc(this);

	float zoomFactor = (float)_zoomPercentage / 100;

	int w,h ;
	GetClientSize(&w,&h);

	if (w != _currentWidth || h != _currentHeight){
		delete (_memBitmap);
		_currentWidth = w;
		_currentHeight = h;
		_memBitmap = new wxBitmap(_currentWidth, _currentHeight);
	}
	/////////////////
	// Create a memory DC
	wxMemoryDC dc;
	dc.SelectObject(*_memBitmap);

	wxColor backColor = GetBackgroundColour();
	dc.SetBackground(*wxTheBrushList->FindOrCreateBrush(backColor,wxSOLID));
	dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(backColor,wxSOLID));
	dc.Clear();
	DrawGrid(dc);

	if (m_showScale){
		m_leftEdge = DrawScale(dc);
	}
	else{
		m_leftEdge = 0;
	}

	size_t largestBufferSize = GetMaxSeriesBufferSize();
	double lastValue = 0;
	for (SeriesMap::iterator it = m_seriesMap.begin(); it != m_seriesMap.end(); ++it){

		float currentX = (float)m_leftEdge;
		int lastX = (int)currentX;
		int lastY;

		Series *series = it->second;
		dc.SetPen(*wxThePenList->FindOrCreatePen(series->GetColor(), 1, wxSOLID));
		size_t bufSize = series->GetBufferSize();
		Range *range = m_rangeArray[series->GetRangeId()];
		if (bufSize > 0){

			double minValue = range->GetMin();
			double maxValue = range->GetMax();

			double loggedValue = series->GetValueAt(0);

			double percentageOfMax = (loggedValue - minValue) / (maxValue - minValue);
			lastY = h - (int)(((double)h) * percentageOfMax);

			size_t i = (size_t)(((double)largestBufferSize) * m_viewOffsetFactor);

			while (i < bufSize && currentX < _currentWidth ){
				if (i == m_markerIndex){
					wxPen pen = dc.GetPen();
					dc.SetPen(*wxThePenList->FindOrCreatePen(*wxLIGHT_GREY, 1, wxSOLID));
					dc.DrawLine(currentX, 0, currentX, _currentHeight);
					DrawCurrentValues(dc, i, currentX, CURRENT_VALUES_TOP_OFFSET);
					dc.SetPen(pen);
				}

				loggedValue = series->GetValueAt(i);

				if (DatalogValue::NULL_VALUE == loggedValue){
					loggedValue = lastValue;
				}
				else{
					lastValue = loggedValue;
				}

				double percentageOfMax = (loggedValue - minValue) / (maxValue - minValue);

				int y = h - (int)(((double)h) * percentageOfMax);

				dc.DrawLine(lastX, lastY, (int)currentX, y);
				lastX = (int)currentX;
				lastY = y;
				currentX += zoomFactor;
				i++;
			}
		}
	}
	if (m_showData) DrawMouseoverMarker(dc);
	//blit into the real DC
	old_dc.Blit(0,0,_currentWidth,_currentHeight,&dc,0,0);

}