Generalized the axis drawing code. All four sides of the chart area are

supported, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30524 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-04-30 22:52:59 +00:00
parent d7c160d3e6
commit b8c273de21
@@ -215,52 +215,98 @@ printf("LegendChartAxis::Render()\n");
if (!_ValidateLayout(view)) if (!_ValidateLayout(view))
return; return;
if (fLocation == CHART_AXIS_BOTTOM) { float valueDirection;
float rulerDirection;
float BSize::* sizeField;
float BSize::* otherSizeField;
float BPoint::* pointField;
float BPoint::* otherPointField;
switch (fLocation) {
case CHART_AXIS_LEFT:
case CHART_AXIS_RIGHT:
valueDirection = -1;
rulerDirection = fLocation == CHART_AXIS_LEFT ? -1 : 1;
sizeField = &BSize::height;
otherSizeField = &BSize::width;
pointField = &BPoint::y;
otherPointField = &BPoint::x;
break;
case CHART_AXIS_TOP:
case CHART_AXIS_BOTTOM:
valueDirection = 1;
rulerDirection = fLocation == CHART_AXIS_TOP ? -1 : 1;
sizeField = &BSize::width;
otherSizeField = &BSize::height;
pointField = &BPoint::x;
otherPointField = &BPoint::y;
break;
default:
return;
}
printf(" rendering...\n"); printf(" rendering...\n");
float totalSize = floorf(fFrame.Width()) + 1; float totalSize = floorf(fFrame.Size().*sizeField) + 1;
double rangeSize = fRange.max - fRange.min; double rangeSize = fRange.max - fRange.min;
if (rangeSize == 0) if (rangeSize == 0)
rangeSize = 1.0; rangeSize = 1.0;
double scale = (double)totalSize / rangeSize; double scale = (double)totalSize / rangeSize;
float BSize::* sizeField = &BSize::width;
// draw the ruler // draw the ruler
float rulerLeft = fFrame.left; float rulerStart = fFrame.LeftBottom().*pointField;
float rulerTop = fFrame.top + kChartRulerDistance; float rulerChartClosest = rulerDirection == 1
float rulerRight = fFrame.right; ? fFrame.LeftTop().*otherPointField + kChartRulerDistance
float rulerBottom = rulerTop + kRulerSize; : fFrame.RightBottom().*otherPointField - kChartRulerDistance;
printf(" ruler: (%f, %f) - (%f, %f)\n", rulerLeft, rulerTop, rulerRight, rulerBottom); float rulerEnd = fFrame.RightTop().*pointField;
float rulerChartDistant = rulerChartClosest + rulerDirection * kRulerSize;
printf(" ruler: (%f, %f) - (%f, %f)\n", rulerStart, rulerChartClosest, rulerEnd, rulerChartDistant);
rgb_color black = { 0, 0, 0, 255 }; rgb_color black = { 0, 0, 0, 255 };
view->BeginLineArray(3 + fLegends.CountItems()); view->BeginLineArray(3 + fLegends.CountItems());
view->AddLine(BPoint(rulerLeft, rulerTop), BPoint first;
BPoint(rulerLeft, rulerBottom), black); first.*pointField = rulerStart;
view->AddLine(BPoint(rulerLeft, rulerBottom), first.*otherPointField = rulerChartClosest;
BPoint(rulerRight, rulerBottom), black); BPoint second = first;
view->AddLine(BPoint(rulerRight, rulerBottom), second.*otherPointField = rulerChartDistant;
BPoint(rulerRight, rulerTop), black); BPoint third = second;
third.*pointField = rulerEnd;
BPoint fourth = third;
fourth.*otherPointField = rulerChartClosest;
view->AddLine(first, second, black);
view->AddLine(second, third, black);
view->AddLine(third, fourth, black);
// marks // marks
for (int32 i = 0; LegendInfo* info = fLegends.ItemAt(i); i++) { for (int32 i = 0; LegendInfo* info = fLegends.ItemAt(i); i++) {
float position = (info->value - fRange.min) * scale; float position = (info->value - fRange.min) * scale;
position += rulerLeft; position = rulerStart + valueDirection * position;
printf(" drawing mark at (%f, %f)\n", position, rulerBottom); first.*pointField = position;
view->AddLine(BPoint(position, rulerBottom), first.*otherPointField = rulerChartDistant;
BPoint(position, rulerBottom + kRulerMarkSize), black); second.*pointField = position;
} second.*otherPointField = rulerChartDistant
view->EndLineArray(); + rulerDirection * kRulerMarkSize;
printf(" drawing mark at (%f, %f)\n", first.x, first.y);
view->AddLine(first, second, black);
}
view->EndLineArray();
// draw the legends // draw the legends
float legendTop = rulerBottom + kRulerMarkSize + kRulerLegendDistance; float legendRulerClosest = rulerChartDistant
+ rulerDirection * (kRulerMarkSize + kRulerLegendDistance);
for (int32 i = 0; LegendInfo* info = fLegends.ItemAt(i); i++) { for (int32 i = 0; LegendInfo* info = fLegends.ItemAt(i); i++) {
float position = _LegendPosition(info->value, info->size.*sizeField, float position = _LegendPosition(info->value, info->size.*sizeField,
(float)totalSize, scale);; (float)totalSize, scale);;
printf(" legend %ld: position: (%f, %f), size: (%f, %f)\n", i, position, legendTop, info->size.width, info->size.height);
fLegendRenderer->RenderLegend(info->legend, view, first.*pointField = rulerStart
BPoint(rulerLeft + position, legendTop)); + (valueDirection == 1
} ? position : -position - info->size.*sizeField);
first.*otherPointField = rulerDirection == 1
? legendRulerClosest
: legendRulerClosest - info->size.*otherSizeField;
printf(" legend %ld: position: (%f, %f), size: (%f, %f)\n", i, first.x, first.y, info->size.width, info->size.height);
fLegendRenderer->RenderLegend(info->legend, view, first);
} }
} }