@@ -527,252 +527,3 @@ fun HorizontalBarChart(
527527 }
528528}
529529
530- /* *
531- *
532- * Used to draw the highlighted text
533- * @param identifiedPoint : Selected points
534- * @param selectedOffset: Offset selected
535- * @param barWidth: Width of single bar
536- * @param highlightData: Data for the highlight section
537- * @param selectedXAxisWidth: when data value is present in xAxis [e.g. Horizontal barchart]
538- */
539- private fun DrawScope.drawHighlightText (
540- identifiedPoint : BarData ,
541- selectedOffset : Offset ,
542- barWidth : Dp ,
543- highlightData : SelectionHighlightData ,
544- selectedXAxisWidth : Float = 0f,
545- barChartType : BarChartType
546- ) {
547-
548- val centerPointOfBar =
549- if (barChartType == BarChartType .VERTICAL ) selectedOffset.x + barWidth.toPx() / 2 else selectedOffset.y + barWidth.toPx() / 2
550- // Drawing the highlighted background and text
551- highlightData.drawPopUp(
552- this ,
553- selectedOffset,
554- identifiedPoint,
555- centerPointOfBar,
556- selectedXAxisWidth,
557- barChartType
558- )
559- }
560-
561-
562- /* *
563- *
564- * returns identified point and displaying the data points and highlighted bar .
565- * @param dragLocks : Mutable map of BarData and drawOffset.
566- * @param barHighlightVisibility : Flag to control the visibility of highlighted text.
567- * @param identifiedPoint: selected bar data.
568- * @param barStyle: Data related to the bar graph styling.
569- * @param isDragging : Boolean flag for the dragging status.
570- * @param columnWidth : Width of the Y axis.
571- * @param yBottom : Bottom padding.
572- * @param paddingRight : Right padding.
573- * @param yOffset : Distance between two y points.
574- * @param shouldShowHighlightPopUp : Default true but if highlight popup not required make it false
575- */
576- private fun DrawScope.highlightVerticalBar (
577- dragLocks : MutableMap <Int , Pair <BarData , Offset >>,
578- barHighlightVisibility : Boolean ,
579- identifiedPoint : BarData ,
580- barStyle : BarStyle ,
581- isDragging : Boolean ,
582- columnWidth : Float ,
583- yBottom : Float ,
584- paddingRight : Dp ,
585- yOffset : Float ,
586- shouldShowHighlightPopUp : Boolean = true,
587- selectedXAxisWidth : Float = 0f,
588- barChartType : BarChartType
589- ): BarData {
590- var mutableIdentifiedPoint: BarData = identifiedPoint
591- // Handle the show the selected bar
592- if (isDragging) {
593- val x = dragLocks.values.firstOrNull()?.second?.x
594- if (x != null ) {
595- mutableIdentifiedPoint = dragLocks.values.map { it.first }.first()
596- }
597-
598- // Draw highlight bar on selection
599- if (barStyle.selectionHighlightData?.isHighlightBarRequired == true ) {
600- dragLocks.values.firstOrNull()?.let { (barData, location) ->
601- val (xPoint, yPoint) = location
602- if (xPoint >= columnWidth && xPoint <= size.width - paddingRight.toPx()) {
603- val y1 = yBottom - ((barData.point.y - 0 ) * yOffset)
604- barStyle.selectionHighlightData.drawHighlightBar(
605- this ,
606- xPoint,
607- yPoint,
608- barStyle.barWidth.toPx(),
609- (yBottom - y1),
610- barStyle.selectionHighlightData.barChartType
611- )
612- }
613- }
614- }
615- }
616- if (shouldShowHighlightPopUp) {
617- val selectedOffset = dragLocks.values.firstOrNull()?.second
618- if (barHighlightVisibility && selectedOffset != null && barStyle.selectionHighlightData != null ) {
619- drawHighlightText(
620- mutableIdentifiedPoint,
621- selectedOffset,
622- barStyle.barWidth,
623- barStyle.selectionHighlightData,
624- selectedXAxisWidth,
625- barChartType
626- )
627- }
628- }
629- return mutableIdentifiedPoint
630- }
631-
632- /* *
633- *
634- * returns identified point and displaying the data points and highlighted bar .
635- * @param dragLocks : Mutable map of BarData and drawOffset.
636- * @param barHighlightVisibility : Flag to control the visibility of highlighted text.
637- * @param identifiedPoint: selected bar data.
638- * @param barStyle: Data related to the bar graph styling.
639- * @param isDragging : Boolean flag for the dragging status.
640- * @param columnWidth : Width of the Y axis.
641- * @param yBottom : Bottom padding.
642- * @param paddingRight : Right padding.
643- * @param yOffset : Distance between two y points.
644- * @param shouldShowHighlightPopUp : Default true but if highlight popup not required make it false
645- */
646- private fun DrawScope.highlightHorizontalBar (
647- dragLocks : MutableMap <Int , Pair <BarData , Offset >>,
648- barHighlightVisibility : Boolean ,
649- identifiedPoint : BarData ,
650- barStyle : BarStyle ,
651- isDragging : Boolean ,
652- yBottom : Float ,
653- paddingTop : Dp ,
654- xStart : Float ,
655- xOffset : Float ,
656- shouldShowHighlightPopUp : Boolean = true
657- ): BarData {
658- var mutableIdentifiedPoint: BarData = identifiedPoint
659- // Handle the show the selected bar
660- var selectedXAxisWidth = 0f
661-
662- if (isDragging) {
663- val y = dragLocks.values.firstOrNull()?.second?.y
664- if (y != null ) {
665- mutableIdentifiedPoint = dragLocks.values.map { it.first }.first()
666- }
667-
668- if (barStyle.selectionHighlightData?.isHighlightBarRequired == true ) {
669- dragLocks.values.firstOrNull()?.let { (barData, location) ->
670- val (xPoint, yPoint) = location
671- selectedXAxisWidth =
672- xStart + ((barData.point.x - 0 ) * xOffset) + barStyle.barWidth.toPx()
673- if (yPoint + barStyle.barWidth.toPx() <= yBottom && yPoint >= paddingTop.toPx()) {
674- val x1 = xStart + ((barData.point.x - 0 ) * xOffset)
675- barStyle.selectionHighlightData?.drawHighlightBar?.invoke(
676- this ,
677- xPoint,
678- yPoint,
679- barStyle.barWidth.toPx(),
680- (x1 - xStart),
681- barStyle.selectionHighlightData.barChartType
682- )
683- }
684- }
685- }
686- }
687- if (shouldShowHighlightPopUp) {
688- val selectedOffset = dragLocks.values.firstOrNull()?.second
689- if (barHighlightVisibility && selectedOffset != null && barStyle.selectionHighlightData != null ) {
690- drawHighlightText(
691- mutableIdentifiedPoint,
692- selectedOffset,
693- barStyle.barWidth,
694- barStyle.selectionHighlightData ? : SelectionHighlightData (),
695- selectedXAxisWidth,
696- barStyle.selectionHighlightData.barChartType
697- )
698- }
699- }
700- return mutableIdentifiedPoint
701- }
702-
703-
704- /* *
705- *
706- * DrawScope.drawUnderXAxisScrollMask extension method used for drawing a rectangular mask to make graph scrollable under the XAxis.
707- * @param columnWidth : Width of the rectangular mask here width of Y Axis is used.
708- * @param paddingRight : Padding given at the end of the graph.
709- * @param bgColor : Background of the rectangular mask.
710- */
711- private fun DrawScope.drawUnderXAxisScrollMask (columnWidth : Float , paddingTop : Dp , bgColor : Color ) {
712- // Draw column to make graph look scrollable under Xaxis
713- drawRect(
714- bgColor, Offset (0f , size.height - columnWidth), Size (size.width, columnWidth)
715- )
716- // Draw top padding
717- drawRect(
718- bgColor,
719- Offset (0f , 0f ),
720- Size (size.width, paddingTop.toPx())
721- )
722- }
723-
724- /* *
725- * returns the draw offset for bar graph.
726- * @param point : bar point
727- * @param xMin: Minimum value on the x axis
728- * @param yMin: Minimum value on the y axis
729- * @param xOffset: Distance between bars
730- * @param yOffset: Distance between y axis points
731- * @param xLeft: X starting point of bar graph
732- * @param scrollOffset: Scroll offset
733- * @param yBottom: Y starting point of bar graph
734- */
735- fun getDrawOffset (
736- point : Point ,
737- xMin : Float ,
738- xOffset : Float ,
739- xLeft : Float ,
740- scrollOffset : Float ,
741- yBottom : Float ,
742- yOffset : Float ,
743- yMin : Float ,
744- startDrawPadding : Float ,
745- zoomScale : Float ,
746- barWidth : Float
747- ): Offset {
748- val (x, y) = point
749- val x1 =
750- ((x - xMin) * xOffset) + xLeft + (startDrawPadding * zoomScale) - barWidth / 2 - scrollOffset
751- val y1 = yBottom - ((y - yMin) * yOffset)
752- return Offset (x1, y1)
753- }
754-
755- fun getDrawHorizontalOffset (
756- point : Point ,
757- xLeft : Float ,
758- scrollOffset : Float ,
759- yBottom : Float ,
760- yOffset : Float ,
761- yMin : Float ,
762- yMax : Float ,
763- yStart : Float ,
764- dataCategoryOptions : DataCategoryOptions ,
765- zoomScale : Float
766- ): Offset {
767- val (_, y) = point
768- val x1 = xLeft
769- val y1 =
770- if (dataCategoryOptions.isDataCategoryStartFromBottom) yBottom - yStart - ((y - yMin) * yOffset) + scrollOffset else {
771- if (zoomScale < 1 ) {
772- yBottom - yStart - ((yMax - y) * yOffset) + scrollOffset
773- } else {
774- yStart + ((y - yMin) * yOffset) - scrollOffset
775- }
776- }
777- return Offset (x1, y1)
778- }
0 commit comments