Skip to content
Snippets Groups Projects
Commit 4538112e authored by cramakri's avatar cramakri
Browse files

LMS-1697 Generate row labels for the heat map using spreedsheet conventions...

LMS-1697 Generate row labels for the heat map using spreedsheet conventions (A, B, ... AA, etc); match the number of heatmap scale labels to the quantization of the paint scale.

SVN: 17563
parent 65e97fbf
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,10 @@ public class TabularDataGraphServlet extends AbstractTabularDataGraphServlet
private IEncapsulatedOpenBISService openBisService;
final public static String WELL_ROW_COLUMN = "Row";
final public static String WELL_COLUMN_COLUMN = "Column";
/**
* An CSV-file-like interface to feature data from the database.
*
......@@ -56,10 +60,6 @@ public class TabularDataGraphServlet extends AbstractTabularDataGraphServlet
{
private static final String WELL_NAME_COLUMN = "WellName";
private static final String WELL_ROW_COLUMN = "Row";
private static final String WELL_COLUMN_COLUMN = "Column";
private final IImagingQueryDAO dao;
private final IEncapsulatedOpenBISService service;
......@@ -67,7 +67,7 @@ public class TabularDataGraphServlet extends AbstractTabularDataGraphServlet
private final String dataSetCode;
private String[] headerCodes;
private String[] headerLabels;
private ArrayList<String[]> lines;
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.dss.generic.server.graph;
import org.jfree.chart.axis.NumberTickUnit;
import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.PlateUtils;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class SpreadsheetColumnTickUnit extends NumberTickUnit
{
private static final long serialVersionUID = 1L;
// Note: this should work as a way of letting the axis select the appropriate
// tick interval, but it doesn't work for some reason.
//
// public static TickUnitSource createStandardTickUnits()
// {
// TickUnits tickUnits = new TickUnits();
// tickUnits.add(new SpreadsheetColumnTickUnit(1.0));
// tickUnits.add(new SpreadsheetColumnTickUnit(2.0));
// tickUnits.add(new SpreadsheetColumnTickUnit(5.0));
// return tickUnits;
// }
/**
* Constructor for a spreadsheet tick unit label.
*/
public SpreadsheetColumnTickUnit(double size)
{
super(size);
}
/**
* Converts the supplied value to a string.
* <P>
* Subclasses may implement special formatting by overriding this method.
*
* @param value the data value.
* @return Value as string.
*/
@Override
public String valueToString(double value)
{
if (value < 1)
{
return "";
}
return PlateUtils.translateRowNumberIntoLetterCode((int) value);
}
}
......@@ -30,6 +30,7 @@ import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.utilities.PropertyParametersUtil;
import ch.systemsx.cisd.common.utilities.PropertyUtils;
import ch.systemsx.cisd.common.utilities.PropertyParametersUtil.SectionProperties;
import ch.systemsx.cisd.openbis.dss.generic.server.TabularDataGraphServlet;
import ch.systemsx.cisd.openbis.dss.generic.server.graph.TabularDataGraphConfiguration.GraphType;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ITabularData;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CodeAndLabel;
......@@ -177,8 +178,14 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
switch (type)
{
case HEATMAP:
CodeAndLabel xAxis = getCodeAndLabel(props, X_AXIS_KEY);
CodeAndLabel yAxis = getCodeAndLabel(props, Y_AXIS_KEY);
// Default the Row and Column header names to the standard ones if no override is
// specified.
CodeAndLabel xAxis =
getCodeAndLabelWithDefault(props, X_AXIS_KEY,
TabularDataGraphServlet.WELL_ROW_COLUMN);
CodeAndLabel yAxis =
getCodeAndLabelWithDefault(props, Y_AXIS_KEY,
TabularDataGraphServlet.WELL_ROW_COLUMN);
CodeAndLabel zAxis = getCodeAndLabel(props, COLUMN_KEY);
if (xAxis.equals(yAxis))
{
......@@ -203,7 +210,7 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
// should never get here
return null;
}
private CodeAndLabel getCodeAndLabel(Properties properties, String key)
{
String labelWithOptionalCode = properties.getProperty(key);
......@@ -227,6 +234,30 @@ public class TabularDataGraphCollectionConfiguration implements ICsvFileReaderCo
return new CodeAndLabel(code, label);
}
private CodeAndLabel getCodeAndLabelWithDefault(Properties properties, String key,
String defaultLabel)
{
String labelWithOptionalCode = properties.getProperty(key);
if (labelWithOptionalCode != null)
{
return new CodeAndLabel(labelWithOptionalCode);
}
String labelKey = key + LABEL_POSTFIX;
String label = properties.getProperty(labelKey);
String codeKey = key + CODE_POSTFIX;
String code = properties.getProperty(codeKey);
if (label == null && code == null)
{
label = defaultLabel;
code = CodeAndLabel.normalize(label);
}
if (code == null)
{
return new CodeAndLabel(label);
}
return new CodeAndLabel(code, label);
}
/**
* Return the graph configuration associated with the graphTypeCode.
*
......
......@@ -24,7 +24,6 @@ import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.LookupPaintScale;
......@@ -48,6 +47,8 @@ import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ITabularData;
public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeatmapConfiguration>
{
private static final int PAINT_SCALE_NUM_STEPS = 11;
/**
* @param configuration
*/
......@@ -107,7 +108,7 @@ public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeat
throw new IllegalArgumentException("Null 'orientation' argument.");
}
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setTickUnit(new NumberTickUnit(1.0));
xAxis.setTickUnit(new SpreadsheetColumnTickUnit(1.0));
xAxis.setInverted(true);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
......@@ -130,6 +131,9 @@ public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeat
NumberAxis scaleAxis = new NumberAxis("Scale");
scaleAxis.setRange(dataset.getRange());
scaleAxis.setStandardTickUnits(new TabularDataTickUnitSource());
scaleAxis.setTickUnit(new TabularDataTickUnit(dataset.getRange().getLength()
/ PAINT_SCALE_NUM_STEPS));
scaleAxis.setAutoRange(true);
PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
psl.setMargin(new RectangleInsets(5, 5, 5, 5));
psl.setPosition(RectangleEdge.RIGHT);
......@@ -160,7 +164,7 @@ public class TabularDataHeatmap extends AbstractTabularDataGraph<TabularDataHeat
LookupPaintScale paintScale = new LookupPaintScale(lowerBound, upperBound, Color.WHITE);
double binMin = range.getLowerBound();
double binStep = range.getLength() / 11;
double binStep = range.getLength() / PAINT_SCALE_NUM_STEPS;
// 1
paintScale.add(binMin, new Color(5, 48, 97));
// 2
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.dss.generic.server.graph;
import java.text.DecimalFormat;
import org.jfree.chart.axis.NumberTickUnit;
/**
* This is a variation on the NumberTickUnit that gracefully switches from standard to scientific
* notation depending on the size of the numbers for the labels.
*
* @author Chandrasekhar Ramakrishnan
*/
public class TabularDataTickUnit extends NumberTickUnit
{
private static final long serialVersionUID = 1L;
final private static int largeScientificNotationTransition = 6;
final private static int smallScientificNotationTransition = 3;
/**
* @param size
*/
public TabularDataTickUnit(double size)
{
super(size, getNumberFormat(Math.abs(size), size >= 1.0));
}
/**
* Use the precision to determine if we should return standard or scientific notation.
*
* @param precision The desired precision of the numbers to display.
* @param greaterThan1 True if the numbers to be shown are greater then 1
*/
private static DecimalFormat getNumberFormat(double precision, boolean greaterThan1)
{
DecimalFormat numberFormat;
if (greaterThan1)
{
if (precision > largeScientificNotationTransition)
{
numberFormat = new DecimalFormat("0.0##E0");
} else
{
numberFormat = getStandardNumberFormat((int) precision, greaterThan1);
}
} else
{
if (precision > smallScientificNotationTransition)
{
numberFormat = new DecimalFormat("0.0##E0");
} else
{
numberFormat = getStandardNumberFormat((int) precision, greaterThan1);
}
}
return numberFormat;
}
/**
* Return a DecimalFormat that uses standard notation (not scientific notation).
*
* @param precision The desired precision of the numbers to display.
* @param greaterThan1 True if the numbers to be shown are greater then 1
*/
private static DecimalFormat getStandardNumberFormat(int precision, boolean greaterThan1)
{
StringBuilder sb = new StringBuilder();
if (greaterThan1)
{
for (int i = 1; i < precision; ++i)
{
sb.append("#");
}
sb.append("0");
} else
{
sb.append("0.0");
for (int i = 0; i < precision - 1; ++i)
{
sb.append("0");
}
}
return new DecimalFormat(sb.toString());
}
}
......@@ -17,9 +17,7 @@
package ch.systemsx.cisd.openbis.dss.generic.server.graph;
import java.io.Serializable;
import java.text.DecimalFormat;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.TickUnit;
import org.jfree.chart.axis.TickUnitSource;
......@@ -39,10 +37,6 @@ public class TabularDataTickUnitSource implements TickUnitSource, Serializable
/** Constant for log(10.0). */
final private static double LOG_10_VALUE = Math.log(10.0);
final private int largeScientificNotationTransition = 6;
final private int smallScientificNotationTransition = 3;
/**
* Returns a tick unit that is larger than the supplied unit.
*
......@@ -75,75 +69,12 @@ public class TabularDataTickUnitSource implements TickUnitSource, Serializable
*/
public TickUnit getCeilingTickUnit(double size)
{
// Use number of decimal digits to determine what the tick size and display format should
// be.
final double numberOfDigits = Math.log(size) / LOG_10_VALUE;
final double higher = Math.ceil(numberOfDigits);
final DecimalFormat numberFormat = getNumberFormat(Math.abs(higher), size >= 1.0);
final double fullTickIncrement = Math.pow(10, higher);
final double halfTickIncrement = fullTickIncrement / 2;
final double tickIncrement =
(size <= halfTickIncrement) ? halfTickIncrement : fullTickIncrement;
return new NumberTickUnit(tickIncrement, numberFormat);
}
/**
* Use the precision to determine if we should return standard or scientific notation.
*
* @param precision The desired precision of the numbers to display.
* @param greaterThan1 True if the numbers to be shown are greater then 1
*/
private DecimalFormat getNumberFormat(double precision, boolean greaterThan1)
{
DecimalFormat numberFormat;
if (greaterThan1)
{
if (precision > largeScientificNotationTransition)
{
numberFormat = new DecimalFormat("0.0##E0");
} else
{
numberFormat = getStandardNumberFormat((int) precision, greaterThan1);
}
} else
{
if (precision > smallScientificNotationTransition)
{
numberFormat = new DecimalFormat("0.0##E0");
} else
{
numberFormat = getStandardNumberFormat((int) precision, greaterThan1);
}
}
return numberFormat;
}
/**
* Return a DecimalFormat that uses standard notation (not scientific notation).
*
* @param precision The desired precision of the numbers to display.
* @param greaterThan1 True if the numbers to be shown are greater then 1
*/
private DecimalFormat getStandardNumberFormat(int precision, boolean greaterThan1)
{
StringBuilder sb = new StringBuilder();
if (greaterThan1)
{
for (int i = 1; i < precision; ++i)
{
sb.append("#");
}
sb.append("0");
} else
{
sb.append("0.0");
for (int i = 0; i < precision - 1; ++i)
{
sb.append("0");
}
}
return new DecimalFormat(sb.toString());
return new TabularDataTickUnit(tickIncrement);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment