Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrackballBehavior.builder not work #2222

Open
chani22 opened this issue Dec 22, 2024 · 0 comments
Open

TrackballBehavior.builder not work #2222

chani22 opened this issue Dec 22, 2024 · 0 comments

Comments

@chani22
Copy link

chani22 commented Dec 22, 2024

Bug description

When I don't define a builder, the trackball contents are displayed normally; however, when I define a builder myself, only the vertical line appears and the widget I created is not shown.

I use 28.1.35 version of syncfusion_flutter_charts

syncfusion_flutter_charts: ^28.1.35

Steps to reproduce

I was creating a chart using SfCartesianChart. I wanted to display detailed information about a specific x-axis using TrackballBehavior, and I was using TrackballDisplayMode.groupAllPoints to show the trackball content. Everything worked as expected until I defined a builder. However, the moment I explicitly defined a builder to change the monetary format in the trackball content, only the trackball’s vertical line appeared, and the detailed information did not show up. After checking the logs, I confirmed that all necessary data was successfully obtained from trackballDetails, leading me to suspect there is a bug with rendering the widget.

Code sample

Code sample
SfCartesianChart(
  legend: Legend(
    isVisible: true,
    position: LegendPosition.bottom
  ),
  trackballBehavior: TrackballBehavior(
    enable: true,
    activationMode: ActivationMode.singleTap,
    tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
    builder: (BuildContext context, TrackballDetails trackballDetails) {
      final grouping = trackballDetails.groupingModeInfo;
      if (grouping == null) {
        print("grouping == null");
        return const SizedBox.shrink();
      }

      final points = grouping.points;
      final seriesList = grouping.visibleSeriesList;

      if (points.isEmpty) {
        print("points.isEmpty");
        return const SizedBox.shrink();
      }

      final firstPoint = points.first;
      final xVal = firstPoint.x; 
      final headerText = xVal?.toString() ?? '';
      print("headerText = $headerText");

      final rowWidgets = <Widget>[];
      for (int i = 0; i < points.length; i++) {
        final CartesianChartPoint point = points[i];
        final dynamic series = i < seriesList.length ? seriesList[i] : null;

        final seriesName = (series?.name ?? '').toString();

        Color seriesColor = Colors.grey;
        if (series is XyDataSeries) {
          seriesColor = series.color ?? Colors.grey;
        }

        final yVal = point.y;
        if (yVal == null) continue;

        String displayValue;
        if (seriesName == '수납률') {
          displayValue = '${yVal.toStringAsFixed(0)}%';
        } else {
          displayValue = StringUtil.currencyFormat(yVal.toInt());
        }
        print("seriesName = $seriesName");
        print("displayValue = $displayValue");

        rowWidgets.add(_buildTrackballItem(seriesName, displayValue, seriesColor));
      }

      return Container(
        padding: const EdgeInsets.all(8),
        decoration: BoxDecoration(
          color: Colors.black87,
          borderRadius: BorderRadius.circular(6),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              headerText,
              style: const TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.bold,
              ),
            ),
            const Divider(color: Colors.white54),
            ...rowWidgets,
          ],
        ),
      );
    },
    hideDelay: 3000
  ),
  primaryXAxis: CategoryAxis(
    axisLabelFormatter: (AxisLabelRenderDetails args) {
      final String originalText = args.text;
      String resultText = originalText;

      final regex = RegExp(r'^(\d{4})년\s*(\d{1,2})월$');
      final match = regex.firstMatch(originalText);
      if (match != null) {
        final yearString = match.group(1)!;  // 그룹 1: 년도
        final monthString = match.group(2)!; // 그룹 2: 월

        final year = int.parse(yearString);
        final month = int.parse(monthString);

        if (thisMonth.year == year) {
          resultText = "$month월";
        } else {
          resultText = "${year % 100}-$month";
        }
      }

      return ChartAxisLabel(
        resultText,
        args.textStyle
      );
    },
  ),
  primaryYAxis: NumericAxis(
    axisLabelFormatter: (AxisLabelRenderDetails details) {
      final num valueInManWon = details.value / 10000; 
      final labelString = valueInManWon.toStringAsFixed(0);
      return ChartAxisLabel(labelString, details.textStyle);
    },
  ),
  axes: <ChartAxis>[
    NumericAxis(
      name: 'percentageAxis', // 이 이름을 시리즈에서 referenceAxisName으로 사용함
      opposedPosition: true,  // 반대편(오른쪽)에 표시
      labelFormat: '{value}%', 
      interval: 25,
      minimum: 0, 
      maximum: 100,
      majorGridLines: MajorGridLines(width: 0)
    ),
  ],
  series: <CartesianSeries>[
    StackedColumnSeries<MonthlyAnalyticsItemsData, String>(
      dataSource: periodicAnalyticsItemsData.monthlyAnalyticsItemsDataList,
      xValueMapper: (MonthlyAnalyticsItemsData data, _) => StringUtil.dateFormat(data.month),
      yValueMapper: (MonthlyAnalyticsItemsData data, _) => data.amountReceived,
      name: '실 수납',
      color: AnalyticsConstant.paidColor,
      animationDuration: 900,
    ),
    StackedColumnSeries<MonthlyAnalyticsItemsData, String>(
      dataSource: periodicAnalyticsItemsData.monthlyAnalyticsItemsDataList,
      xValueMapper: (MonthlyAnalyticsItemsData data, _) => StringUtil.dateFormat(data.month),
      yValueMapper: (MonthlyAnalyticsItemsData data, _) => data.unpaid,
      name: '미납',
      color: AnalyticsConstant.unpaidColor,
      animationDuration: 900,
    ),
    if (hasFuture)
      StackedColumnSeries<MonthlyAnalyticsItemsData, String>(
        dataSource: periodicAnalyticsItemsData.monthlyAnalyticsItemsDataList,
        xValueMapper: (MonthlyAnalyticsItemsData data, _) => StringUtil.dateFormat(data.month),
        yValueMapper: (MonthlyAnalyticsItemsData data, _) => data.notComing,
        name: '예정',
        color: AnalyticsConstant.notComingColor,
        animationDuration: 900,
      ),
    LineSeries<MonthlyAnalyticsItemsData, String>(
      // 수납률 데이터를 표시할 시리즈
      dataSource: periodicAnalyticsItemsData.monthlyAnalyticsItemsDataList,
      xValueMapper: (MonthlyAnalyticsItemsData data, _) => StringUtil.dateFormat(data.month),
      yValueMapper: (MonthlyAnalyticsItemsData data, _) => data.amountReceived / data.totalPayment * 100,
      name: '수납률',
      
      // 수납률은 보조 축을 쓴다고 명시 ("percentageAxis"라는 이름으로 정의한 축 사용)
      yAxisName: 'percentageAxis', 
      markerSettings: MarkerSettings(
        isVisible: true,
        height: 6,
        width: 6,
      ),
      color: Color.fromARGB(255, 3, 71, 134),
      animationDuration: 1200,
    ),
  ],
),
Widget _buildTrackballItem(String title, String value, Color color) {
  return Padding(
    padding: const EdgeInsets.symmetric(vertical: 2),
    child: Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        // 원형 색상 아이콘
        Container(
          width: 8,
          height: 8,
          decoration: BoxDecoration(
            color: color,
            shape: BoxShape.circle,
          ),
        ),
        const SizedBox(width: 6),
        Text(
          '$title: $value',
          style: const TextStyle(color: Colors.white),
        ),
      ],
    ),
  );
}

Screenshots or Video

Screenshots / Video demonstration

<Trackball contents are displayed - no custom builder>
Simulator Screenshot - iPhone 15 Pro - 2024-12-22 at 16 53 00

<Trackball contents are not displayed - custom builder>
Simulator Screenshot - iPhone 15 Pro - 2024-12-22 at 16 48 45

<Logs with custom builder (logged by code sample)>
스크린샷 2024-12-22 오후 4 49 33

Stack Traces

Stack Traces
No stack traces (not exception)

On which target platforms have you observed this bug?

iOS

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale ko-KR)
    • Flutter version 3.22.1 on channel stable at /Users/minchansong/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a14f74ff3a (7 months ago), 2024-05-22 11:08:21 -0500
    • Engine revision 55eae6864b
    • Dart version 3.4.1
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/minchansong/Library/Android/sdk
    • Platform android-34, build-tools 31.0.0
    • ANDROID_HOME = /Users/minchansong/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.81.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64  • Android
      13 (API 33) (emulator)
    • iPhone 15 Pro (mobile)          • B58AE792-5128-4BF7-90CB-AED0FB36DC36 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS
      14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS
      14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google
      Chrome 131.0.6778.205

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant