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

Fix: CustomAnnotation == logic #316

Closed

Conversation

dan12411
Copy link
Contributor

@dan12411 dan12411 commented Sep 4, 2024

Description

By adding a CustomAnnotation circle at the last interval mark, when data growing the circle position would not change.

Solution

Add compare values data:

   @override
   bool operator ==(Object other) =>
      other is CustomAnnotation && super == other && values == other.values;

Test

As is:

As.is.webm

To be:

To.be.webm

Demo Sample Code:

CustomAnnotation:

                  annotations: [
                    CustomAnnotation(
                      renderer: (offset, size) =>
                          [CircleElement(center: offset, radius: 8, style: PaintStyle(fillColor: Colors.green))],
                      values: [data.last['genre'], data.last['sold']],
                    ),
                  ],

Adding new data after 5s:

    data = [
      {'genre': 'Sports', 'sold': rdm.nextInt(300)},
    ];

    int index = 1;

    timer = Timer.periodic(const Duration(seconds: 1), (_) {
      setState(() {
        if (index >= 5) {
          data.last = ({'genre': 'Other_4', 'sold': rdm.nextInt(300)});
          data = List.of(data);
          return;
        }

        data.add({'genre': 'Other_${index}', 'sold': rdm.nextInt(300)});
        data = List.from(data);
        index += 1;
      });
    });

@entronad
Copy link
Owner

entronad commented Sep 6, 2024

The values equality is checked in the parent class (and is deep equality test):

deepCollectionEquals(values, values) &&

I don't know why it desen't work

@dan12411
Copy link
Contributor Author

dan12411 commented Sep 6, 2024

OK, I will take more survey, thanks for relay.

@dan12411 dan12411 closed this Sep 6, 2024
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