refactoring
This commit is contained in:
parent
6bb0a1c56b
commit
7cec254bb0
|
@ -19,7 +19,7 @@ import static com.rusefi.config.generated.Fields.PROTOCOL_ES_UP;
|
|||
*
|
||||
* @see SensorSnifferPane
|
||||
*/
|
||||
public class EngineReport implements TimeAxisTranslator {
|
||||
public class EngineReport {
|
||||
public static final String ENGINE_CHART = Fields.PROTOCOL_ENGINE_SNIFFER;
|
||||
public static final EngineReport MOCK = new EngineReport(Collections.singletonList(new UpDown(0, -1, 1, -1)));
|
||||
/**
|
||||
|
@ -68,6 +68,8 @@ public class EngineReport implements TimeAxisTranslator {
|
|||
return list;
|
||||
}
|
||||
|
||||
|
||||
private TimeAxisTranslator timeAxisTranslator = new TimeAxisTranslator() {
|
||||
@Override
|
||||
public int getMaxTime() {
|
||||
return maxTime;
|
||||
|
@ -78,6 +80,23 @@ public class EngineReport implements TimeAxisTranslator {
|
|||
return minTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int timeToScreen(int time, int width) {
|
||||
double translated = (time - minTime) * 1.0 / getDuration();
|
||||
return (int) (width * translated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double screenToTime(int screenX, int screenWidth) {
|
||||
double time = 1.0 * screenX * getDuration() / screenWidth + minTime;
|
||||
return (int) time;
|
||||
}
|
||||
};
|
||||
|
||||
public TimeAxisTranslator getTimeAxisTranslator() {
|
||||
return timeAxisTranslator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EngineChartParser#unpackToMap(String)
|
||||
*/
|
||||
|
@ -121,18 +140,6 @@ public class EngineReport implements TimeAxisTranslator {
|
|||
return times;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int timeToScreen(int time, int width) {
|
||||
double translated = (time - minTime) * 1.0 / getDuration();
|
||||
return (int) (width * translated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double screenToTime(int screenX, int screenWidth) {
|
||||
double time = 1.0 * screenX * getDuration() / screenWidth + minTime;
|
||||
return (int) time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Length of this chart in Engine Sniffer ticks
|
||||
*/
|
||||
|
|
|
@ -17,9 +17,9 @@ public class EngineReportTest {
|
|||
EngineReport wr = new EngineReport(report);
|
||||
assertEquals(14, wr.getList().size());
|
||||
|
||||
assertEquals(14679, wr.getMinTime());
|
||||
assertEquals(43849, wr.getMaxTime());
|
||||
assertEquals(14679, wr.getTimeAxisTranslator().getMinTime());
|
||||
assertEquals(43849, wr.getTimeAxisTranslator().getMaxTime());
|
||||
|
||||
assertEquals(59, wr.timeToScreen(18134, 500));
|
||||
assertEquals(59, wr.getTimeAxisTranslator().timeToScreen(18134, 500));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class EngineSnifferStatusPanel {
|
|||
private final JLabel timeLabel = new JLabel();
|
||||
private final JLabel angleLabel = new JLabel();
|
||||
private final JLabel rpmLabel = new JLabel();
|
||||
private TimeAxisTranslator translator = EngineReport.MOCK;
|
||||
private TimeAxisTranslator translator = EngineReport.MOCK.getTimeAxisTranslator();
|
||||
|
||||
private RevolutionLog time2rpm = RevolutionLog.parseRevolutions(null);
|
||||
|
||||
|
|
|
@ -119,22 +119,22 @@ public class UpDownImage extends JPanel {
|
|||
return new TimeAxisTranslator() {
|
||||
@Override
|
||||
public int timeToScreen(int time, int width) {
|
||||
return UpDownImage.this.engineReport.timeToScreen(time, width);
|
||||
return UpDownImage.this.engineReport.getTimeAxisTranslator().timeToScreen(time, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double screenToTime(int screen, int width) {
|
||||
return UpDownImage.this.engineReport.screenToTime(screen, width);
|
||||
return UpDownImage.this.engineReport.getTimeAxisTranslator().screenToTime(screen, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxTime() {
|
||||
return UpDownImage.this.engineReport.getMaxTime();
|
||||
return UpDownImage.this.engineReport.getTimeAxisTranslator().getMaxTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinTime() {
|
||||
return UpDownImage.this.engineReport.getMinTime();
|
||||
return UpDownImage.this.engineReport.getTimeAxisTranslator().getMinTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue