Commit 0fbc1e53 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

ENH: Added mouse interactivity and rescaling to the XY chart classes.

parent 59c61802
......@@ -54,18 +54,19 @@ private:
};
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkChart, "1.3");
vtkCxxRevisionMacro(vtkChart, "1.4");
vtkCxxSetObjectMacro(vtkChart, AnnotationLink, vtkAnnotationLink);
//-----------------------------------------------------------------------------
vtkChart::vtkChart()
{
int i=0;
while(i<6)
{
this->Geometry[i]=0;
++i;
}
this->Geometry[0] = 0;
this->Geometry[1] = 0;
this->Point1[0] = 0;
this->Point1[1] = 0;
this->Point2[0] = 0;
this->Point2[1] = 0;
this->Observer = vtkChart::Command::New();
this->Observer->SetTarget(this);
this->AnnotationLink = NULL;
......@@ -89,6 +90,43 @@ vtkIdType vtkChart::GetNumberPlots()
return 0;
}
//-----------------------------------------------------------------------------
void vtkChart::SetBottomBorder(int border)
{
this->Point1[1] = border >= 0 ? border : 0;
}
//-----------------------------------------------------------------------------
void vtkChart::SetTopBorder(int border)
{
this->Point2[1] = border >=0 ?
this->Geometry[1] - border :
this->Geometry[1];
}
//-----------------------------------------------------------------------------
void vtkChart::SetLeftBorder(int border)
{
this->Point1[0] = border >= 0 ? border : 0;
}
//-----------------------------------------------------------------------------
void vtkChart::SetRightBorder(int border)
{
this->Point2[0] = border >=0 ?
this->Geometry[0] - border :
this->Geometry[0];
}
//-----------------------------------------------------------------------------
void vtkChart::SetBorders(int left, int right, int top, int bottom)
{
this->SetLeftBorder(left);
this->SetRightBorder(right);
this->SetTopBorder(top);
this->SetBottomBorder(bottom);
}
//-----------------------------------------------------------------------------
void vtkChart::AddInteractorStyle(vtkInteractorStyle *interactor)
{
......
......@@ -68,11 +68,30 @@ public:
vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
// Description:
// This function allows you to set the overall dimensions of the chart.
// An int pointer of length 6 is expected with the dimensions in the order of
// width, height, left border, bottom border, right border, top border in
// pixels of the device. Initial value is (0,0,0,0,0,0).
vtkSetVector6Macro(Geometry, int);
// Set/get the width and the height of the chart.
vtkSetVector2Macro(Geometry, int);
vtkGetVector2Macro(Geometry, int);
// Description:
// Set/get the first point in the chart (the bottom left).
vtkSetVector2Macro(Point1, int);
vtkGetVector2Macro(Point1, int);
// Description:
// Set/get the second point in the chart (the top right).
vtkSetVector2Macro(Point2, int);
vtkGetVector2Macro(Point2, int);
// Description:
// Set/get the borders of the chart (space in pixels around the chart).
void SetBottomBorder(int border);
void SetTopBorder(int border);
void SetLeftBorder(int border);
void SetRightBorder(int border);
// Description:
// Set/get the borders of the chart (space in pixels around the chart).
void SetBorders(int left, int right, int top, int bottom);
// Description:
// Add the chart as an observer on the supplied interaction style.
......@@ -96,11 +115,17 @@ protected:
// Our annotation link, used for sharing selections etc.
vtkAnnotationLink *AnnotationLink;
// Store the chart dimensions packed into a vtkPoints2D
// [0] = width, height of chart in screen coordinates
// [1] = left border, bottom border (roughly - origin of the chart
// [2] = right border, top border (offset from top right most point)
int Geometry[6];
// Description:
// The width and the height of the chart.
int Geometry[2];
// Description:
// The position of the lower left corner of the chart.
int Point1[2];
// Description:
// The position of the upper right corner of the chart.
int Point2[2];
// Description:
// The command object for the charts.
......
This diff is collapsed.
......@@ -57,19 +57,69 @@ public:
//ETX
virtual vtkIdType GetNumberPlots();
// Description:
// Return true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse enter event.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse leave event.
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button down event
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button release event.
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse wheel event, positive delta indicates forward movement of the wheel.
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta);
//BTX
protected:
vtkChartXY();
~vtkChartXY();
// Description:
// Recalculate the plot area transform to fit in all points that will be
// plotted.
void RecalculatePlotTransform();
// Description:
// Calculate the optimal zoom level such that all of the points to be plotted
// will fit into the plot area.
void RecalculatePlotBounds();
// Description:
// Process a rubber band selection event.
virtual void ProcessSelectionEvent(vtkObject* caller, void* callData);
// Description:
// The X and Y axes for the chart
vtkAxis *XAxis, *YAxis;
// Description:
// The grid for the chart.
vtkPlotGrid *Grid;
// Description:
// The 2D transform for the series drawn in the plot area
vtkTransform2D *PlotTransform;
// Description:
// Does the plot area transform need to be recalculated?
bool PlotTransformValid;
private:
vtkChartXY(const vtkChartXY &); // Not implemented.
void operator=(const vtkChartXY &); // Not implemented.
......
......@@ -27,7 +27,7 @@
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkContextView, "1.2");
vtkCxxRevisionMacro(vtkContextView, "1.3");
vtkStandardNewMacro(vtkContextView);
vtkCxxSetObjectMacro(vtkContextView, Context, vtkContext2D);
......@@ -70,7 +70,6 @@ vtkContextView::~vtkContextView()
// The scene is owned by the context actor
if (this->Scene)
{
this->Scene->SetWindow(NULL);
this->Scene->Delete();
this->Scene = NULL;
}
......
......@@ -23,7 +23,7 @@
#include "vtkStdString.h"
vtkCxxRevisionMacro(vtkPlot, "1.3");
vtkCxxRevisionMacro(vtkPlot, "1.4");
vtkCxxSetObjectMacro(vtkPlot, Selection, vtkIdTypeArray);
//-----------------------------------------------------------------------------
......@@ -33,7 +33,7 @@ vtkPlot::vtkPlot()
this->Color[1] = 0;
this->Color[2] = 0;
this->Color[3] = 255;
this->Width = 1.0;
this->Width = 2.0;
this->Data = vtkContextMapper2D::New();
this->Selection = NULL;
}
......
......@@ -71,6 +71,8 @@ public:
virtual void SetSelection(vtkIdTypeArray *id);
virtual void GetBounds(double bounds[4]) { vtkNotUsed(bounds); }
//BTX
// Description:
// A General setter/getter that should be overridden. It can silently drop
......
......@@ -30,7 +30,7 @@
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkPlotLine, "1.3");
vtkCxxRevisionMacro(vtkPlotLine, "1.4");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotLine);
......@@ -186,8 +186,14 @@ bool vtkPlotLine::UpdateTableCache(vtkTable *table)
else
{
vtkErrorMacro(<< "Error the x or y array was not a valid type."
<< endl << x->GetClassName()
<< "\t" << y->GetClassName());
<< endl
<< x->GetClassName() << "\tT=" << x->GetNumberOfTuples()
<< "\tC=" << x->GetNumberOfComponents()
<< endl
<< y->GetClassName() << "\tT=" << y->GetNumberOfTuples()
<< "\tC=" << y->GetNumberOfComponents());
// Give a little more information about them
vtkErrorMacro(<<"Table: " << table->GetNumberOfColumns())
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment