|
| 1 | +classdef FigureStudioSourceAxesTest < matlab.unittest.TestCase |
| 2 | + %FIGURESTUDIOSOURCEAXESTEST Verify Figure Studio source axes import prep. |
| 3 | + |
| 4 | + methods (Test, TestTags = {'Unit'}) |
| 5 | + function copyToPreviewNormalizesLayoutBeforeStyling(testCase) |
| 6 | + setupLabKitTestPath(); |
| 7 | + cleanup = onCleanup(@() closeAllTestFigures()); |
| 8 | + |
| 9 | + sourceFig = figure('Visible', 'off', 'Color', 'w'); |
| 10 | + sourceAx = axes('Parent', sourceFig); |
| 11 | + plot(sourceAx, linspace(0, 30, 200), sin(linspace(0, 30, 200))); |
| 12 | + xlabel(sourceAx, 'Time'); |
| 13 | + ylabel(sourceAx, 'Signal'); |
| 14 | + pbaspect(sourceAx, [1 0.1 1]); |
| 15 | + daspect(sourceAx, [10 1 1]); |
| 16 | + |
| 17 | + previewFig = figure('Visible', 'off', 'Color', 'w'); |
| 18 | + previewAx = axes('Parent', previewFig); |
| 19 | + figure_studio.sourceAxes.copyToPreview(sourceAx, previewAx); |
| 20 | + |
| 21 | + testCase.verifyEqual(string(previewAx.PlotBoxAspectRatioMode), "auto", ... |
| 22 | + "Imported FIG layout constraints should not be carried into the Studio preview."); |
| 23 | + testCase.verifyEqual(string(previewAx.DataAspectRatioMode), "auto", ... |
| 24 | + "Imported FIG data aspect constraints should be normalized before Studio styling."); |
| 25 | + testCase.verifyEqual(numel(previewAx.Children), numel(sourceAx.Children), ... |
| 26 | + "Imported FIG data graphics should still be copied into the preview."); |
| 27 | + end |
| 28 | + |
| 29 | + function figFileImportUsesDisplayedAxesRatioForCanvas(testCase) |
| 30 | + setupLabKitTestPath(); |
| 31 | + cleanup = onCleanup(@() closeAllTestFigures()); |
| 32 | + |
| 33 | + sourceFig = figure('Visible', 'off', 'Color', 'w', ... |
| 34 | + 'Units', 'pixels', 'Position', [100 100 720 540]); |
| 35 | + sourceAx = axes('Parent', sourceFig, 'Units', 'normalized', ... |
| 36 | + 'Position', [0.13 0.34 0.775 0.58]); |
| 37 | + plot(sourceAx, 1:4, [1 3 2 4]); |
| 38 | + pbaspect(sourceAx, [1 0.1 1]); |
| 39 | + |
| 40 | + style = figure_studio.sourceAxes.sourceStyle(sourceAx, ... |
| 41 | + "PreserveAspect", false); |
| 42 | + ratio = double(style.canvasWidth) / double(style.canvasHeight); |
| 43 | + |
| 44 | + testCase.verifyGreaterThan(ratio, 1.2, ... |
| 45 | + "FIG default canvas should follow displayed axes geometry."); |
| 46 | + testCase.verifyLessThan(ratio, 3, ... |
| 47 | + "FIG default canvas should not inherit extreme cached plot-box ratios."); |
| 48 | + end |
| 49 | + |
| 50 | + function axesHandoffCanPreserveSourcePlotBoxRatio(testCase) |
| 51 | + setupLabKitTestPath(); |
| 52 | + cleanup = onCleanup(@() closeAllTestFigures()); |
| 53 | + |
| 54 | + sourceFig = figure('Visible', 'off', 'Color', 'w'); |
| 55 | + sourceAx = axes('Parent', sourceFig); |
| 56 | + plot(sourceAx, 1:4, [1 3 2 4]); |
| 57 | + pbaspect(sourceAx, [2 1 1]); |
| 58 | + |
| 59 | + style = figure_studio.sourceAxes.sourceStyle(sourceAx); |
| 60 | + ratio = double(style.canvasWidth) / double(style.canvasHeight); |
| 61 | + |
| 62 | + testCase.verifyLessThan(abs(ratio - 2), 0.02, ... |
| 63 | + "Axes handoff should still preserve explicit source plot-box ratios."); |
| 64 | + end |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +function closeAllTestFigures() |
| 69 | + delete(findall(groot, 'Type', 'figure')); |
| 70 | +end |
0 commit comments