Skip to content

Commit fa4d4d4

Browse files
authored
Merge pull request #38737 from mantidproject/setMarkerStyle_ornl-next
Fix call to getMarkerStyle
2 parents d571a4f + 89a0e5f commit fa4d4d4

File tree

6 files changed

+76
-8
lines changed

6 files changed

+76
-8
lines changed

Framework/API/inc/MantidAPI/MatrixWorkspace.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,44 @@ class ParameterMap;
3333
}
3434

3535
const std::vector<std::string> validPlotTypes{"plot", "marker", "histogram", "errorbar_x", "errorbar_y", "errorbar_xy"};
36+
const std::vector<std::string> validMarkerStyles{"square",
37+
"plus (filled)",
38+
"point",
39+
"tickdown",
40+
"triangle_right",
41+
"tickup",
42+
"hline",
43+
"vline",
44+
"pentagon",
45+
"tri_left",
46+
"caretdown",
47+
"caretright (centered at base)",
48+
"tickright",
49+
"caretright",
50+
"caretleft",
51+
"tickleft",
52+
"tri_up",
53+
"circle",
54+
"pixel",
55+
"caretleft (centered at base)",
56+
"diamond",
57+
"star",
58+
"hexagon1",
59+
"octagon",
60+
"hexagon2",
61+
"tri_right",
62+
"x (filled)",
63+
"thin_diamond",
64+
"tri_down",
65+
"triangle_left",
66+
"plus",
67+
"triangle_down",
68+
"triangle_up",
69+
"x",
70+
"caretup",
71+
"caretup (centered at base)",
72+
"caretdown (centered at base)",
73+
"None"};
3674

3775
namespace API {
3876
class Axis;

Framework/API/src/MatrixWorkspace.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ void MatrixWorkspace::setPlotType(const std::string &t) {
337337
run.addProperty("plot_type", t, true);
338338
else
339339
run.addProperty("plot_type", t, false);
340+
} else {
341+
std::string validValues = std::accumulate(
342+
validPlotTypes.begin() + 1, validPlotTypes.end(), validPlotTypes.front(),
343+
[](const std::string &valuesString, const std::string &plotType) { return valuesString + ", " + plotType; });
344+
g_log.warning("Invalid plot type '" + t + "'. Must be one of: " + validValues);
340345
}
341346
}
342347

@@ -359,7 +364,20 @@ std::string MatrixWorkspace::getPlotType() const {
359364
*
360365
* @param markerType :: The Marker Type
361366
*/
362-
void MatrixWorkspace::setMarkerStyle(const std::string &markerType) { m_marker = markerType; }
367+
void MatrixWorkspace::setMarkerStyle(const std::string &markerType) {
368+
StringListValidator v(validMarkerStyles);
369+
370+
if (v.isValid(markerType) == "") {
371+
m_marker = markerType;
372+
} else {
373+
std::string validValues =
374+
std::accumulate(validMarkerStyles.begin() + 1, validMarkerStyles.end(), validMarkerStyles.front(),
375+
[](const std::string &valuesString, const std::string &markerStyle) {
376+
return valuesString + ", " + markerStyle;
377+
});
378+
g_log.warning("Invalid marker type '" + markerType + "'. Must be one of: " + validValues);
379+
}
380+
}
363381

364382
/**
365383
* get the marker type
@@ -368,7 +386,7 @@ void MatrixWorkspace::setMarkerStyle(const std::string &markerType) { m_marker =
368386
*/
369387
std::string MatrixWorkspace::getMarkerStyle() const {
370388
if (m_marker.empty())
371-
return Kernel::ConfigService::Instance().getString("markerworkspace.marker.Style");
389+
return Kernel::ConfigService::Instance().getString("plots.markerworkspace.MarkerStyle");
372390
else
373391
return m_marker;
374392
}

Framework/API/test/MatrixWorkspaceTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite {
417417

418418
void testGetSetMarkerStyle() {
419419
// test default
420-
TS_ASSERT_EQUALS(ws->getMarkerStyle(), "");
420+
TS_ASSERT_EQUALS(ws->getMarkerStyle(), "vline");
421421

422422
// test set
423423
ws->setMarkerStyle("square");

Framework/PythonInterface/mantid/plots/utility.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,7 @@ def get_plot_specific_properties(ws, plot_type, plot_kwargs):
310310
else:
311311
if plot_type == "marker":
312312
plot_kwargs["linestyle"] = "None"
313-
if ws.getMarkerStyle():
314-
plot_kwargs["marker"] = MARKER_MAP[ws.getMarkerType()]
315-
else:
316-
plot_kwargs["marker"] = MARKER_MAP[ConfigService.getString("plots.markerworkspace.MarkerStyle")]
313+
plot_kwargs["marker"] = MARKER_MAP[ws.getMarkerStyle()]
317314
marker_size = ws.getMarkerSize()
318315
plot_kwargs["markersize"] = (
319316
marker_size if marker_size != 6 else float(ConfigService.getString("plots.markerworkspace.MarkerSize"))

Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ def test_setPlotType(self):
411411
ws1.setPlotType("marker")
412412
self.assertEqual("marker", ws1.getPlotType())
413413

414+
def test_setMarkerStyle(self):
415+
run_algorithm("CreateWorkspace", OutputWorkspace="ws1", DataX=[1.0, 2.0, 3.0], DataY=[2.0, 3.0], DataE=[2.0, 3.0], UnitX="TOF")
416+
ws1 = AnalysisDataService["ws1"]
417+
418+
# test default
419+
self.assertEqual("vline", ws1.getMarkerStyle())
420+
421+
# test invalid doesn't take
422+
ws1.setMarkerStyle("invalid")
423+
self.assertEqual("vline", ws1.getMarkerStyle())
424+
425+
# test valid takes
426+
ws1.setMarkerStyle("square")
427+
self.assertEqual("square", ws1.getMarkerStyle())
428+
414429
def test_setGetMonitorWS(self):
415430
run_algorithm("CreateWorkspace", OutputWorkspace="ws1", DataX=[1.0, 2.0, 3.0], DataY=[2.0, 3.0], DataE=[2.0, 3.0], UnitX="TOF")
416431
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")

buildconfig/CMake/CppCheck_Suppressions.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/FunctionValues
106106
missingOverride:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IAlgorithmRuntimeProps.h:16
107107
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IMDWorkspace.h:92
108108
virtualCallInConstructor:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IPowderDiffPeakFunction.h:41
109-
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MatrixWorkspace.h:354
109+
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MatrixWorkspace.h:392
110110
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MultipleFileProperty.h:122
111111
returnByReference:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MultipleFileProperty.h:125
112112
virtualCallInConstructor:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/ParameterTie.h:42

0 commit comments

Comments
 (0)