Skip to content

Commit f53c8ef

Browse files
committed
gradient only the fade area
1 parent d42fb9e commit f53c8ef

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/chart/rendering/drawlegend.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,22 @@ void DrawLegend::drawDimension(const Info &info) const
157157
< info.markerWindowRect.y().getMin())
158158
continue;
159159

160+
const auto needGradient =
161+
itemRect.y().getMax()
162+
> info.markerWindowRect.y().getMax() - info.fadeHeight
163+
|| itemRect.y().getMin()
164+
< info.markerWindowRect.y().getMin()
165+
+ info.fadeHeight;
166+
160167
const auto alpha{Math::FuzzyBool{value.second.weight}
161168
&& Math::FuzzyBool{info.weight}};
162169

163170
drawMarker(info,
164171
value.second.categoryValue,
165172
colorBuilder.render(value.second.colorBase)
166173
* double{alpha},
167-
getMarkerRect(info, itemRect));
174+
getMarkerRect(info, itemRect),
175+
needGradient);
168176

169177
value.second.label.visit(
170178
[&](::Anim::InterpolateIndex, const auto &weighted)
@@ -185,7 +193,10 @@ void DrawLegend::drawDimension(const Info &info) const
185193
alpha
186194
&& Math::FuzzyBool{weighted.weight}},
187195
.gradient =
188-
std::ref(info.colorGradientSetter)});
196+
needGradient
197+
? std::ref(info.colorGradientSetter)
198+
: decltype(DrawLabel::Options::
199+
gradient){}});
189200
});
190201
}
191202
}
@@ -222,11 +233,16 @@ Geom::TransformedRect DrawLegend::getLabelRect(const Info &info,
222233
void DrawLegend::drawMarker(const Info &info,
223234
std::string_view categoryValue,
224235
const Gfx::Color &color,
225-
const Geom::Rect &rect) const
236+
const Geom::Rect &rect,
237+
bool needGradient) const
226238
{
227239
info.canvas.save();
228240

229-
info.colorGradientSetter(info.canvas, {}, color);
241+
if (needGradient)
242+
info.colorGradientSetter(info.canvas, {}, color);
243+
else
244+
info.canvas.setBrushColor(color);
245+
230246
info.canvas.setLineColor(color);
231247
info.canvas.setLineWidth(0);
232248

src/chart/rendering/drawlegend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class DrawLegend : public DrawingContext
6464
void drawMarker(const Info &info,
6565
std::string_view categoryValue,
6666
const Gfx::Color &color,
67-
const Geom::Rect &rect) const;
67+
const Geom::Rect &rect,
68+
bool needGradient) const;
6869
[[nodiscard]] static Geom::Rect getItemRect(const Info &info,
6970
double index);
7071
[[nodiscard]] static Geom::Rect getMarkerRect(const Info &info,

0 commit comments

Comments
 (0)