001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.survival.kaplanmeier.figure; 022 023import java.awt.*; 024import java.io.FileInputStream; 025import java.util.ArrayList; 026import java.util.Properties; 027 028/** 029 * 030 * @author Scooter Willis <willishf at gmail dot com> 031 */ 032public class KMFigureInfo { 033 034 /** 035 * 036 */ 037 public int titleHeight = 40; 038 /** 039 * 040 */ 041 public int padding = 20; 042 /** 043 * 044 */ 045 public Integer width = 600; 046 /** 047 * 048 */ 049 public Integer height = 400; 050 /** 051 * 052 */ 053 public double timeScale = 1.0; //multiplier to change time from days to months etc 054 /** 055 * 056 */ 057 public double yaxisPercentIncrement = .2; 058 /** 059 * 060 */ 061 public double xaxisPercentIncrement = .25; 062 /** 063 * 064 */ 065 public double legendUpperPercentX = .95; 066 /** 067 * 068 */ 069 public double legendUpperPercentY = .95; 070 /** 071 * 072 */ 073 public double figureLineInfoLowerPercentX = .01; 074 /** 075 * 076 */ 077 public double figureLineInfoLowerPercentY = .01; 078 /** 079 * 080 */ 081 public BasicStroke axisStroke = new BasicStroke(2); 082 /** 083 * 084 */ 085 public BasicStroke kmStroke = new BasicStroke(3); 086 /** 087 * 088 */ 089 public Color[] legendColor = {Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.ORANGE, Color.YELLOW, Color.MAGENTA, Color.PINK}; 090 public ArrayList<Double> xAxisLabels = new ArrayList<Double>();//new ArrayList<Double>(Arrays.asList(0.0, 5.0, 10.0, 15.0, 20.0)); 091 public String xAxisLegend = ""; 092 public String yAxisLegend = ""; 093 public Color getColor(int index) { 094 return legendColor[index]; 095 } 096 097 /** 098 * 099 * @param propertyFileName 100 * @throws Exception 101 */ 102 public void init(String propertyFileName) throws Exception { 103 Properties properties = new Properties(); 104 properties.load(new FileInputStream(propertyFileName)); 105 106 if (properties.containsKey("legendUpperPercentX")) { 107 legendUpperPercentX = Double.parseDouble(properties.getProperty("legendUpperPercentX")); 108 } 109 110 if (properties.containsKey("legendUpperPercentY")) { 111 legendUpperPercentY = Double.parseDouble(properties.getProperty("legendUpperPercentY")); 112 } 113 114 if (properties.containsKey("xAxisLabels")) { 115 String values = properties.getProperty("xAxisLabels").trim(); 116 if (values.startsWith("[") || values.startsWith("(") || values.startsWith("{")) { 117 values = values.substring(1, values.length()).trim(); 118 } 119 if (values.endsWith("]") || values.endsWith(")") || values.endsWith("}")) { 120 values = values.substring(0, values.length() - 1).trim(); 121 } 122 xAxisLabels.clear(); 123 String[] data = values.split(","); 124 for (String d : data) { 125 try { 126 Double v = Double.parseDouble(d.trim()); 127 xAxisLabels.add(v); 128 } catch (Exception e) { 129 } 130 } 131 } 132 133 if (properties.containsKey("xAxisLegend")) { 134 xAxisLegend = properties.getProperty("xAxisLegend"); 135 } 136 137 if (properties.containsKey("yAxisLegend")) { 138 yAxisLegend = properties.getProperty("yAxisLegend"); 139 } 140 } 141}