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

Performance Issue with getTitles with large range between flSpots. #67

Closed
chagaj opened this issue Sep 16, 2019 · 7 comments
Closed

Performance Issue with getTitles with large range between flSpots. #67

chagaj opened this issue Sep 16, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@chagaj
Copy link

chagaj commented Sep 16, 2019

Hello,

I am having a similar issue to that described in #54.

For example, the following:
FlSpot(1,-1000000) ,
FlSpot(1, 1000000)],
minY = -1000000,
leads to 1,000,000+ calls to the function that getTitles in the FlTitlesData() widget points too. This results in my app becoming completely non-responsive for a while until all these calls have completed.

Here's the code for my line chart:
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 18,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: MediaQuery.of(context).size.width * .95,
height: MediaQuery.of(context).size.height * .8,
child: FlChart(
chart: LineChart(
LineChartData(
lineTouchData: const LineTouchData(enabled: false),
lineBarsData: [
LineChartBarData(
spots: getSpots(),
isCurved: false,
barWidth: 8,
colors: [
Colors.indigo,
],
belowBarData: BelowBarData(
show: true,
colors: [Colors.deepPurple.withOpacity(0.2)],
),
dotData: FlDotData(
show: false,
),
),
],
minY: widget.minY,
titlesData: FlTitlesData(
bottomTitles: SideTitles(
showTitles: true,
textStyle: TextStyle(
fontSize: 10,
color: Colors.purple,
fontWeight: FontWeight.bold),
getTitles: (value) {
return value.toStringAsFixed(0);
}),
leftTitles: SideTitles(
showTitles: true,
getTitles: (value) {
return getLeftTitle(value); //This function gets called 1,000,000+ times
},
),
),
),
),
),
),
),
],
);

Map<double, String> leftTileValues = {};

String getLeftTitle(double value) {
return widget.leftTileValues[value]; //it doesn't seem to matter what I do here, this function is called 1,000,000+ times.
}

Here, the getLeftListTile(value) function gets called 1,000,000 + times.

Since my FlSpots are created dynamically, and minY and maxY values are determined at runtime, I am not using a switch to return the titles as you do in the examples provided. Instead, I created a Map<double,String> with 10 entries that are spaced evenly between the range of FlSpots. In other words (maxY - minY).

Is there a better way for me to dynamically create 10 titles evenly spaced between a large range of values over the Y axis (set an interval for Y axis titles) or is this a bug?

@wksvo
Copy link

wksvo commented Sep 17, 2019

me too.

@imaNNeo imaNNeo added the bug Something isn't working label Sep 22, 2019
@imaNNeo
Copy link
Owner

imaNNeo commented Sep 27, 2019

Hi guys, I know your problem, but not sure what could we do,
I think you guys can scale down your values to fix this problem, is it works?

@chagaj
Copy link
Author

chagaj commented Sep 27, 2019

Hey Iman,

Thanks for taking the time to respond. Unfortunately this would not be ideal in my case, which is that I wish to implement a PNL graph.

Depending on the user (and their currencies), values can range in the 1000s or 10,000,000s.

While I do understand that your current implementation of line charts does not support a large range in values, it may be something you wish to consider implementing in the future as this issue is bound to prop up for others.

For example, any finance app that supports a low value currency that wishes to use your line chart will need it to support large range of values.

Perhaps you could implement a way to set an interval between y-axis titles so that getTitles isn't called on every incremental integer?

Do put the word out if you decide to work on it.

Outside of that, thanks for all the work you've done on this package :).

@imaNNeo
Copy link
Owner

imaNNeo commented Sep 27, 2019

Your welcome, and it's my pleasure to read your text,
You are right, we should fix this problem,
as I understand the problem is just about y titles right?
Your welcome,
Thanks!

@chagaj
Copy link
Author

chagaj commented Sep 30, 2019

You're welcome and thanks for your response!

I have not tested it for the x-axis but but it looks to me like it would work the same way when getTitles() is called for titles of the x-axis too.

I fear the same issue may result if the graph needs to plot points with a large range of x values as well.

@imaNNeo
Copy link
Owner

imaNNeo commented Sep 30, 2019

Ok, I will check it too,
stay tuned.
Thanks!

imaNNeo added a commit that referenced this issue Oct 3, 2019
added interval field in the SideTitles class, fixed issue #67
@imaNNeo
Copy link
Owner

imaNNeo commented Oct 3, 2019

Fixed problem in 0.3.1, you can now set the interval in the SideTitles to fix your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants