forked from LupusNobilis/java-org.hwo.ui
70 lines
1.1 KiB
Java
70 lines
1.1 KiB
Java
package org.hwo.ui.diagram;
|
|
|
|
public class LinearScaler implements Scaler{
|
|
|
|
double offset,
|
|
window,
|
|
scale;
|
|
int height;
|
|
|
|
|
|
public LinearScaler() {
|
|
this.height = 1;
|
|
this.offset = 0;
|
|
this.window = 1;
|
|
this.scale();
|
|
}
|
|
|
|
private void scale(){
|
|
this.scale = this.height / this.window;
|
|
}
|
|
|
|
@Override
|
|
public void setHeight(int height) {
|
|
this.height = height;
|
|
this.scale();
|
|
}
|
|
|
|
@Override
|
|
public void scale(double minValue, double maxValue, boolean useMargin) {
|
|
this.offset = minValue;
|
|
this.window = maxValue - minValue;
|
|
if (this.window == 0)
|
|
{
|
|
this.window = this.offset * 0.1;
|
|
this.offset -= this.window / 2;
|
|
}
|
|
this.scale();
|
|
}
|
|
|
|
@Override
|
|
public int getPosition(double value) {
|
|
return (int)((value - this.offset) * this.scale);
|
|
}
|
|
|
|
@Override
|
|
public double getValue(int position) {
|
|
return ((double)position / this.scale) + this.offset;
|
|
}
|
|
|
|
@Override
|
|
public double getMinValue() {
|
|
return this.offset;
|
|
}
|
|
|
|
@Override
|
|
public double getMaxValue() {
|
|
return this.offset + this.window;
|
|
}
|
|
|
|
@Override
|
|
public double getWindow() {
|
|
return this.window;
|
|
}
|
|
|
|
@Override
|
|
public double[] getMarkerHints() {
|
|
return null;
|
|
}
|
|
}
|