reporting: implement enlarge y limits for graph; requires a change in shading to get programmed ymin => using fill now

remove-priordens
Houtan Bastani 2014-02-13 16:47:17 +01:00
parent 95f9c37726
commit 7f199ee114
2 changed files with 24 additions and 33 deletions

View File

@ -48,7 +48,7 @@ o.yrange = '';
o.shade = '';
o.shadeColor = 'green';
o.shadeOpacity = .2;
o.shadeOpacity = 20;
o.showGrid = true;
@ -105,8 +105,8 @@ assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or
assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false');
assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false');
assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
o.shadeOpacity >= 0 && o.shadeOpacity <= 1, ...
'@graph.graph: o.shadeOpacity must be a real in [0 1]');
o.shadeOpacity >= 0 && o.shadeOpacity <= 100, ...
'@graph.graph: o.shadeOpacity must be a real in [0 100]');
assert(isfloat(o.width), '@graph.graph: o.width must be a real number');
assert(isfloat(o.height), '@graph.graph: o.height must be a real number');
assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number');

View File

@ -55,20 +55,6 @@ else
dd = o.xrange;
end
if isempty(o.yrange)
ymax = zeros(1, ne);
ymin = zeros(1, ne);
for i=1:ne
ymax(i) = o.series{i}.ymax(dd);
ymin(i) = o.series{i}.ymin(dd);
end
ymax = ceil(max(ymax));
ymin = floor(min(ymin));
else
ymin = o.yrange(1);
ymax = o.yrange(2);
end
fprintf(fid, '\\begin{axis}[%%\n');
% set tick labels
if isempty(o.xTickLabels)
@ -101,9 +87,13 @@ fprintf(fid, ['},\n',...
'scale only axis,\n'...
'xmin=1,\n'...
'xmax=%d,\n'...
'ymin=%d,\n'...
'ymax=%d,\n'...
'axis lines=box,\n'], o.width, o.height, dd.ndat, ymin, ymax);
'axis lines=box,\n'], o.width, o.height, dd.ndat);
if isempty(o.yrange)
fprintf(fid, 'enlarge y limits=true,\n');
else
fprintf(fid, 'ymin=%f,\nymax=%f,\n',o.yrange(1),o.yrange(2));
end
if o.showLegend
fprintf(fid, 'legend style={');
@ -134,19 +124,6 @@ if o.showZeroline
fprintf(fid, '%%zeroline\n\\addplot[black,line width=.5,forget plot] coordinates {(1,0)(%d,0)};\n',dd.ndat);
end
if ~isempty(o.shade)
xTickLabels = strings(dd);
x1 = find(strcmpi(date2string(o.shade(1)), xTickLabels));
x2 = find(strcmpi(date2string(o.shade(end)), xTickLabels));
assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ...
date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ...
'range of data selected.']);
fprintf(fid, ['%%shading\n\\addplot[area legend,solid,fill=%s,' ...
'opacity=%f,draw=black,forget plot]\ntable[row sep=crcr]{\nx ' ...
'y\\\\\n%d %d\\\\\n%d %d\\\\\n%d %d\\\\\n%d %d\\\\\n};\n'], ...
o.shadeColor, o.shadeOpacity, x1, ymin, x1, ymax, x2, ymax, x2, ymin);
end
for i=1:ne
o.series{i}.writeSeriesForGraph(fid, dd);
if o.showLegend
@ -154,6 +131,20 @@ for i=1:ne
end
end
if ~isempty(o.shade)
xTickLabels = strings(dd);
x1 = find(strcmpi(date2string(o.shade(1)), xTickLabels));
x2 = find(strcmpi(date2string(o.shade(end)), xTickLabels));
assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ...
date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ...
'range of data selected.']);
fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
'cs:%d,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n' ...
'\\end{pgfonlayer}\n'], ...
o.shadeColor, o.shadeOpacity, x1, x2);
end
fprintf(fid, '\\end{axis}\n\\end{tikzpicture}\n');
if fclose(fid) == -1
error('@graph.writeGraphFile: closing %s\n', o.filename);