Skip to content

Commit 21358d8

Browse files
Add tests for line and rectangle
1 parent 5aa73ff commit 21358d8

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

‎plotly/Test_plotlyfig.m‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,6 +3815,75 @@ function testImagescPlotData(tc)
38153815
end
38163816
try close(); catch; end
38173817
end
3818+
3819+
function testLinePrimitivePlotData(tc)
3820+
% the line() primitive becomes a single lines trace.
3821+
fig = figure("Visible","off");
3822+
x = [0 1 2];
3823+
y = [0 1 0];
3824+
line(x, y, "LineWidth", 2);
3825+
3826+
p = plotlyfig(fig,"visible","off");
3827+
3828+
tc.verifyNumElements(p.data, 1);
3829+
expected = struct( ...
3830+
"type", "scatter", ...
3831+
"xaxis", "x1", ...
3832+
"yaxis", "y1", ...
3833+
"visible", true, ...
3834+
"name", '', ...
3835+
"mode", 'lines', ...
3836+
"x", x, ...
3837+
"y", y, ...
3838+
"line", struct( ...
3839+
"color", PlotlyTestCase.AnyColorString(), ...
3840+
"width", 2, ...
3841+
"dash", "solid" ...
3842+
), ...
3843+
"marker", struct( ...
3844+
"size", 3.6, ...
3845+
"line", struct( ...
3846+
"width", 2 ...
3847+
), ...
3848+
"color", PlotlyTestCase.AnyColorString() ...
3849+
), ...
3850+
"showlegend", false ...
3851+
);
3852+
tc.verifyEqualStructs(p.data{1}, expected, 'AbsTol', 1e-15);
3853+
try close(); catch; end
3854+
end
3855+
3856+
function testRectanglePlotData(tc)
3857+
% rectangle() becomes a single closed-loop lines trace.
3858+
fig = figure("Visible","off");
3859+
x = [0 0 2 2 0];
3860+
y = [0 3 3 0 0];
3861+
rectangle("Position", [0 0 2 3], "FaceColor", "r");
3862+
3863+
p = plotlyfig(fig,"visible","off");
3864+
3865+
tc.verifyNumElements(p.data, 1);
3866+
expected = struct( ...
3867+
"type", "scatter", ...
3868+
"xaxis", "x1", ...
3869+
"yaxis", "y1", ...
3870+
"x", x, ...
3871+
"y", y, ...
3872+
"name", '', ...
3873+
"mode", 'lines', ...
3874+
"visible", true, ...
3875+
"fill", "tonexty", ...
3876+
"line", struct( ...
3877+
"color", PlotlyTestCase.AnyColorString(), ...
3878+
"width", 0.5, ...
3879+
"dash", "solid" ...
3880+
), ...
3881+
"fillcolor", PlotlyTestCase.AnyColorString(), ...
3882+
"showlegend", false ...
3883+
);
3884+
tc.verifyEqualStructs(p.data{1}, expected, 'AbsTol', 1e-15);
3885+
try close(); catch; end
3886+
end
38183887
end
38193888

38203889
methods (Static)

0 commit comments

Comments
 (0)