@@ -30,16 +30,19 @@ namespace Vizzu::Draw
3030
3131void DrawInterlacing::drawGeometries (Gen::AxisId axisIndex,
3232 const Math::Range<> &filter,
33+ const Math::Range<> &otherFilter,
3334 const Geom::AffineTransform &tr,
3435 double w) const
3536{
3637 const auto &guides = parent.plot ->guides .at (axisIndex);
3738 const auto &axisStyle = parent.rootStyle .plot .getAxis (axisIndex);
3839 if (axisStyle.interlacing .color ->isTransparent ()
39- || guides.interlacings == false )
40+ || guides.interlacings == false
41+ || Math::Floating::is_zero (otherFilter.size ()))
4042 return ;
4143
42- auto otherWeights = getInterlacingWeights (!axisIndex);
44+ auto otherWeights =
45+ getInterlacingWeights (!axisIndex, otherFilter);
4346 auto &&otherInterlacingColor =
4447 *parent.rootStyle .plot .getAxis (!axisIndex).interlacing .color ;
4548
@@ -101,7 +104,8 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex,
101104void DrawInterlacing::drawTexts (Gen::AxisId axisIndex,
102105 const Math::Range<> &filter,
103106 const Geom::AffineTransform &tr,
104- double w) const
107+ double w,
108+ bool onlyOne) const
105109{
106110 const auto &axis = parent.getAxis (axisIndex).measure ;
107111 auto orientation = !Gen::orientation (axisIndex);
@@ -123,10 +127,45 @@ void DrawInterlacing::drawTexts(Gen::AxisId axisIndex,
123127
124128 if (!needText && !needTick) return ;
125129
130+ std::array<std::array<const DrawAxes::Separator *, 2 >, 2 >
131+ latests{};
132+
133+ if (needText && onlyOne)
134+ for (const auto &sep :
135+ parent.getSeparators (axisIndex, filter)) {
136+ if (!sep.label ) continue ;
137+ if (auto &&cmp = std::weak_order (*sep.label , 0.0 );
138+ !is_eq (cmp)
139+ && (!latests[is_lt (cmp)][0 ]
140+ || std::abs (*latests[is_lt (cmp)][0 ]->label )
141+ < std::abs (*sep.label ))) {
142+ auto &[f, s] = latests[is_lt (cmp)];
143+ if (!s)
144+ s = std::addressof (sep);
145+ else if (std::abs (*s->label ) < std::abs (*sep.label )) {
146+ if (Math::AddTolerance (s->weight + sep.weight )
147+ == 1.0 )
148+ f = s;
149+ else if (f
150+ && Math::AddTolerance (
151+ f->weight + sep.weight )
152+ > 1.0 )
153+ f = nullptr ;
154+ s = std::addressof (sep);
155+ }
156+ else if (Math::AddTolerance (s->weight + sep.weight )
157+ == 1.0 )
158+ f = std::addressof (sep);
159+ }
160+ }
161+
126162 for (const auto &sep : parent.getSeparators (axisIndex, filter)) {
127163 auto tickPos =
128164 Geom::Point::Coord (orientation, origo, sep.position );
129- if (needText && sep.label )
165+ if (needText && sep.label
166+ && (!onlyOne || &sep == latests[0 ][0 ]
167+ || &sep == latests[0 ][1 ] || &sep == latests[1 ][0 ]
168+ || &sep == latests[1 ][1 ]))
130169 drawDataLabel (axis.enabled ,
131170 axisIndex,
132171 tickPos,
@@ -280,9 +319,11 @@ void DrawInterlacing::drawSticks(double tickLength,
280319}
281320
282321std::map<double , double > DrawInterlacing::getInterlacingWeights (
283- Gen::AxisId axisIndex) const
322+ Gen::AxisId axisIndex,
323+ const Math::Range<> &filter) const
284324{
285- std::map<double , double > weights{{0.0 , 0.0 }, {1.0 , 0.0 }};
325+ std::map<double , double > weights{{filter.min , 0.0 },
326+ {filter.max , 0.0 }};
286327
287328 auto &&guides = parent.plot ->guides .at (axisIndex);
288329 auto &&axisStyle = parent.rootStyle .plot .getAxis (axisIndex);
@@ -291,9 +332,12 @@ std::map<double, double> DrawInterlacing::getInterlacingWeights(
291332 return weights;
292333
293334 for (auto &&interval : parent.getIntervals (axisIndex)) {
294- if (Math::Floating::is_zero (interval.isSecond )) continue ;
295- auto min = std::max (interval.range .min , 0.0 );
296- auto max = std::min (interval.range .max , 1.0 );
335+ if (Math::Floating::is_zero (interval.isSecond )
336+ || !interval.range .intersects (filter))
337+ continue ;
338+ auto min = std::max (interval.range .min , filter.min );
339+ auto max = std::min (interval.range .max , filter.max );
340+
297341 auto mprev = std::prev (weights.upper_bound (min));
298342 auto mnext = weights.lower_bound (max);
299343
0 commit comments