Commit 7d73e565 authored by Shawn Waldon's avatar Shawn Waldon Committed by Kitware Robot

Merge topic 'sort-lineplot-data-by-x-axis'

88cad87b Add a test of sorting the line chart data by x-axis
9f7d433c Add option to sort data by x-axis for vtkPVXYChartView
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1280
parents b7301259 88cad87b
Pipeline #46004 pending with stage
......@@ -354,6 +354,7 @@ list(APPEND TESTS_WITH_BASELINES
${CMAKE_CURRENT_SOURCE_DIR}/SelectionLinkMultiple.xml
${CMAKE_CURRENT_SOURCE_DIR}/SelectionLinkRemove.xml
${CMAKE_CURRENT_SOURCE_DIR}/SelectionLinkReaction.xml
${CMAKE_CURRENT_SOURCE_DIR}/SortLineChartData.xml
${CMAKE_CURRENT_SOURCE_DIR}/StreamTracerSurface.xml
${CMAKE_CURRENT_SOURCE_DIR}/StockColors.xml
${CMAKE_CURRENT_SOURCE_DIR}/StreamTracerUpdates.xml
......@@ -664,6 +665,9 @@ SET (Flow2_THRESHOLD 15)
SET (UndoRedo1_THRESHOLD 15)
SET (UndoRedo4_THRESHOLD 15)
# Differnces between systems on whether the lines are anti-aliased or not
SET (SortLineChartData_THRESHOLD 50)
# Since often there are issues with fonts etc.
SET (XYChart_THRESHOLD 150)
SET (CheckableHeader_THRESHOLD 150)
......
<?xml version="1.0" ?>
<pqevents>
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuTools" />
<pqevent object="pqClientMainWindow/menubar/menuTools" command="activate" arguments="actionTesting_Window_Size" />
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuSources" />
<pqevent object="pqClientMainWindow/menubar/menuSources" command="activate" arguments="LineSource" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/InteractiveLine/point1X" command="set_string" arguments="0" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/InteractiveLine/point2X" command="set_string" arguments="10" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/InteractiveLine/point2X" command="set_string" arguments="10" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Resolution/LineEdit0" command="set_string" arguments="50" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/pqProxyGroupMenuManager0/Calculator" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/sin" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/LeftParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Scalars" command="activate" arguments="" />
<pqevent object="1QMenu0" command="activate" arguments="coordsX" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/RightParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/pqProxyGroupMenuManager0/Calculator" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/floor" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/LeftParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Function" command="set_string" arguments="floor(5" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Minus" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Scalars" command="activate" arguments="" />
<pqevent object="1QMenu0" command="activate" arguments="coordsX" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/LeftParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/RightParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Divide" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Function" command="set_string" arguments="floor((5-coordsX)/5" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/RightParentheses" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Multiply" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Function" command="set_string" arguments="floor((5-coordsX)/5)*1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Function" command="set_string" arguments="floor((5-coordsX)/5)*11" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Plus" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Function/Scalars" command="activate" arguments="" />
<pqevent object="1QMenu0" command="activate" arguments="coordsX" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ResultArrayName/ResultArrayName" command="set_string" arguments="Result2" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuFilters" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/Alphabetical" command="activate" arguments="PlotAttributes" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mousePress" arguments="(0.428937,0.463918,1,1,0)" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mouseMove" arguments="(0.428937,0.463918,1,0,0)" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mouseRelease" arguments="(0.428937,0.463918,1,0,0)" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/DisplayFrame/ProxyPanel/SeriesEditor/SeriesTable" command="setCheckState" arguments="2.0,0" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/DisplayFrame/ProxyPanel/SeriesEditor/SeriesTable" command="setCheckState" arguments="3.0,0" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/DisplayFrame/ProxyPanel/UseIndexForXAxis/CheckBox" command="set_boolean" arguments="false" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/DisplayFrame/ProxyPanel/XArrayName/ComboBox" command="activated" arguments="Result2" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/SortByXAxis/CheckBox" command="set_boolean" arguments="true" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mousePress" arguments="(0.93,0.533333,1,1,0)" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mouseMove" arguments="(0.93,0.533333,1,0,0)" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Frame.2/CentralWidgetFrame/Viewport" command="mouseRelease" arguments="(0.93,0.533333,1,0,0)" />
<pqevent object="pqClientMainWindow/cameraToolbar/actionResetCamera" command="activate" arguments="" />
</pqevents>
......@@ -239,6 +239,7 @@ int vtkChartRepresentation::RequestData(
reductionFilter->Update();
data = reductionFilter->GetOutputDataObject(0);
data = this->TransformTable(data);
if (this->EnableServerSideRendering && numProcs > 1)
{
......@@ -282,6 +283,12 @@ vtkDataObject* vtkChartRepresentation::TransformInputData(
return data;
}
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataObject> vtkChartRepresentation::TransformTable(
vtkSmartPointer<vtkDataObject> data)
{
return data;
}
//----------------------------------------------------------------------------
bool vtkChartRepresentation::IsCached(double cache_key)
{
......
......@@ -220,6 +220,14 @@ protected:
virtual vtkDataObject* TransformInputData(
vtkInformationVector** inputVector, vtkDataObject* data);
/**
* Method to be overridden to apply an operation of the table after it is
* gathered to the first rank for rendering the chart. This allows subclasses
* to operate on the final table. The default implementation just returns the
* input.
*/
virtual vtkSmartPointer<vtkDataObject> TransformTable(vtkSmartPointer<vtkDataObject> table);
typedef std::map<std::string, vtkSmartPointer<vtkTable> > MapOfTables;
/**
* Convenience method to get all vtkTable instances with their associated
......
......@@ -69,6 +69,7 @@ vtkPVXYChartView::vtkPVXYChartView()
this->InternalTitle = NULL;
this->PlotTime = vtkPVPlotTime::New();
this->HideTimeMarker = false;
this->SortByXAxis = false;
// Use the buffer id - performance issues are fixed.
this->ContextView->GetScene()->SetUseBufferId(true);
......
......@@ -423,6 +423,15 @@ public:
vtkGetMacro(HideTimeMarker, bool);
//@}
//@{
/**
* Set whether to sort the data in the chart by the x-axis array so that line
* plot connectivity is from left to right rather than semi-randomly by index.
*/
vtkGetMacro(SortByXAxis, bool);
vtkSetMacro(SortByXAxis, bool);
//@}
/**
* Provides access to the chart view.
*/
......@@ -483,6 +492,7 @@ protected:
void SelectionChanged();
bool HideTimeMarker;
bool SortByXAxis;
private:
vtkPVXYChartView(const vtkPVXYChartView&) VTK_DELETE_FUNCTION;
......
......@@ -16,16 +16,58 @@
#include "vtkXYChartRepresentationInternals.h"
#include "vtkCommand.h"
#include "vtkCompositeDataIterator.h"
#include "vtkContextView.h"
#include "vtkDataSetAttributes.h"
#include "vtkInformation.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVContextView.h"
#include "vtkPVXYChartView.h"
#include "vtkScalarsToColors.h"
#include "vtkSmartPointer.h"
#include "vtkSortFieldData.h"
#include "vtkTableAlgorithm.h"
#include "vtkWeakPointer.h"
#include <map>
#include <string>
class vtkXYChartRepresentation::SortTableFilter : public vtkTableAlgorithm
{
private:
char* ArrayToSortBy;
protected:
SortTableFilter()
: ArrayToSortBy(NULL)
{
}
~SortTableFilter() {}
public:
static SortTableFilter* New();
int RequestData(
vtkInformation*, vtkInformationVector** inVector, vtkInformationVector* outVector) VTK_OVERRIDE
{
vtkTable* in = vtkTable::GetData(inVector[0], 0);
vtkTable* out = vtkTable::GetData(outVector, 0);
if (!this->ArrayToSortBy)
{
vtkErrorMacro(<< "The array name to sort by must be set.");
return 0;
}
out->DeepCopy(in);
vtkSortFieldData::Sort(out->GetRowData(), this->ArrayToSortBy, 0, 0);
return 1;
}
vtkGetStringMacro(ArrayToSortBy);
vtkSetStringMacro(ArrayToSortBy);
};
vtkStandardNewMacro(vtkXYChartRepresentation::SortTableFilter);
//-----------------------------------------------------------------------------
#define vtkCxxSetChartTypeMacro(_name, _value) \
void vtkXYChartRepresentation::SetChartTypeTo##_name() { this->SetChartType(_value); }
......@@ -43,6 +85,7 @@ vtkXYChartRepresentation::vtkXYChartRepresentation()
, ChartType(vtkChart::LINE)
, XAxisSeriesName(NULL)
, UseIndexForXAxis(true)
, SortDataByXAxis(false)
, PlotDataHasChanged(false)
, SeriesLabelPrefix(NULL)
{
......@@ -80,6 +123,16 @@ void vtkXYChartRepresentation::PrintSelf(ostream& os, vtkIndent indent)
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkXYChartRepresentation::SetSortDataByXAxis(bool val)
{
if (this->SortDataByXAxis == val)
{
return;
}
this->SortDataByXAxis = val;
this->MarkModified();
}
//----------------------------------------------------------------------------
void vtkXYChartRepresentation::SetVisibility(bool visible)
{
......@@ -234,6 +287,21 @@ void vtkXYChartRepresentation::ClearLabels()
this->Modified();
}
//----------------------------------------------------------------------------
int vtkXYChartRepresentation::ProcessViewRequest(
vtkInformationRequestKey* request_type, vtkInformation* inInfo, vtkInformation* outInfo)
{
if (request_type == vtkPVView::REQUEST_UPDATE())
{
vtkPVXYChartView* view = vtkPVXYChartView::SafeDownCast(inInfo->Get(vtkPVView::VIEW()));
if (view)
{
this->SetSortDataByXAxis(view->GetSortByXAxis());
}
}
return Superclass::ProcessViewRequest(request_type, inInfo, outInfo);
}
//----------------------------------------------------------------------------
int vtkXYChartRepresentation::RequestData(
vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
......@@ -252,6 +320,22 @@ int vtkXYChartRepresentation::RequestData(
return 1;
}
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataObject> vtkXYChartRepresentation::TransformTable(
vtkSmartPointer<vtkDataObject> data)
{
if (!(this->SortDataByXAxis && this->XAxisSeriesName))
{
return Superclass::TransformTable(data);
}
vtkNew<SortTableFilter> sorter;
sorter->SetInputDataObject(data);
sorter->SetArrayToSortBy(this->XAxisSeriesName);
sorter->Update();
vtkSmartPointer<vtkDataObject> sortedTable = sorter->GetOutputDataObject(0);
return sortedTable;
}
//----------------------------------------------------------------------------
void vtkXYChartRepresentation::PrepareForRendering()
{
......
......@@ -92,6 +92,16 @@ public:
vtkGetMacro(UseIndexForXAxis, bool);
//@}
//@{
/**
* Get/set whether the points in the chart should be sorted by their x-axis value.
* Points are connected in line plots in the order they are in the table. Sorting
* by the x-axis allows the line to have no cycles.
*/
void SetSortDataByXAxis(bool val);
vtkGetMacro(SortDataByXAxis, bool);
//@}
//@{
/**
* Set/Clear the properties for Y series/columns.
......@@ -141,16 +151,23 @@ protected:
/**
* Overridden to remove all plots from the view.
*/
virtual bool RemoveFromView(vtkView* view) VTK_OVERRIDE;
bool RemoveFromView(vtkView* view) VTK_OVERRIDE;
int ProcessViewRequest(vtkInformationRequestKey* request_type, vtkInformation* inInfo,
vtkInformation* outInfo) VTK_OVERRIDE;
virtual int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) VTK_OVERRIDE;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) VTK_OVERRIDE;
virtual void PrepareForRendering() VTK_OVERRIDE;
vtkSmartPointer<vtkDataObject> TransformTable(vtkSmartPointer<vtkDataObject>) VTK_OVERRIDE;
void PrepareForRendering() VTK_OVERRIDE;
class vtkInternals;
friend class vtkInternals;
vtkInternals* Internals;
class SortTableFilter;
private:
vtkXYChartRepresentation(const vtkXYChartRepresentation&) VTK_DELETE_FUNCTION;
void operator=(const vtkXYChartRepresentation&) VTK_DELETE_FUNCTION;
......@@ -158,6 +175,7 @@ private:
int ChartType;
char* XAxisSeriesName;
bool UseIndexForXAxis;
bool SortDataByXAxis;
bool PlotDataHasChanged;
double SelectionColor[3];
char* SeriesLabelPrefix;
......
......@@ -194,6 +194,14 @@
value="8" />
</EnumerationDomain>
</IntVectorProperty>
<IntVectorProperty command="SetSortByXAxis"
default_values="0"
name="SortByXAxis"
label="Sort By X-Axis"
number_of_elements="1">
<BooleanDomain name="bool" />
<Documentation>Sort the chart data by the x-axis before deciding line plot connectivity.</Documentation>
</IntVectorProperty>
<IntVectorProperty command="SetLegendPosition"
default_values="0 0"
name="LegendPosition"
......
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