reporting: add writeCSV option for graphs, #693

time-shift
Houtan Bastani 2014-07-29 12:34:20 +02:00
parent f6fa361838
commit b4dd4b5de1
4 changed files with 34 additions and 3 deletions

View File

@ -11322,7 +11322,7 @@ command. Default: @code{`!'}
@end defmethod
@anchor{addGraph}
@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor
@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, writeCSV, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor
Adds a @code{Graph} to a @code{Section}.
@optionshead
@table @code
@ -11337,10 +11337,12 @@ to the left, right, bottom, and top of the graphed line(s). @code{`L'} means
that there is an axis to the left and bottom of the graphed line(s). Default:
@code{`box'}
@anchor{graphDirName}
@item graphDirName, @code{STRING}
The name of the folder in which to store this figure. Default:
@code{tmpRepDir}
@anchor{graphName}
@item graphName, @code{STRING}
The name to use when saving this figure. Default: something of the
form @code{graph_pg1_sec2_row1_col3.tex}
@ -11426,6 +11428,12 @@ the title and subtitles. Default: @code{TikZ default}
@item width, @code{DOUBLE}
The width of the graph, in inches. Default: @code{6.0}
@item writeCSV, @code{BOOLEAN}
Whether or not to write a CSV file with only the plotted data. The file will be
saved in the directory specified by @ref{graphDirName} with the same base name
as specified by @ref{graphName} with the ending @code{.csv}. Default:
@code{false}
@item xlabel, @code{STRING}
The x-axis label. Default: @code{none}

View File

@ -85,6 +85,8 @@ o.height = 4.5;
o.miscTikzPictureOptions = '';
o.miscTikzAxisOptions = '';
o.writeCSV = false;
if nargin == 1
assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ...
'must pass a graph object']);
@ -139,7 +141,7 @@ assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must b
assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false');
assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false');
assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false');
assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false');
assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string');
assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ...

View File

@ -231,8 +231,25 @@ if o.showZeroline
o.zeroLineColor, dd.ndat);
end
if o.writeCSV
csvseries = dseries();
end
for i=1:ne
o.series{i}.writeSeriesForGraph(fid, dd);
if o.writeCSV
csvseries = [csvseries ...
o.series{i}.data(dd).set_names([...
o.series{i}.data.name{:} '_' ...
o.series{i}.graphLegendName '_' ...
o.series{i}.graphLineColor '_' ...
o.series{i}.graphLineStyle '_' ...
num2str(o.series{i}.graphLineWidth) '_' ...
o.series{i}.graphMarker '_' ...
o.series{i}.graphMarkerEdgeColor '_' ...
o.series{i}.graphMarkerFaceColor '_' ...
num2str(o.series{i}.graphMarkerSize)]) ...
];
end
if o.showLegend
le = o.series{i}.getNameForLegend();
if ~isempty(le)
@ -240,6 +257,9 @@ for i=1:ne
end
end
end
if o.writeCSV
csvseries.save(strrep(o.graphName, '.tex', ''), 'csv');
end
fprintf(fid, '\\end{axis}\n\\end{tikzpicture}%%');
if fclose(fid) == -1
error('@graph.writeGraphFile: closing %s\n', o.filename);

View File

@ -25,7 +25,8 @@ rep = rep.addGraph('title', 'Interest Rate', ...
'showZeroline', true, ...
'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
'xTickLabelRotation', 0);
'xTickLabelRotation', 0, ...
'writeCSV', true);
rep = rep.addSeries('data', db_q{['RS_' countryAbbr]}, ...
'graphLineColor', 'blue', ...
'graphLineStyle', 'dashed', ...