Skip to content

Commit

Permalink
Merge pull request #38737 from mantidproject/setMarkerStyle_ornl-next
Browse files Browse the repository at this point in the history
Fix call to getMarkerStyle
  • Loading branch information
searscr authored Jan 29, 2025
2 parents d571a4f + 89a0e5f commit fa4d4d4
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
38 changes: 38 additions & 0 deletions Framework/API/inc/MantidAPI/MatrixWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,44 @@ class ParameterMap;
}

const std::vector<std::string> validPlotTypes{"plot", "marker", "histogram", "errorbar_x", "errorbar_y", "errorbar_xy"};
const std::vector<std::string> validMarkerStyles{"square",
"plus (filled)",
"point",
"tickdown",
"triangle_right",
"tickup",
"hline",
"vline",
"pentagon",
"tri_left",
"caretdown",
"caretright (centered at base)",
"tickright",
"caretright",
"caretleft",
"tickleft",
"tri_up",
"circle",
"pixel",
"caretleft (centered at base)",
"diamond",
"star",
"hexagon1",
"octagon",
"hexagon2",
"tri_right",
"x (filled)",
"thin_diamond",
"tri_down",
"triangle_left",
"plus",
"triangle_down",
"triangle_up",
"x",
"caretup",
"caretup (centered at base)",
"caretdown (centered at base)",
"None"};

namespace API {
class Axis;
Expand Down
22 changes: 20 additions & 2 deletions Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ void MatrixWorkspace::setPlotType(const std::string &t) {
run.addProperty("plot_type", t, true);
else
run.addProperty("plot_type", t, false);
} else {
std::string validValues = std::accumulate(
validPlotTypes.begin() + 1, validPlotTypes.end(), validPlotTypes.front(),
[](const std::string &valuesString, const std::string &plotType) { return valuesString + ", " + plotType; });
g_log.warning("Invalid plot type '" + t + "'. Must be one of: " + validValues);
}
}

Expand All @@ -359,7 +364,20 @@ std::string MatrixWorkspace::getPlotType() const {
*
* @param markerType :: The Marker Type
*/
void MatrixWorkspace::setMarkerStyle(const std::string &markerType) { m_marker = markerType; }
void MatrixWorkspace::setMarkerStyle(const std::string &markerType) {
StringListValidator v(validMarkerStyles);

if (v.isValid(markerType) == "") {
m_marker = markerType;
} else {
std::string validValues =
std::accumulate(validMarkerStyles.begin() + 1, validMarkerStyles.end(), validMarkerStyles.front(),
[](const std::string &valuesString, const std::string &markerStyle) {
return valuesString + ", " + markerStyle;
});
g_log.warning("Invalid marker type '" + markerType + "'. Must be one of: " + validValues);
}
}

/**
* get the marker type
Expand All @@ -368,7 +386,7 @@ void MatrixWorkspace::setMarkerStyle(const std::string &markerType) { m_marker =
*/
std::string MatrixWorkspace::getMarkerStyle() const {
if (m_marker.empty())
return Kernel::ConfigService::Instance().getString("markerworkspace.marker.Style");
return Kernel::ConfigService::Instance().getString("plots.markerworkspace.MarkerStyle");
else
return m_marker;
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/API/test/MatrixWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite {

void testGetSetMarkerStyle() {
// test default
TS_ASSERT_EQUALS(ws->getMarkerStyle(), "");
TS_ASSERT_EQUALS(ws->getMarkerStyle(), "vline");

// test set
ws->setMarkerStyle("square");
Expand Down
5 changes: 1 addition & 4 deletions Framework/PythonInterface/mantid/plots/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@ def get_plot_specific_properties(ws, plot_type, plot_kwargs):
else:
if plot_type == "marker":
plot_kwargs["linestyle"] = "None"
if ws.getMarkerStyle():
plot_kwargs["marker"] = MARKER_MAP[ws.getMarkerType()]
else:
plot_kwargs["marker"] = MARKER_MAP[ConfigService.getString("plots.markerworkspace.MarkerStyle")]
plot_kwargs["marker"] = MARKER_MAP[ws.getMarkerStyle()]
marker_size = ws.getMarkerSize()
plot_kwargs["markersize"] = (
marker_size if marker_size != 6 else float(ConfigService.getString("plots.markerworkspace.MarkerSize"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,21 @@ def test_setPlotType(self):
ws1.setPlotType("marker")
self.assertEqual("marker", ws1.getPlotType())

def test_setMarkerStyle(self):
run_algorithm("CreateWorkspace", OutputWorkspace="ws1", DataX=[1.0, 2.0, 3.0], DataY=[2.0, 3.0], DataE=[2.0, 3.0], UnitX="TOF")
ws1 = AnalysisDataService["ws1"]

# test default
self.assertEqual("vline", ws1.getMarkerStyle())

# test invalid doesn't take
ws1.setMarkerStyle("invalid")
self.assertEqual("vline", ws1.getMarkerStyle())

# test valid takes
ws1.setMarkerStyle("square")
self.assertEqual("square", ws1.getMarkerStyle())

def test_setGetMonitorWS(self):
run_algorithm("CreateWorkspace", OutputWorkspace="ws1", DataX=[1.0, 2.0, 3.0], DataY=[2.0, 3.0], DataE=[2.0, 3.0], UnitX="TOF")
run_algorithm("CreateWorkspace", OutputWorkspace="ws_mon", DataX=[1.0, 2.0, 3.0], DataY=[2.0, 3.0], DataE=[2.0, 3.0], UnitX="TOF")
Expand Down
2 changes: 1 addition & 1 deletion buildconfig/CMake/CppCheck_Suppressions.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/FunctionValues
missingOverride:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IAlgorithmRuntimeProps.h:16
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IMDWorkspace.h:92
virtualCallInConstructor:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IPowderDiffPeakFunction.h:41
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MatrixWorkspace.h:354
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MatrixWorkspace.h:392
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MultipleFileProperty.h:122
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MultipleFileProperty.h:125
virtualCallInConstructor:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/ParameterTie.h:42
Expand Down

0 comments on commit fa4d4d4

Please sign in to comment.