Skip to content

Commit

Permalink
Last bit of tests + codecov.io badge on top-level readme
Browse files Browse the repository at this point in the history
+ Fine tuned tests to bring to the edge the global coverage

- Error thrown by hex2rgb for invalid range converted in handled message

- Error thrown by palette.crameri for invalid name converted as well

+ Codecov badge in README

> This commit should release...
  • Loading branch information
beddalumia committed Aug 20, 2022
1 parent f21950c commit f74ca87
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .test/test_X11.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function X11_colors()
close all
clear

rgb.X11 % print help

names = rgb.X11('list');
disp('Are colornames unchanged?')
assert(isequal(names,reference_names),'X11 colornames have changed')
Expand Down
16 changes: 12 additions & 4 deletions .test/test_all_docstrings.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function all_docstrings()
disp '...done!'

disp X11
X11('navyblue')
X11("navyblue")
X11('SpringGreen','CornflowerBlue','sapphire','radioactive green')
x = -pi:.1:pi;
y = cos(x);
Expand All @@ -33,7 +33,7 @@ function all_docstrings()
disp '...done!'

disp xkcd
xkcd('baby blue')
xkcd("baby blue")
xkcd('wintergreen','sunflower yellow','sapphire','radioactive green')
x = -pi:.1:pi;
y = cos(x);
Expand All @@ -60,6 +60,7 @@ function all_docstrings()
view_color({'pyplot1',"pyplot2",'pyplot3'},'vbars')
view_color(palette.tab20(16),'hbars')
view_color(palette.cubehelix(36))
view_color(palette.cubehelix(36),'square') % wrong form factor -> print help
close all; clear
disp '...done!'

Expand All @@ -74,11 +75,13 @@ function all_docstrings()
disp '...done!'

disp hex2rgb
hex2rgb % print help :)
rgb = [0.2000,0.3020,0.4000];
assert(norm(rgb-hex2rgb('#334D66'))<1e10)
assert(norm(rgb-hex2rgb('334D66'))<1e10)
RGB = [51,77,102];
assert(norm(rgb-hex2rgb('#334D66',256))<1e10)
assert(norm(RGB-hex2rgb('#334D66',256))<1e10)
hex2rgb('#334D66',250) % Error handling :)
hexmatrix = ['#334D66';'#8099B3';'#CC9933';'#3333E6'];
hexchcell = {'#334D66';'#8099B3';'#CC9933';'#3333E6'};
hexstrarr = ["#334D66","#8099B3","#CC9933","#3333E6"];
Expand All @@ -88,6 +91,7 @@ function all_docstrings()
disp '...done!'

disp rgb2hex
hex2rgb % print help :)
hex = '#00FF00';
rgb = [0 1 0];
RGB = [0 255 0];
Expand Down Expand Up @@ -153,7 +157,8 @@ function all_docstrings()
close
[X,Y,Z] = peaks(30);
surfc(X,Y,Z+4)
palette.crameri('bam','pivot',4)
palette.crameri('Bam','pivot',4)
palette.crameri('sBam') % Error handling :)
preset_palette(@palette.crameri,'oleron'); % preselect the map.
cmap = palette.crameri('-oleron');
assert(isequal(cmap(end:-1:1,:),preset_palette))
Expand Down Expand Up @@ -197,8 +202,11 @@ function all_docstrings()
end

disp paletteshow
paletteshow.brewer('show') % Error handling :)
paletteshow.brewer
paletteshow.cmocean('show') % Error handling :)
paletteshow.cmocean
paletteshow.crameri('show') % Error handling :)
paletteshow.crameri
%paletteshow.matplotlib TODO!
close all force % brewer is nasty
Expand Down
6 changes: 4 additions & 2 deletions .test/test_color_order.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ function color_order()
close all
clear

N = 7;

set_colororder % prints help
N = 7
set_colororder show
N = N + 2
set_colororder('show',N)

disp('>> All good!')
Expand Down
7 changes: 7 additions & 0 deletions .test/test_default_palettes.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ function default_palettes()
close all
clear

set_palette % prints help

disp 'default N'
set_palette show

N = 3;
disp 'N = 3'
set_palette('show',N)

disp('>> All good!')
disp('------------')

Expand Down
4 changes: 3 additions & 1 deletion .test/test_string_lookup.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function strlook()

disp('TESTING smart string lookup [+rgb;get_palette]')
disp('TESTING smart string lookup [+rgb;get_palette;set_palette;set_colororder]')

colorlab.enter
close all
Expand All @@ -12,6 +12,8 @@ function strlook()

get_palette virridis;

set_palette magda

set_colororder tab;

disp('>> All good!')
Expand Down
2 changes: 2 additions & 0 deletions .test/test_xkcd.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function xkcd_colors()
close all
clear

rgb.xkcd % print help

names = rgb.xkcd('list');
disp('Are colornames unchanged?')
assert(isequal(names,reference_names),'xkcd colornames have changed')
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![R2021a](https://github.com/bellomia/colorlab/actions/workflows/R2021a.yaml/badge.svg)](https://github.com/bellomia/colorlab/actions/workflows/R2021a.yaml)
[![R2021b](https://github.com/bellomia/colorlab/actions/workflows/R2021b.yaml/badge.svg)](https://github.com/bellomia/colorlab/actions/workflows/R2021b.yaml)
[![R2022a](https://github.com/bellomia/colorlab/actions/workflows/R2022a.yaml/badge.svg)](https://github.com/bellomia/colorlab/actions/workflows/R2022a.yaml)
[![codecov](https://codecov.io/gh/bellomia/colorlab/branch/master/graph/badge.svg?token=DPZTI61U97)](https://codecov.io/gh/bellomia/colorlab)

For a long time Matlab has excelled for its plotting features, at a point where [matplotlib](https://matplotlib.org), arguably the most popular open-source plotting library nowadays, has started as an explicit clone of such functionality and still today keeps a strong influence. In recent years, though, one important aspect has greatly evolved in the plotting business: color management. So we had [Dave Green's 2011 paper](https://astron-soc.in/bulletin/11June/289392011.pdf) introducing a new, revolutionary, colormap with the aim of representing astronomical data with monotonically increasing brightness (and so black-and-white print friendliness); then in 2015 even better advances by the SciPy team, enriching matplotib with beautiful _perceptually uniform_ colormaps ([viridis, magma, plasma](https://www.youtube.com/watch?v=xAoljeRJ3lU) and the [domain-specific ones for oceanography: cmocean](https://youtu.be/XjHzLUnHeM0)). Meanwhile the results of a totally crazy and marvelous at the same time [2010 color survey](https://blog.xkcd.com/2010/05/03/color-survey-results/) made by the great xkcd webcomic, have gained more and more popularity, in fact challenging the old and trusted [X11 colorset](https://en.wikipedia.org/wiki/X11_color_names). Nowadays it's embedded again in [matplotlib](https://matplotlib.org/stable/tutorials/colors/colors.html) and available in [LaTeX](https://www.ctan.org/pkg/xkcdcolors), in [R](https://cran.r-project.org/web/packages/xkcdcolors/), and [Julia](https://github.com/JuliaGraphics/NamedColors.jl).

Expand Down
6 changes: 5 additions & 1 deletion brewer/+paletteshow/brewer.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function brewer()
function brewer(varargin)
% Simple plot of all ColorBrewer colorscheme nodes in one static figure.
%
% (c) 2014-2022 Stephen Cobeldick, 2022 Gabriele Bellomia (package adaptation)
Expand All @@ -9,6 +9,10 @@ function brewer()
% See also PALETTE PALETTEDITOR PALETTESHOW CUBEHELIX MAXDISTCOLOR
% LBMAP PARULA LINES RGBPLOT COLORMAP COLORBAR PLOT PLOT3 AXES SET

if nargin > 0
fprintf(2,'Warning: you might want to call palette.brewer instead.\n');
end

[mcs,nmn,pyt] = palette.brewer('list');
%
persistent cbh axh
Expand Down
3 changes: 2 additions & 1 deletion colortools/hex2rgb.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
rgb = reshape(sscanf(hex.','%2x'),3,[]).';

otherwise
error('Range must be either "1" to scale from 0 to 1 or "256" to scale from 0 to 255.')
disp('ERROR: Range must be either "1" to scale from 0 to 1 or "256" to scale from 0 to 255.')
return
end

if isempty(rgb)
Expand Down
5 changes: 3 additions & 2 deletions crameri/+palette/crameri.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@
S = load('CrameriColourMaps.mat',ColormapName);
cmap = S.(ColormapName);
catch
error(['Unknown colormap name ''',ColormapName,...
'''. Try typing paletteshow.crameri to check the options and try again.'])
fprintf(2,['ERROR: Unknown colormap name ''',ColormapName,...
'''. Try typing paletteshow.crameri to check the options and try again.\n'])
return
end
end

Expand Down

0 comments on commit f74ca87

Please sign in to comment.