@@ -265,7 +265,7 @@ fun LineChart(
265265 .weight(1f )
266266 .fillMaxSize()
267267 .pointerInput(data, minValue, maxValue, linesPathData) {
268- if (! popupProperties.enabled) return @pointerInput
268+ if (! popupProperties.enabled || data.all { it.popupProperties?.enabled == false } ) return @pointerInput
269269 detectHorizontalDragGestures(
270270 onDragEnd = {
271271 scope.launch {
@@ -280,66 +280,68 @@ fun LineChart(
280280 popups.clear()
281281 data.forEachIndexed { dataIndex, line ->
282282 val properties = line.popupProperties ? : popupProperties
283-
284- val positionX =
285- (change.position.x).coerceIn(
286- 0f ,
287- size.width.toFloat()
288- )
289- val pathData = linesPathData[dataIndex]
290-
291- if (positionX >= pathData.xPositions[pathData.startIndex] && positionX <= pathData.xPositions[pathData.endIndex]) {
292- val showOnPointsThreshold =
293- ((properties.mode as ? PopupProperties .Mode .PointMode )?.threshold
294- ? : 0 .dp).toPx()
295- val pointX =
296- pathData.xPositions.find { it in positionX - showOnPointsThreshold.. positionX + showOnPointsThreshold }
297-
298- if (properties.mode !is PopupProperties .Mode .PointMode || pointX != null ) {
299- val fraction =
300- ((if (properties.mode is PopupProperties .Mode .PointMode ) (pointX?.toFloat()
301- ? : 0f ) else positionX) / size.width)
302-
303- // Calculate the data index
304- val valueIndex = calculateValueIndex(
305- fraction = fraction.toDouble(),
306- values = line.values,
307- pathData = pathData
283+ if (properties.enabled){
284+ val positionX =
285+ (change.position.x).coerceIn(
286+ 0f ,
287+ size.width.toFloat()
308288 )
289+ val pathData = linesPathData[dataIndex]
290+
291+ if (positionX >= pathData.xPositions[pathData.startIndex] && positionX <= pathData.xPositions[pathData.endIndex]) {
292+ val showOnPointsThreshold =
293+ ((properties.mode as ? PopupProperties .Mode .PointMode )?.threshold
294+ ? : 0 .dp).toPx()
295+ val pointX =
296+ pathData.xPositions.find { it in positionX - showOnPointsThreshold.. positionX + showOnPointsThreshold }
297+
298+ if (properties.mode !is PopupProperties .Mode .PointMode || pointX != null ) {
299+ val fraction =
300+ ((if (properties.mode is PopupProperties .Mode .PointMode ) (pointX?.toFloat()
301+ ? : 0f ) else positionX) / size.width)
302+
303+ // Calculate the data index
304+ val valueIndex = calculateValueIndex(
305+ fraction = fraction.toDouble(),
306+ values = line.values,
307+ pathData = pathData
308+ )
309309
310- val popupValue = getPopupValue(
311- points = line.values,
312- fraction = fraction.toDouble(),
313- rounded = line.curvedEdges ? : curvedEdges,
314- size = _size ,
315- minValue = minValue,
316- maxValue = maxValue
317- )
318- popups.add(
319- Popup (
320- position = popupValue.offset,
321- value = popupValue.calculatedValue,
322- properties = properties,
323- dataIndex = dataIndex,
324- valueIndex = valueIndex
310+ val popupValue = getPopupValue(
311+ points = line.values,
312+ fraction = fraction.toDouble(),
313+ rounded = line.curvedEdges ? : curvedEdges,
314+ size = _size ,
315+ minValue = minValue,
316+ maxValue = maxValue
325317 )
326- )
327- if (popupsOffsetAnimators.count() < popups.count()) {
328- repeat(popups.count() - popupsOffsetAnimators.count()) {
329- popupsOffsetAnimators.add(
330- // add fixed position for popup when mode is point mode
331- if (properties.mode is PopupProperties .Mode .PointMode ) {
332- Animatable (popupValue.offset.x) to Animatable (
333- popupValue.offset.y
334- )
335- } else {
336- Animatable (0f ) to Animatable (0f )
337- }
318+ popups.add(
319+ Popup (
320+ position = popupValue.offset,
321+ value = popupValue.calculatedValue,
322+ properties = properties,
323+ dataIndex = dataIndex,
324+ valueIndex = valueIndex
338325 )
326+ )
327+ if (popupsOffsetAnimators.count() < popups.count()) {
328+ repeat(popups.count() - popupsOffsetAnimators.count()) {
329+ popupsOffsetAnimators.add(
330+ // add fixed position for popup when mode is point mode
331+ if (properties.mode is PopupProperties .Mode .PointMode ) {
332+ Animatable (popupValue.offset.x) to Animatable (
333+ popupValue.offset.y
334+ )
335+ } else {
336+ Animatable (0f ) to Animatable (0f )
337+ }
338+ )
339+ }
339340 }
340341 }
341342 }
342343 }
344+
343345 }
344346 scope.launch {
345347 // animate popup (alpha)
0 commit comments