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

speedometer division control of values #35

Closed
EPapadopoulou opened this issue Jul 20, 2017 · 9 comments
Closed

speedometer division control of values #35

EPapadopoulou opened this issue Jul 20, 2017 · 9 comments
Labels

Comments

@EPapadopoulou
Copy link

EPapadopoulou commented Jul 20, 2017

Hi, great work with the speedometers!

I have a question/request!

Example: Given the following: minSpeed=0, maxSpeed=20000, lowSpeedPercent=50, mediumSpeedPercent=35, can we have the low zone between the values 0 and 1000, the medium zone between 1000 and 2000 and the high zone between 2000 and 20000?

Also, is it possible to assign labels to the ticks? For example, instead of showing 1000m, I would like to show 1km!

Thanks in advance!

@anastr
Copy link
Owner

anastr commented Jul 21, 2017

Hello @EPapadopoulou ,
to set low zone between the values 0 and 1'000 easily we calculate percent value for (1'000 of 20'000).
which means lowSpeedPercent = 1'000 * 100 / 20'000 = 5%.
same way for mediumSpeedPercent = 2'000 * 100 / 20'000 = 10%
by default High zone will take the remaining space.
and be careful, lowSpeedPercent must be smaller than mediumSpeedPercent, or it may throw IllegalArgumentException.

for ticks issue, it doesn't support ... it can be considered in the next version.

@EPapadopoulou
Copy link
Author

Hi! Thanks for the quick reply. That's not what I meant. I did not explain it well enough. I understand how to setup the lowSpeedPercent and mediumSpeedPercent to reflect what I want and I've already done that. What I really want is to have the gauge to function in a logarithmic scale. i.e. I want the values between 0 and 2000 to cover most of the gauge.
Thanks!

@anastr
Copy link
Owner

anastr commented Jul 21, 2017

mmmm, unfortunately, this kind of speedometer doesn't supported 😞 .
to do this in not-practical way you can use ImageSpeedometer, but it is not very good for dealing with values.

any suggestions !!

@EPapadopoulou
Copy link
Author

Actually, that's what I was thinking of. I was going to create my own image so that the appropriate values are displayed and I was going to calculate the values with speedTo. However, I will not be able to control the value displayed in the center.

@anastr
Copy link
Owner

anastr commented Jul 21, 2017

After you build your own image, build costum speedometer by extends Image Speedometer and override getDegreeAtSpeed(float speed) method to return custom degree at current speed value like so:

@Override
protected float getDegreeAtSpeed(float speed) {
     int maxDegree = getEndDegree() - getStartDegree();
     // calculate your degree, must be between [0, maxDegree]
     float degree = ....;
     // we add startDegree to make sure our degree between startDegree and endDegree.
     return degree + getStartDegree();
}

I hope it will help...

@anastr
Copy link
Owner

anastr commented Sep 12, 2017

since version 1.1.6 you can change tick label as you wish use OnPrintTickLabel :

speedometer.setOnPrintTickLabel(new OnPrintTickLabel() {
    @Override
    public String getTickLabel(int tickPosition, int tick) {
        if(tick >= 1000)
            return String.format(Locale.getDefault(), "%.1f Km", tick / 1000f);
        return String.format(Locale.getDefault(), "%d M", tick);
    }
});

this will show 1km instead of showing 1000m 👍
read release 1.1.6 note to know what is changes.

@wenmin92
Copy link

wenmin92 commented Jul 29, 2019

@anastr 1.4.0(kotlin) should open fun getDegreeAtSpeed(speed: Float) for override. I need override it to draw a speed view which ticks not equal, see below:
image

@anastr
Copy link
Owner

anastr commented Jul 29, 2019

Hi @wenmin92
You can use Custom Ticks for this:

    speedometer.setTicks(0, 2, 5, 10, 25, 50, 75, 150, 300)

Or maybe you need Custom Tick Label

@anastr
Copy link
Owner

anastr commented Jul 27, 2020

this kind of behavior will not be implemented, since you can add it in ImageSpeedometer, Custom Ticks, Custom Tick Label and SpeedTextListener.

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

No branches or pull requests

3 participants