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

added custom properties attribute to line chart bar data #1664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alr2413
Copy link

@alr2413 alr2413 commented May 14, 2024

Hi, thanks for providing this awesome library.
In this PR, I added a properties attribute as Map<string, dynamic> in order to store optional line curve parameters, like name or any other curve setting. by this change if you have multiple curves in a chart, now it's possible to show the name of each curve next to the value on the tooltip message.
image

@alr2413
Copy link
Author

alr2413 commented Jun 17, 2024

@imaNNeo,
is there any issue with this PR?
please let me know, thanks.

@imaNNeo
Copy link
Owner

imaNNeo commented Jun 21, 2024

Yes, there are issues with this PR,

  1. I think it is better to use dynamic or Object type for the properties
  2. I think you can wrap the LineChartBarData to add your own custom data, you can check out this message
  3. Please read the contributing guidelines, (you should not change the library version)

@alr2413
Copy link
Author

alr2413 commented Jun 24, 2024

Thanks for your reply :)
Here is my comments:

  1. I defined the type of properties attribute, because if we want to include that attribute in lerp operation, the type must be known. so we can't use the dynamic or Object type.

  2. I think it would be the best if you include this hint in readme file (since currently there are multiple PR requests for this types of features). I tried to do that and it worked. Just need to override the copyWith operation. I added here as a reference:

class LineChartBarDataWrapper extends LineChartBarData {
  final String label;

  LineChartBarDataWrapper({
    super.spots,
    super.show,
    super.color,
    super.gradient,
    super.barWidth,
    super.isCurved,
    super.curveSmoothness,
    super.preventCurveOverShooting,
    super.preventCurveOvershootingThreshold,
    super.isStrokeCapRound,
    super.isStrokeJoinRound,
    super.belowBarData,
    super.aboveBarData,
    super.dotData,
    super.showingIndicators,
    super.dashArray,
    super.shadow,
    super.isStepLineChart,
    super.lineChartStepData,
    required this.label,
  });

  @override
  LineChartBarDataWrapper copyWith({
    List<FlSpot>? spots,
    bool? show,
    Color? color,
    Gradient? gradient,
    double? barWidth,
    bool? isCurved,
    double? curveSmoothness,
    bool? preventCurveOverShooting,
    double? preventCurveOvershootingThreshold,
    bool? isStrokeCapRound,
    bool? isStrokeJoinRound,
    BarAreaData? belowBarData,
    BarAreaData? aboveBarData,
    FlDotData? dotData,
    List<int>? dashArray,
    List<int>? showingIndicators,
    Shadow? shadow,
    bool? isStepLineChart,
    LineChartStepData? lineChartStepData,
    String? label,
  }) {
    return LineChartBarDataWrapper(
      spots: spots ?? this.spots,
      show: show ?? this.show,
      color: color ?? this.color,
      gradient: gradient ?? this.gradient,
      barWidth: barWidth ?? this.barWidth,
      isCurved: isCurved ?? this.isCurved,
      curveSmoothness: curveSmoothness ?? this.curveSmoothness,
      preventCurveOverShooting:
          preventCurveOverShooting ?? this.preventCurveOverShooting,
      preventCurveOvershootingThreshold: preventCurveOvershootingThreshold ??
          this.preventCurveOvershootingThreshold,
      isStrokeCapRound: isStrokeCapRound ?? this.isStrokeCapRound,
      isStrokeJoinRound: isStrokeJoinRound ?? this.isStrokeJoinRound,
      belowBarData: belowBarData ?? this.belowBarData,
      aboveBarData: aboveBarData ?? this.aboveBarData,
      dotData: dotData ?? this.dotData,
      dashArray: dashArray ?? this.dashArray,
      showingIndicators: showingIndicators ?? this.showingIndicators,
      shadow: shadow ?? this.shadow,
      isStepLineChart: isStepLineChart ?? this.isStepLineChart,
      lineChartStepData: lineChartStepData ?? this.lineChartStepData,
      label: label ?? this.label,
    );
  }
}

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

Successfully merging this pull request may close these issues.

2 participants