use of org.jfree.chart.axis.ValueAxis in project Course_Generator by patrovite.
the class JPanelAnalysisSpeedSlope method Refresh.
/**
* Update the Slope/Speed chart
*/
public void Refresh(TrackData track, CgSettings settings) {
if (track == null)
return;
if (track.data.isEmpty())
return;
this.track = track;
this.settings = settings;
// -- Clear all series
if (datasetSpeedSlopePoint.getSeriesCount() > 0)
datasetSpeedSlopePoint.removeAllSeries();
if (datasetSpeedSlopeLine.getSeriesCount() > 0)
datasetSpeedSlopeLine.removeAllSeries();
XYPlot plot = chart.getXYPlot();
plot.clearDomainMarkers();
// -- Populate the series
XYSeries serie1 = new XYSeries("Speed/Slope (points)");
XYSeries serie2 = new XYSeries("Speed/Slope (line)");
int[] nb;
int j = 0;
double[] fCurveSpeedSlope = new double[101];
double[] fCurveSpeedSlope2 = new double[101];
Double[] Average = new Double[101];
Double[] Variance = new Double[101];
Double[] StandardDeviation = new Double[101];
nb = new int[101];
// -- init calc
for (j = 0; j < 101; j++) {
fCurveSpeedSlope[j] = 0;
fCurveSpeedSlope2[j] = 0;
nb[j] = 0;
}
// -- Execute the speed filtering calculation
SpeedFilter();
/*
* -- Pass 1 We calculate the average, variance and standard deviation
* of each area (1% per area)
*/
int n = 0;
double s = 0.0;
double coeff = 0.0;
double diff = 0.0;
for (CgData r : track.data) {
if (btSpeedSlopeFilter.isSelected())
s = r.tmp1;
else
s = r.getSpeed(settings.Unit);
if (btSpeedSlopeCorr.isSelected()) {
coeff = r.getCoeff() / 100.0;
diff = r.getDiff() / 100.0;
} else {
coeff = 1.00;
diff = 1.00;
}
if (s > 1.5) {
if (r.getSlope() < -49) {
fCurveSpeedSlope[0] = fCurveSpeedSlope[0] + (s / coeff / diff);
fCurveSpeedSlope2[0] = fCurveSpeedSlope2[0] + Math.pow((s / coeff / diff), 2);
nb[0]++;
} else if (r.getSlope() > 49) {
fCurveSpeedSlope[100] = fCurveSpeedSlope[100] + (s / coeff / diff);
fCurveSpeedSlope2[100] = fCurveSpeedSlope2[100] + Math.pow((s / coeff / diff), 2);
nb[100]++;
} else {
n = (int) Math.floor(r.getSlope());
fCurveSpeedSlope[n + 50] = fCurveSpeedSlope[n + 50] + (s / coeff / diff);
fCurveSpeedSlope2[n + 50] = fCurveSpeedSlope2[n + 50] + Math.pow((s / coeff / diff), 2);
nb[n + 50]++;
}
}
}
for (j = 0; j < 101; j++) {
if ((nb[j] > 0)) {
Average[j] = fCurveSpeedSlope[j] / nb[j];
Variance[j] = fCurveSpeedSlope2[j] / nb[j] - Average[j] * Average[j];
StandardDeviation[j] = Math.sqrt(Variance[j]);
}
}
// -- Init calc
for (j = 0; j < 101; j++) {
fCurveSpeedSlope[j] = 0;
fCurveSpeedSlope2[j] = 0;
nb[j] = 0;
}
n = 0;
s = 0.0;
coeff = 0.0;
diff = 0.0;
for (CgData r : track.data) {
{
if (btSpeedSlopeFilter.isSelected())
s = r.tmp1;
else
s = r.getSpeed(settings.Unit);
if (btSpeedSlopeCorr.isSelected()) {
coeff = r.getCoeff() / 100.0;
diff = r.getDiff() / 100.0;
} else {
coeff = 1.00;
diff = 1.00;
}
if (s > 1.5) {
if (r.getSlope() < -49) {
if ((s <= Average[0] + StandardDeviation[0]) || (s >= Average[0] - StandardDeviation[0])) {
fCurveSpeedSlope[0] = fCurveSpeedSlope[0] + (s / coeff / diff);
fCurveSpeedSlope2[0] = fCurveSpeedSlope2[0] + Math.pow((s / coeff / diff), 2);
nb[0]++;
}
} else if (r.getSlope() > 49) {
if ((s <= Average[100] + StandardDeviation[100]) || (s >= Average[100] - StandardDeviation[100])) {
fCurveSpeedSlope[100] = fCurveSpeedSlope[100] + (s / coeff / diff);
fCurveSpeedSlope2[100] = fCurveSpeedSlope2[100] + Math.pow((s / coeff / diff), 2);
nb[100]++;
}
} else {
n = (int) Math.floor(r.getSlope());
if ((s <= Average[n + 50] + StandardDeviation[n + 50]) || (s >= Average[n + 50] - StandardDeviation[n + 50])) {
fCurveSpeedSlope[n + 50] = fCurveSpeedSlope[n + 50] + (s / coeff / diff);
fCurveSpeedSlope2[n + 50] = fCurveSpeedSlope2[n + 50] + Math.pow((s / coeff / diff), 2);
nb[n + 50]++;
}
}
}
}
}
double maxspeed = 0.0;
// -- Populate the first serie
for (CgData r : track.data) {
if (btSpeedSlopeFilter.isSelected())
s = r.tmp1;
else
s = r.getSpeed(settings.Unit);
if (s > maxspeed)
maxspeed = s;
serie1.add(r.getSlope(), s);
}
datasetSpeedSlopePoint.addSeries(serie1);
// -- Populate the second serie
double m = 0.0;
for (j = 0; j < 101; j++) {
if ((nb[j] > 0)) {
m = fCurveSpeedSlope[j] / nb[j];
if (m > maxspeed)
maxspeed = m;
serie2.add(j - 50, m);
}
}
// -- If there is no speed the exit (not already calculated)
if (maxspeed == 0)
return;
datasetSpeedSlopeLine.addSeries(serie2);
// -- Set the range of the X axis
ValueAxis axisX = plot.getDomainAxis();
axisX.setRange(-50.0, 50.0);
ValueAxis axisY = plot.getRangeAxis(0);
axisY.setRange(0, Math.ceil(maxspeed / 5.0) * 5.0);
axisY = plot.getRangeAxis(1);
axisY.setRange(1, Math.ceil(maxspeed / 5.0) * 5.0);
}
use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class CategoryPlotFactory method create.
public Plot create(DataSource dataSource, CategoryItemRenderer renderer, ChartParams params) throws GenerateException, DataSourceException {
String dataSeries = params.getString(ChartParams.SERIES);
CategoryAxis domainAxis = new CategoryAxis();
ValueAxis rangeAxis = new NumberAxis();
ChartCustomizer.customizeCategoryAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
ChartCustomizer.customizeValueAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
Class rendererClass = params.getClass(ChartParams.RENDERER);
ChartCustomizer.customizeCategoryItemRenderer(renderer, params);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
if ("columns".equals(dataSeries)) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) : ("Category " + (column + 1)), dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) : ("Series " + (row + 1)));
}
}
} else if ("rows".equals(dataSeries)) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) : ("Category " + (row + 1)), dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) : ("Series " + (column + 1)));
}
}
} else {
throw new GenerateException("Invalid series parameter: " + dataSeries);
}
return new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
}
use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class AbstractXYPlotGenerator method generate.
@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
XYDataset dataset;
ValueAxis domainAxis;
ValueAxis rangeAxis;
if (model.getDataset() instanceof XYDataset) {
dataset = (XYDataset) model.getDataset();
} else {
throw new PlotGeneratorException("Incompatible dataset for xy plot.");
}
if (model.getAxis(0) instanceof ValueAxis) {
domainAxis = (ValueAxis) model.getAxis(0);
} else {
throw new PlotGeneratorException("Incompatible axis 0 for xy plot.");
}
if (model.getAxis(1) instanceof ValueAxis) {
rangeAxis = (ValueAxis) model.getAxis(1);
} else {
throw new PlotGeneratorException("Incompatible axis 1 for xy plot.");
}
return new XYPlot(dataset, domainAxis, rangeAxis, getRenderer(parameters));
}
use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class TableCategoryDatasetBuilderTest method testBuildCategoryDataset.
@Test
public void testBuildCategoryDataset() throws Exception {
String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3"), null);
ChartModel chartModel = getDataSource().getChartModel();
Dataset dataset = chartModel.getDataset();
Assert.assertTrue(dataset instanceof CategoryDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
CategoryDataset categoryDataset = (CategoryDataset) dataset;
Assert.assertTrue(categoryDataset.getRowKey(0).equals(" row 1 "));
Assert.assertTrue(categoryDataset.getRowKey(1).equals(" row 2 "));
Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" column 2 "));
Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" column 3 "));
Assert.assertTrue(categoryDataset.getColumnKey(2).equals(" column 4"));
Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 13);
Assert.assertTrue(categoryDataset.getValue(0, 2).intValue() == 14);
Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 22);
Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
Assert.assertTrue(categoryDataset.getValue(1, 2).intValue() == 24);
}
use of org.jfree.chart.axis.ValueAxis in project xwiki-platform by xwiki.
the class TableCategoryDatasetBuilderTest method testBuildCategoryDatasetColumnsSeries.
@Test
public void testBuildCategoryDatasetColumnsSeries() throws Exception {
String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3", "series", "columns"), null);
ChartModel chartModel = getDataSource().getChartModel();
Dataset dataset = chartModel.getDataset();
Assert.assertTrue(dataset instanceof CategoryDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
CategoryDataset categoryDataset = (CategoryDataset) dataset;
Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" row 1 "));
Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" row 2 "));
Assert.assertTrue(categoryDataset.getRowKey(0).equals(" column 2 "));
Assert.assertTrue(categoryDataset.getRowKey(1).equals(" column 3 "));
Assert.assertTrue(categoryDataset.getRowKey(2).equals(" column 4"));
Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 13);
Assert.assertTrue(categoryDataset.getValue(2, 0).intValue() == 14);
Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 22);
Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
Assert.assertTrue(categoryDataset.getValue(2, 1).intValue() == 24);
}
Aggregations