// $Revision: 1.5 $ // AxisDrawer.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_AXISDRAWER #include "AxisDrawer.h" #endif #ifndef TaligentSamples_STANDARDGRAPH #include "StandardGraph.h" #endif //============================================================================== // TAxisDrawer TaligentTypeExtensionMacro(TAxisDrawer); TAxisDrawer::TAxisDrawer() : TGraphDrawer(), fAxisColor(0., 0., 0.), fXAxisLocation(0.) { } TAxisDrawer::TAxisDrawer(GraphValue xAxisLocation) : TGraphDrawer(), fAxisColor(0., 0., 0.), fXAxisLocation(xAxisLocation) { } TAxisDrawer::TAxisDrawer(const TAxisDrawer& source) : TGraphDrawer(source), fAxisColor(source.fAxisColor), fXAxisLocation(source.fXAxisLocation) { } TAxisDrawer::~TAxisDrawer() { } TAxisDrawer& TAxisDrawer::operator=(const TAxisDrawer& source) { if(&source != this) { TGraphDrawer::operator=(source); fAxisColor = source.fAxisColor; fXAxisLocation = source.fXAxisLocation; } return *this; } TStream& TAxisDrawer::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TGraphDrawer::operator>>=(toStream); fAxisColor >>= toStream; fXAxisLocation >>= toStream; return toStream; } TStream& TAxisDrawer::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TGraphDrawer::operator<<=(fromStream); fAxisColor <<= fromStream; fXAxisLocation <<= fromStream; return fromStream; } const TRGBColor& TAxisDrawer::GetAxisColor() const { return fAxisColor; } GraphValue TAxisDrawer::GetXAxisLocation() const { return fXAxisLocation; } void TAxisDrawer::SetAxisColor(const TRGBColor& color) { fAxisColor = color; } void TAxisDrawer::SetXAxisLocation(GraphValue xAxisLocation) { fXAxisLocation = xAxisLocation; } void TAxisDrawer::DrawIntoGraph(TGrafPort& port) const { TLine line(TGLine(), new TGrafBundle(GetAxisColor())); const TStandardGraph& graph = GetTargetGraph(); GraphValue minXValue = graph.GetXRange().GetMin(); GraphValue maxXValue = graph.GetXRange().GetMax(); GraphValue minYValue = graph.GetYRange().GetMin(); GraphValue maxYValue = graph.GetYRange().GetMax(); // Draw the x-axis. line.SetStartPoint(graph.MapValuesToPoint(minXValue, GetXAxisLocation())); line.SetEndPoint(graph.MapValuesToPoint(maxXValue, GetXAxisLocation())); line.Draw(port); // Draw the y-axis. line.SetStartPoint(graph.MapValuesToPoint(minXValue, minYValue)); line.SetEndPoint(graph.MapValuesToPoint(minXValue, maxYValue)); line.Draw(port); } TGRect TAxisDrawer::GetBounds() const { TGRect totalBounds(TGRect::kZeroRect); const TStandardGraph& graph = GetTargetGraph(); if (GetXAxisLocation() > graph.GetYRange().GetMax()) { totalBounds.SetTopLeft(graph.MapValuesToPoint(graph.GetXRange().GetMin(), GetXAxisLocation())); totalBounds.SetBottomRight(graph.MapValuesToPoint(graph.GetXRange().GetMax(), graph.GetYRange().GetMin())); } else if (GetXAxisLocation() < graph.GetYRange().GetMin()) { totalBounds.SetTopLeft(graph.MapValuesToPoint(graph.GetXRange().GetMin(), graph.GetYRange().GetMax())); totalBounds.SetBottomRight(graph.MapValuesToPoint(graph.GetXRange().GetMax(), GetXAxisLocation())); } else { totalBounds.SetTopLeft(graph.MapValuesToPoint(graph.GetXRange().GetMin(), graph.GetYRange().GetMax())); totalBounds.SetBottomRight(graph.MapValuesToPoint(graph.GetXRange().GetMax(), graph.GetYRange().GetMin())); } return totalBounds; }