Skip to content

Commit

Permalink
PlotAxisLabeled: new options majorTickSpacing, minorTickSpacing, grid…
Browse files Browse the repository at this point in the history
…LineSpacing.
  • Loading branch information
tmayerguerr committed Dec 2, 2024
1 parent e1d7c4e commit d3983f2
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- New program: Conversion: OceanTidesDTU2GriddedData.
- New class: PlotDegreeAmplitudes: degreeAmplitudesSimple.
- New option: GnssAntennaNormalsConstraint: gnssType selection for TEC constraint.
- New option: PlotAxisLabeled: majorTickSpacing, minorTickSpacing, gridLineSpacing.
- File format: TideGeneratingPotential includes now degree 3 tides.
- Bugfix: GUI: fixed Ctrl+Shift+Up/Down for variables.
- Bugfix: slrParametrizationRangeBiasStationSatellite: Fix station index.
Expand Down
Binary file modified docs/documentation.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/html/documentationSearchIndex.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions docs/html/plotAxisType.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ <h2>Labeled</h2><p>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config mustset-unbounded">labels</div></div></td><td>string</td><td>tick labels (ticks are placed at their index. e.g. 0, 1, ..., 5)</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">min</div></div></td><td>expression</td><td>minimum value of the axis</td></tr>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">max</div></div></td><td>expression</td><td>maximum values of the axis</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">orthogonalLabels</div></div></td><td>boolean</td><td>labels are oriented orthogonal to axis</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">majorTickSpacing</div></div></td><td>expression</td><td>The boundary annotation.</td></tr>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">minorTickSpacing</div></div></td><td>expression</td><td>The spacing of the frame tick intervals.</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">gridLineSpacing</div></div></td><td>expression</td><td>The spacing of the grid line intervals</td></tr>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">gridLine</div></div></td><td><a href="plotLineType.html">plotLine</a></td><td>The style of the grid lines.</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config mustset">color</div></div></td><td><a href="plotColorType.html">plotColor</a></td><td>set the color of the axis and labels</td></tr>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">changeDirection</div></div></td><td>boolean</td><td>If set to 'yes', the directions right/up are changed to left/down.</td></tr>
<tr class="table-light"><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">orthogonalLabels</div></div></td><td>boolean</td><td>labels are oriented orthogonal to axis</td></tr>
<tr class=""><td class="m-0"><div class="h-100 config-tree depth-0"><div class="h-100 config optional">changeDirection</div></div></td><td>boolean</td><td>If set to 'yes', the directions right/up are changed to left/down.</td></tr>
</table>

</div>
Expand Down
5 changes: 4 additions & 1 deletion docs/latex/classes.auto.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7140,9 +7140,12 @@ \subsection{Labeled}
\hfuzz=500pt\includegraphics[width=1em]{element-mustset-unbounded.pdf}~labels & \hfuzz=500pt string & \hfuzz=500pt tick labels (ticks are placed at their index. e.g. 0, 1, ..., 5)\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~min & \hfuzz=500pt expression & \hfuzz=500pt minimum value of the axis\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~max & \hfuzz=500pt expression & \hfuzz=500pt maximum values of the axis\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~orthogonalLabels & \hfuzz=500pt boolean & \hfuzz=500pt labels are oriented orthogonal to axis\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~majorTickSpacing & \hfuzz=500pt expression & \hfuzz=500pt The boundary annotation.\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~minorTickSpacing & \hfuzz=500pt expression & \hfuzz=500pt The spacing of the frame tick intervals.\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~gridLineSpacing & \hfuzz=500pt expression & \hfuzz=500pt The spacing of the grid line intervals\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~gridLine & \hfuzz=500pt \hyperref[plotLineType]{plotLine} & \hfuzz=500pt The style of the grid lines.\\
\hfuzz=500pt\includegraphics[width=1em]{element-mustset.pdf}~color & \hfuzz=500pt \hyperref[plotColorType]{plotColor} & \hfuzz=500pt set the color of the axis and labels\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~orthogonalLabels & \hfuzz=500pt boolean & \hfuzz=500pt labels are oriented orthogonal to axis\\
\hfuzz=500pt\includegraphics[width=1em]{element.pdf}~changeDirection & \hfuzz=500pt boolean & \hfuzz=500pt If set to 'yes', the directions right/up are changed to left/down.\\
\hline
\end{tabularx}
Expand Down
19 changes: 17 additions & 2 deletions groops.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -7898,9 +7898,19 @@
<xs:documentation>maximum values of the axis</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="orthogonalLabels" type="boolean" minOccurs="0" default="0">
<xs:element name="majorTickSpacing" type="expression" minOccurs="0" default="1">
<xs:annotation>
<xs:documentation>labels are oriented orthogonal to axis</xs:documentation>
<xs:documentation>The boundary annotation.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="minorTickSpacing" type="expression" minOccurs="0" default="1">
<xs:annotation>
<xs:documentation>The spacing of the frame tick intervals.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="gridLineSpacing" type="expression" minOccurs="0" default="1">
<xs:annotation>
<xs:documentation>The spacing of the grid line intervals</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="gridLine" type="plotLineType" minOccurs="0" default="{&quot;solid&quot;: {&quot;width&quot;:&quot;0.25&quot;, &quot;color&quot;:&quot;gray&quot;}}">
Expand All @@ -7913,6 +7923,11 @@
<xs:documentation>set the color of the axis and labels</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="orthogonalLabels" type="boolean" minOccurs="0" default="0">
<xs:annotation>
<xs:documentation>labels are oriented orthogonal to axis</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="changeDirection" type="boolean" minOccurs="0" default="0">
<xs:annotation>
<xs:documentation>If set to &apos;yes&apos;, the directions right/up are changed to left/down.</xs:documentation>
Expand Down
66 changes: 51 additions & 15 deletions source/plot/plotAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,13 @@ Axis with string labels. The coordinate system is based on the label indices (e.
class PlotAxisLabeled : public PlotAxis
{
std::vector<std::string> labels;
Double annotation, frame, grid;
Bool orthoLabels;
FileName dataFileName;

public:
PlotAxisLabeled(Config &config);
void setAutoInterval(Double /*minAuto*/, Double /*maxAuto*/) {}
void setAutoInterval(Double minAuto, Double maxAuto);
void writeDataFile(const FileName &workingDirectory, const std::string &axis);
std::string axisModifier() const {return "";}
std::string scriptEntry(const std::string &axis, Bool withGrid) const;
Expand All @@ -332,24 +333,49 @@ PlotAxisLabeled::PlotAxisLabeled(Config &config)
{
try
{
ExpressionVariablePtr exprMin, exprMax;
ExpressionVariablePtr exprMin, exprMax, exprAnnotation, exprFrame, exprGrid;
vMin = vMax = NAN_EXPR;
annotation = 1;
frame = 1;
grid = 1;

readConfig(config, "labels", labels, Config::MUSTSET, "", "tick labels (ticks are placed at their index. e.g. 0, 1, ..., 5)");
readConfig(config, "min", exprMin, Config::DEFAULT, "0", "minimum value of the axis");
readConfig(config, "max", exprMax, Config::DEFAULT, "labelCount-1", "maximum values of the axis");
readConfig(config, "orthogonalLabels", orthoLabels, Config::DEFAULT, "0", "labels are oriented orthogonal to axis");
readConfig(config, "min", exprMin, Config::OPTIONAL, "0", "minimum value of the axis");
readConfig(config, "max", exprMax, Config::OPTIONAL, "labelCount-1", "maximum values of the axis");
readConfig(config, "majorTickSpacing", exprAnnotation, Config::OPTIONAL, "1", "The boundary annotation.");
readConfig(config, "minorTickSpacing", exprFrame, Config::OPTIONAL, "1", "The spacing of the frame tick intervals.");
readConfig(config, "gridLineSpacing", exprGrid, Config::OPTIONAL, "1", "The spacing of the grid line intervals");
readConfig(config, "gridLine", gridLine, Config::OPTIONAL, R"({"solid": {"width":"0.25", "color":"gray"}})", "The style of the grid lines.");
readConfig(config, "color", color, Config::MUSTSET, "", "set the color of the axis and labels");
readConfig(config, "orthogonalLabels", orthoLabels, Config::DEFAULT, "0", "labels are oriented orthogonal to axis");
readConfig(config, "changeDirection", changeDirection, Config::DEFAULT, "0", "If set to 'yes', the directions right/up are changed to left/down.");
if(isCreateSchema(config)) return;

margin = 0.5;

VariableList fileNameVariableList;
fileNameVariableList.setVariable("labelCount", static_cast<Double>(labels.size()));
VariableList variableList;
variableList.setVariable("labelCount", static_cast<Double>(labels.size()));
if(exprMin) vMin = exprMin->evaluate(variableList) - 0.5;
if(exprMax) vMax = exprMax->evaluate(variableList) + 0.5;
if(exprAnnotation) annotation = exprAnnotation->evaluate(variableList);
if(exprFrame) frame = exprFrame->evaluate(variableList);
if(exprGrid) grid = exprGrid->evaluate(variableList);
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}

/***********************************************/

vMin = exprMin->evaluate(fileNameVariableList) - 0.5;
vMax = exprMax->evaluate(fileNameVariableList) + 0.5;
void PlotAxisLabeled::setAutoInterval(Double minAuto, Double maxAuto)
{
try
{
if(minAuto > maxAuto) std::swap(minAuto, maxAuto);
if(std::isnan(vMin)) vMin = minAuto;
if(std::isnan(vMax)) vMax = maxAuto;
}
catch(std::exception &e)
{
Expand All @@ -363,14 +389,24 @@ void PlotAxisLabeled::writeDataFile(const FileName &workingDirectory, const std:
{
try
{
std::vector<std::pair<Double, std::string>> lines;
for(UInt k=0; k<labels.size(); k++)
if((vMin <= k) && (k <= vMax) && (std::fmod(k, annotation) == 0))
lines.push_back(std::pair<Double, std::string>(k, " a "s+labels.at(k)));

if(frame > 0)
for(Double k=vMin-std::fmod(vMin, frame); k<=vMax; k+=frame)
lines.push_back(std::pair<Double, std::string>(k, " f"));

if(gridLine && (grid > 0))
for(Double k=vMin-std::fmod(vMin, grid); k<=vMax; k+=grid)
lines.push_back(std::pair<Double, std::string>(k, " g"));

std::sort(lines.begin(), lines.end(), [](auto &a, auto &b){return a.first < b.first;});
dataFileName = "labels."+axis+".txt";
OutFile file(workingDirectory.append(dataFileName));
for(UInt k=0; k<labels.size(); k++)
if((k >= vMin) && (k <= vMax))
{
file<<k<<" a "<<labels.at(k)<<std::endl;
if(gridLine) file<<k<<" g"<<std::endl;
}
for(auto &line : lines)
file<<line.first<<line.second<<std::endl;
}
catch(std::exception &e)
{
Expand Down

0 comments on commit d3983f2

Please sign in to comment.