Skip to content

Commit 0912a6e

Browse files
committed
Merge remote-tracking branch 'origin/main' into dim_dim_on_x_y
2 parents 901cd78 + 573e50b commit 0912a6e

File tree

11 files changed

+71
-65
lines changed

11 files changed

+71
-65
lines changed

src/base/anim/interpolated.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ template <typename Type> class Weighted
4141
[[nodiscard]] bool hasValue() const { return weight > 0.0; }
4242
};
4343

44-
enum class InterpolateIndex : bool {
45-
first = false,
46-
secondIfExists = true
47-
};
44+
enum class InterpolateIndex : bool { first = false, second = true };
4845

4946
using enum InterpolateIndex;
5047

@@ -125,7 +122,7 @@ template <typename Type> class Interpolated
125122
throw std::logic_error("Invalid Weigthed Pair");
126123
}
127124

128-
[[nodiscard]] const Weighted<Type> &get(
125+
[[nodiscard]] const Weighted<Type> &get_or_first(
129126
InterpolateIndex index) const
130127
{
131128
return values[has_second && static_cast<bool>(index)];
@@ -175,7 +172,7 @@ template <typename Type> class Interpolated
175172
{
176173
if (values[0].hasValue()) branch(first, values[0]);
177174
if (has_second && values[1].hasValue())
178-
branch(secondIfExists, values[1]);
175+
branch(second, values[1]);
179176
}
180177

181178
template <class T, class Fun> T combine(Fun &&branch) const

src/chart/generator/axis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct DimensionAxis
133133
::Anim::InterpolateIndex index) const
134134
{
135135
return (index == ::Anim::first && start)
136-
|| (index == ::Anim::secondIfExists && end);
136+
|| (index == ::Anim::second && end);
137137
}
138138
};
139139
using Values = std::multimap<Data::SliceIndex, Item>;

src/chart/generator/plot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void Plot::clearEmptyBuckets(const Buckets &buckets, bool main) const
207207

208208
void Plot::addSpecLayout(Buckets &buckets)
209209
{
210-
auto geometry = getOptions()->geometry.get(::Anim::first).value;
210+
auto geometry =
211+
getOptions()->geometry.get_or_first(::Anim::first).value;
211212
if (auto &markers = getMarkers();
212213
geometry == ShapeType::line || geometry == ShapeType::area) {
213214
Charts::TableChart::setupVector(markers, true);

src/chart/main/style.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ struct Font
105105
[[nodiscard]] std::string calculatedFamily() const
106106
{
107107
if (fontFamily.has_value())
108-
if (auto &&ff = fontFamily->get(::Anim::first).value;
108+
if (auto &&ff =
109+
fontFamily->get_or_first(::Anim::first).value;
109110
!ff.empty())
110111
return ff;
111112

src/chart/rendering/colorbuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ ColorBuilder::ColorBuilder(const LighnessRange &lighnessRange,
1717
Gfx::Color ColorBuilder::render(
1818
const Anim::Interpolated<Gen::ColorBase> &colorBase) const
1919
{
20-
if (!colorBase.get(::Anim::first).value.isDiscrete()
21-
&& !colorBase.get(::Anim::secondIfExists)
20+
if (!colorBase.get_or_first(::Anim::first).value.isDiscrete()
21+
&& !colorBase.get_or_first(::Anim::second)
2222
.value.isDiscrete()) {
2323
auto pos = colorBase.combine<double>(
2424
[](const Gen::ColorBase &base)

src/chart/rendering/drawaxes.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Geom::Point DrawAxes::getTitleBasePos(Gen::ChannelId axisIndex,
9090

9191
double orthogonal{0.0};
9292

93-
switch (titleStyle.position->get(index).value) {
93+
switch (titleStyle.position->get_or_first(index).value) {
9494
default:
9595
case Pos::min_edge: break;
9696
case Pos::max_edge: orthogonal = 1.0; break;
@@ -101,7 +101,7 @@ Geom::Point DrawAxes::getTitleBasePos(Gen::ChannelId axisIndex,
101101

102102
double parallel{0.0};
103103

104-
switch (titleStyle.vposition->get(index).value) {
104+
switch (titleStyle.vposition->get_or_first(index).value) {
105105
default:
106106
case VPos::end: parallel = 1.0; break;
107107
case VPos::middle: parallel = 0.5; break;
@@ -130,9 +130,9 @@ Geom::Point DrawAxes::getTitleOffset(Gen::ChannelId axisIndex,
130130
}
131131
};
132132

133-
auto orthogonal = fades
134-
? calcSide(titleStyle.side->get(index).value)
135-
: titleStyle.side->combine<double>(calcSide);
133+
auto orthogonal =
134+
fades ? calcSide(titleStyle.side->get_or_first(index).value)
135+
: titleStyle.side->combine<double>(calcSide);
136136

137137
auto calcVSide = [](const auto &side)
138138
{
@@ -145,9 +145,9 @@ Geom::Point DrawAxes::getTitleOffset(Gen::ChannelId axisIndex,
145145
}
146146
};
147147

148-
auto parallel = fades
149-
? calcVSide(titleStyle.vside->get(index).value)
150-
: titleStyle.vside->combine<double>(calcVSide);
148+
auto parallel =
149+
fades ? calcVSide(titleStyle.vside->get_or_first(index).value)
150+
: titleStyle.vside->combine<double>(calcVSide);
151151

152152
return axisIndex == Gen::ChannelId::x
153153
? Geom::Point{parallel, -orthogonal}
@@ -165,12 +165,13 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const
165165
|| titleString.maxIndex();
166166

167167
for (auto &&index : Type::Bools{fades}) {
168-
auto title = titleString.get(index);
168+
auto title = titleString.get_or_first(index);
169169
if (title.value.empty()) continue;
170170

171-
auto weight = title.weight
172-
* titleStyle.position->get(index).weight
173-
* titleStyle.vposition->get(index).weight;
171+
auto weight =
172+
title.weight
173+
* titleStyle.position->get_or_first(index).weight
174+
* titleStyle.vposition->get_or_first(index).weight;
174175

175176
const Gfx::Font font(titleStyle);
176177
canvas.setFont(font);
@@ -182,9 +183,8 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const
182183

183184
auto normal = Geom::Point::Ident(true);
184185

185-
auto offset = getTitleOffset(axisIndex,
186-
index,
187-
fades == ::Anim::secondIfExists);
186+
auto offset =
187+
getTitleOffset(axisIndex, index, fades == ::Anim::second);
188188

189189
auto posDir = coordSys.convertDirectionAt(
190190
{relCenter, relCenter + normal});
@@ -207,16 +207,17 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const
207207

208208
auto angle =
209209
-M_PI / 2.0
210-
* (fades == ::Anim::secondIfExists
211-
? titleStyle.orientation->get(index).value
210+
* (fades == ::Anim::second
211+
? titleStyle.orientation->get_or_first(index)
212+
.value
212213
== Styles::AxisTitle::Orientation::vertical
213214
: titleStyle.orientation->factor<double>(
214215
Styles::AxisTitle::Orientation::vertical));
215216

216217
auto orientedSize =
217-
fades == ::Anim::secondIfExists
218+
fades == ::Anim::second
218219
? calcOrientation(
219-
titleStyle.orientation->get(index).value)
220+
titleStyle.orientation->get_or_first(index).value)
220221
: titleStyle.orientation->combine<Geom::Size>(
221222
calcOrientation);
222223

@@ -315,11 +316,12 @@ void DrawAxes::drawDimensionLabel(bool horizontal,
315316
auto relCenter =
316317
refPos + ident * it->second.range.middle();
317318

318-
auto under = labelStyle.position->interpolates()
319-
? labelStyle.side->get(index).value
320-
== Styles::AxisLabel::Side::negative
321-
: labelStyle.side->factor<double>(
322-
Styles::AxisLabel::Side::negative);
319+
auto under =
320+
labelStyle.position->interpolates()
321+
? labelStyle.side->get_or_first(index).value
322+
== Styles::AxisLabel::Side::negative
323+
: labelStyle.side->factor<double>(
324+
Styles::AxisLabel::Side::negative);
323325

324326
auto sign = 1 - 2 * under;
325327

@@ -347,15 +349,16 @@ void DrawAxes::drawDimensionLabel(bool horizontal,
347349

348350
if (labelStyle.position->interpolates()
349351
&& text.interpolates())
350-
draw(text.get(index), position.weight);
352+
draw(text.get_or_first(index), position.weight);
351353
if (!labelStyle.position->interpolates()
352354
&& !text.interpolates())
353-
draw(text.get(::Anim::first));
355+
draw(text.get_or_first(::Anim::first));
354356
else if (labelStyle.position->interpolates())
355-
draw(text.get(::Anim::first), position.weight);
357+
draw(text.get_or_first(::Anim::first),
358+
position.weight);
356359
else if (text.interpolates()) {
357-
draw(text.get(::Anim::first));
358-
draw(text.get(::Anim::secondIfExists));
360+
draw(text.get_or_first(::Anim::first));
361+
draw(text.get_or_first(::Anim::second));
359362
}
360363
});
361364
}

src/chart/rendering/drawinterlacing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ void DrawInterlacing::drawDataLabel(
239239
auto &&normal = Geom::Point::Ident(horizontal);
240240
for (auto &&index : Type::Bools{interpolates}) {
241241
if (labelStyle.position->interpolates()
242-
&& !axisEnabled.get(index).value)
242+
&& !axisEnabled.get_or_first(index).value)
243243
continue;
244-
auto &&position = labelStyle.position->get(index);
244+
auto &&position = labelStyle.position->get_or_first(index);
245245

246246
Geom::Point refPos = tickPos;
247247

@@ -253,7 +253,7 @@ void DrawInterlacing::drawDataLabel(
253253
}
254254

255255
auto under = labelStyle.position->interpolates()
256-
? labelStyle.side->get(index).value
256+
? labelStyle.side->get_or_first(index).value
257257
== Styles::AxisLabel::Side::negative
258258
: labelStyle.side->factor<double>(
259259
Styles::AxisLabel::Side::negative);
@@ -262,7 +262,7 @@ void DrawInterlacing::drawDataLabel(
262262
coordSys.convertDirectionAt({refPos, refPos + normal})
263263
.extend(1 - 2 * under);
264264

265-
auto &&wUnit = unit.get(index);
265+
auto &&wUnit = unit.get_or_first(index);
266266
auto str = Text::SmartString::fromPhysicalValue(value,
267267
*labelStyle.numberFormat,
268268
static_cast<size_t>(*labelStyle.maxFractionDigits),

src/chart/rendering/drawmarkerinfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,15 @@ void DrawMarkerInfo::draw(Gfx::ICanvas &canvas,
188188
const Geom::Rect &boundary) const
189189
{
190190
for (const auto &info : plot->getMarkersInfo()) {
191-
auto &&[cnt1, weight1] = info.second.get(::Anim::first);
191+
auto &&[cnt1, weight1] =
192+
info.second.get_or_first(::Anim::first);
192193
if (!info.second.interpolates() && cnt1) {
193194
MarkerDC dc(*this, canvas, boundary, cnt1);
194195
dc.draw(weight1);
195196
}
196197
else if (info.second.interpolates()) {
197198
auto &&[cnt2, weight2] =
198-
info.second.get(::Anim::secondIfExists);
199+
info.second.get_or_first(::Anim::second);
199200
if (!cnt1 && cnt2)
200201
fadeInMarkerInfo(canvas, boundary, cnt2, weight2);
201202
else if (cnt1 && !cnt2)

src/chart/rendering/markerrenderer.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
118118
&value = ::Anim::Weighted(
119119
Gen::Options::MarkerIndex{}))
120120
{
121-
if (index == ::Anim::secondIfExists && !other) {
121+
if (index == ::Anim::second && !other) {
122122
other.emplace(
123123
AbstractMarker::createInterpolated(ctx(),
124124
blended.marker,
125-
::Anim::secondIfExists));
125+
::Anim::second));
126126
}
127-
const auto &blended0 = index == ::Anim::secondIfExists
128-
? *other
129-
: blended;
127+
const auto &blended0 =
128+
index == ::Anim::second ? *other : blended;
130129

131130
auto lineFactor =
132131
getOptions().geometry.factor<double>(
@@ -160,10 +159,10 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
160159
auto lineIndex =
161160
Gen::isConnecting(
162161
getOptions()
163-
.geometry.get(::Anim::first)
162+
.geometry.get_or_first(::Anim::first)
164163
.value)
165164
? ::Anim::first
166-
: ::Anim::secondIfExists;
165+
: ::Anim::second;
167166

168167
drawMarker(lineIndex);
169168
}
@@ -185,14 +184,14 @@ void MarkerRenderer::drawLabels(Gfx::ICanvas &canvas) const
185184
if (blended.marker.enabled == false) continue;
186185
drawLabel(canvas,
187186
blended,
188-
axis.unit.get(::Anim::first).value,
187+
axis.unit.get_or_first(::Anim::first).value,
189188
keepMeasure,
190189
::Anim::first);
191190
drawLabel(canvas,
192191
blended,
193-
axis.unit.get(::Anim::secondIfExists).value,
192+
axis.unit.get_or_first(::Anim::second).value,
194193
keepMeasure,
195-
::Anim::secondIfExists);
194+
::Anim::second);
196195
}
197196
}
198197

@@ -211,7 +210,7 @@ bool MarkerRenderer::shouldDrawMarkerBody(
211210
enabled |= prev0->enabled != false;
212211
if (const auto *prev1 = ConnectingMarker::getPrev(marker,
213212
plot->getMarkers(),
214-
::Anim::secondIfExists))
213+
::Anim::second))
215214
enabled |= prev1->enabled != false;
216215
}
217216
return enabled;
@@ -302,7 +301,7 @@ void MarkerRenderer::drawLabel(Gfx::ICanvas &canvas,
302301

303302
auto weight =
304303
marker.label.interpolates() || index == ::Anim::first
305-
? marker.label.get(index).weight
304+
? marker.label.get_or_first(index).weight
306305
: 0.0;
307306
if (weight == 0.0) return;
308307

@@ -342,7 +341,7 @@ std::string MarkerRenderer::getLabelText(
342341
::Anim::InterpolateIndex index) const
343342
{
344343
const auto &labelStyle = rootStyle.plot.marker.label;
345-
const auto &labelValue = label.get(index).value;
344+
const auto &labelValue = label.get_or_first(index).value;
346345

347346
auto needsInterpolation = label.interpolates() && keepMeasure;
348347

src/chart/rendering/markers/abstractmarker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ AbstractMarker AbstractMarker::createInterpolated(
4040
{
4141
const auto &options = ctx.getOptions();
4242

43-
auto fromShapeType = options.geometry.get(::Anim::first).value;
43+
auto fromShapeType =
44+
options.geometry.get_or_first(::Anim::first).value;
4445

4546
auto fromMarker = create(ctx, marker, fromShapeType, lineIndex);
4647

4748
auto toShapeType =
48-
options.geometry.get(::Anim::secondIfExists).value;
49+
options.geometry.get_or_first(::Anim::second).value;
4950

5051
if (fromShapeType == toShapeType) return fromMarker;
5152

0 commit comments

Comments
 (0)