@@ -134,14 +134,15 @@ void drawItem::drawLabel()
134134{
135135 if ((double )marker.enabled == 0 ) return ;
136136
137- BlendedDrawItem blended0 (marker,
137+ BlendedDrawItem blended (marker,
138138 options,
139139 diagram.getStyle (),
140140 coordSys,
141141 diagram.getMarkers (),
142142 0 );
143143
144- drawLabel (blended0);
144+ drawLabel (blended, 0 );
145+ drawLabel (blended, 1 );
145146}
146147
147148bool drawItem::shouldDraw ()
@@ -201,16 +202,16 @@ void drawItem::draw(
201202 }
202203}
203204
204- void drawItem::drawLabel (const DrawItem &drawItem)
205+ void drawItem::drawLabel (const DrawItem &drawItem, size_t index )
205206{
206207 if ((double )drawItem.labelEnabled == 0 ) return ;
207208
208- auto color = getColor (drawItem, 1 , true ).second ;
209-
210- auto weight = marker.label .factor ();
209+ auto weight = marker.label .values [index].weight ;
211210 if (weight == 0.0 ) return ;
212211
213- auto text = getLabelText ();
212+ auto color = getColor (drawItem, 1 , true ).second ;
213+
214+ auto text = getLabelText (index);
214215 if (text.empty ()) return ;
215216
216217 auto &labelStyle = style.plot .marker .label ;
@@ -231,52 +232,62 @@ void drawItem::drawLabel(const DrawItem &drawItem)
231232 centered, textColor, bgColor);
232233}
233234
234- std::string drawItem::getLabelText ()
235+ std::string drawItem::getLabelText (size_t index) const
235236{
236237 auto &labelStyle = style.plot .marker .label ;
238+ auto &values = marker.label .values ;
237239
238- const auto &val0 = marker.label .values [0 ];
239- const auto &val1 = marker.label .values [1 ];
240+ auto needsInterpolation = marker.label .count == 2
241+ && (values[0 ].value .continousId
242+ == values[1 ].value .continousId );
240243
241- auto value = marker.label .count == 1 ? val0.value .value :
242- val0.value .value * val0.weight
243- + val1.value .value * val1.weight ;
244+ auto value = needsInterpolation
245+ ? marker.label .combine <double >(
246+ [&](const auto &value){ return value.value ; })
247+ : values[index].value .value ;
244248
245- auto text = Text::SmartString::fromNumber (value,
246- *labelStyle.numberFormat );
249+ std::string valueStr;
250+ if (values[index].value .hasValue ())
251+ {
252+ valueStr = Text::SmartString::fromNumber (value,
253+ *labelStyle.numberFormat );
247254
248- if (val0.value .hasValue
249- && !val0.value .unit .empty ()
250- && *labelStyle.numberFormat != Text::NumberFormat::prefixed)
251- text += " " ;
255+ if (!values[index].value .unit .empty ())
256+ {
257+ if (*labelStyle.numberFormat != Text::NumberFormat::prefixed)
258+ valueStr += " " ;
259+
260+ valueStr += values[index].value .unit ;
261+ }
262+ }
252263
253- auto text0 = val0.value .hasValue ? text + val0.value .unit : std::string ();
254- auto idx0 = val0.value .indexStr ;
264+ auto indexStr = values[index].value .indexStr ;
255265
256266 // todo: interpolate Format
257267 typedef Styles::MarkerLabel::Format Format;
258268 switch ((Format)*labelStyle.format )
259269 {
260270 default :
261- case Format::measureFirst:
262- if (!idx0.empty ())
271+ case Format::measureFirst: {
272+ auto text = valueStr;
273+ if (!indexStr.empty ())
263274 {
264- if (!text0 .empty ()) text0 += " , " ;
265- text0 += idx0 ;
275+ if (!text .empty ()) text += " , " ;
276+ text += indexStr ;
266277 }
267- text = text0 ;
268- break ;
278+ return text ;
279+ }
269280
270- case Format::dimensionsFirst:
271- if (!text0.empty ())
281+ case Format::dimensionsFirst: {
282+ auto text = indexStr;
283+ if (!valueStr.empty ())
272284 {
273- if (!idx0 .empty ()) idx0 += " , " ;
274- idx0 += text0 ;
285+ if (!text .empty ()) text += " , " ;
286+ text += valueStr ;
275287 }
276- text = idx0 ;
277- break ;
288+ return text ;
289+ }
278290 }
279- return text;
280291}
281292
282293std::pair<Gfx::Color, Gfx::Color> drawItem::getColor (
0 commit comments