Skip to content

Commit

Permalink
fill and alpha property
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Nov 8, 2023
1 parent 72ad8ee commit daad2f6
Show file tree
Hide file tree
Showing 16 changed files with 3,193 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,15 @@ jobs:
- name: Benchs
run: |
set OMP_NUM_THREADS=1
set NELSON_TERM_IS_UNICODE_SUPPORTED=TRUE
set PATH=C:\Program Files\Microsoft MPI\Bin;%PATH%
set TESTS_RESULT_DIR=%GITHUB_WORKSPACE%/artifacts
"c:/install/Nelson ${{ steps.json_version.outputs.packageVersion }}.%GITHUB_RUN_NUMBER%/bin/win32/nelson-cli" --noipc --quiet -f "c:/install/Nelson ${{ steps.json_version.outputs.packageVersion }}.%GITHUB_RUN_NUMBER%/tools/benchs_all/runbenchs_all.m"
- name: Tests
run: |
set OMP_NUM_THREADS=1
set NELSON_TERM_IS_UNICODE_SUPPORTED=TRUE
set PATH=C:\Program Files\Microsoft MPI\Bin;%PATH%
set TESTS_RESULT_DIR=%GITHUB_WORKSPACE%/artifacts
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `scatter` Scatter plot.
- `stem` Plot discrete sequence data.
- `stairs` Stairstep graph.
- `fill` 2-D patch.

### Changed

- axis limits recalculate with `hggroup`.
- `axes` forces focus on current axe.
- function_handle parenthese precedence.
- [#997](http://github.com/Nelson-numerical-software/nelson/issues/997) Macos BigSur Github CI support removed.
- `patch` and `fill` manages `FaceAlpha`.

## 0.7.10 (2023-10-27)

Expand Down
63 changes: 63 additions & 0 deletions modules/graphics/functions/fill.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
%=============================================================================
% Copyright (c) 2016-present Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
function varargout = fill(varargin)
% fill(X, Y, C)
% fill(..., Name, Value)
% fill(ax, ...)
% p = fill(...)

nargoutchk(0, 1);
narginchk(3, 100);

args = parsePatchArguments(varargin);

h = patch(args{:});

if (nargout > 0)
varargout{1} = h;
else
varargout = {};
end
end
%=============================================================================
function args = parsePatchArguments(inputArguments)
if (length(inputArguments) > 0 &&isscalar(inputArguments{1}) && (isgraphics(inputArguments{1}, 'axes') || isgraphics(inputArguments{1}, 'hggroup')))
ax = inputArguments{1};
inputArguments = inputArguments{2:end};
else
ax = [];
end

nbInputArguments = length(inputArguments);

firstString = find (cellfun ('isclass', inputArguments, 'char'), 1);
if (isempty(firstString))
firstString = nbInputArguments + 1;
end
if (firstString == 3)
XData = inputArguments{1};
YData = inputArguments{2};
CData = validatecolor(inputArguments{3});
ZData = zeros(size(XData));
elseif (firstString == 4)
XData = inputArguments{1};
YData = inputArguments{2};
CData = inputArguments{3};
ZData = zeros(size(XData));
elseif (nbInputArguments > 0)
error(_('Wrong number of input arguments.'));
end
args = {};
if ~isempty(ax)
args = {ax};
end
args = [args, XData, YData, ZData, CData, inputArguments(firstString+1:end)];
end
%=============================================================================
3 changes: 2 additions & 1 deletion modules/graphics/functions/legend.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
for k = 1:length(lineHandles)
lineHandles(k).Visible = 'on';
end
axes(ax);
parentFigure = ancestor(ax, 'figure');
parentFigure.CurrentAxes = ax;
if nargout > 0
varargout{1} = cba;
end
Expand Down
34 changes: 26 additions & 8 deletions modules/graphics/functions/patch.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
if (isempty(firstString))
firstString = nbInputArguments + 1;
end

if ((nbInputArguments >= 3) && (firstString == 3)) || ((nbInputArguments >= 4) && (firstString == 4))
% h = patch(X, Y, C) or h = patch(X, Y, Z, C)
str = inputArguments{firstString};
Expand All @@ -66,8 +66,8 @@
else
C = validatecolor(str);
end
inputArguments = [inputArguments(1:firstString-1), C];
propertiesList = inputArguments(firstString+1:end);
propertiesList = inputArguments(firstString+1:end);
inputArguments = [inputArguments(1:firstString-1), C];
end
else
propertiesList = inputArguments(firstString:end);
Expand All @@ -77,7 +77,7 @@
propertiesList = inputArguments(firstString:end);
inputArguments = inputArguments(1:firstString-1);
end

nbInputArguments = length(inputArguments);
ax = [];
XData = [];
Expand Down Expand Up @@ -152,7 +152,12 @@
if isfield(args, 'Faces')
rmfield(args, 'Faces');
end


FaceAlphasAsProperty = getValueFromStruct(args, 'FaceAlpha');
if isfield(args, 'FaceAlpha')
rmfield(args, 'FaceAlpha');
end

VerticesAsProperty = getValueFromStruct(args, 'Vertices');
if isfield(args, 'Vertices')
rmfield(args, 'Vertices');
Expand Down Expand Up @@ -268,8 +273,8 @@
end

if ~isempty(FaceVertexCDataAsProperty)
FaceVertexCData = FaceVertexCDataAsProperty;
else
FaceVertexCData = FaceVertexCDataAsProperty;
else
if isnumeric(CData)
FaceVertexCData = CData;
elseif ischar(CData)
Expand Down Expand Up @@ -301,7 +306,19 @@
else
EdgeColor = EdgeColorDefault;
end


if ~isempty(FaceAlphasAsProperty)
FaceAlpha = FaceAlphasAsProperty;
else
FaceAlpha = 1;
end

if (isvector(XData) && (length(XData) == 3))
XData = [XData(1), XData(:)']';
YData = [YData(1), YData(:)']';
ZData = [ZData(1), ZData(:)']';
end

args.Parent = Parent;
args.XData = XData;
args.YData = YData;
Expand All @@ -312,6 +329,7 @@
args.FaceVertexCData = FaceVertexCData;
args.FaceColor = FaceColor;
args.EdgeColor = EdgeColor;
args.FaceAlpha = FaceAlpha;

args = reshape([fieldnames(args)'; struct2cell(args)'], 1, []);

Expand Down
Loading

0 comments on commit daad2f6

Please sign in to comment.