Skip to content

Commit 2387ae1

Browse files
authored
Merge pull request #335 from Caltech-IPAC/DM-9342-HistogramOption
DM-9342:histogram option input dialog
2 parents a084955 + 12e59cb commit 2387ae1

File tree

4 files changed

+264
-44
lines changed

4 files changed

+264
-44
lines changed

src/firefly/java/edu/caltech/ipac/firefly/server/query/HistogramProcessor.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ public class HistogramProcessor extends IpacTablePartProcessor {
4444
columns[2].getFormatInfo().setDataFormat("%.14g");
4545
}
4646
private final String FIXED_SIZE_ALGORITHM = "fixedSizeBins";
47-
private final String NUMBER_BINS = "numBins";
47+
private final String FIXED_BIN_SIZE_SELECTION="fixedBinSizeSelection";
48+
private final String BIN_SIZE = "binSize";
4849
private final String COLUMN = "columnExpression";
49-
5050
private final String MIN = "min";
5151
private final String MAX = "max";
5252
// private final String ALGORITHM = "algorithm";
5353
private final String FALSEPOSTIVERATE = "falsePositiveRate";
5454
private final String PRESERVE_EMPTY_BIN="preserveEmptyBins";
5555
private String algorithm = null;// FIXED_SIZE_ALGORITHM;
56-
private int numBins;
56+
private int numBins=0;
57+
private double binWidth=0.0;
58+
private String binSelection;
59+
private String binSize;
5760
private double min = Double.NaN;
5861
private double max = Double.NaN;
5962
private String columnExpression;
@@ -155,17 +158,32 @@ private void getParameters(TableServerRequest tableServerRequest) {
155158

156159
} else if (name.equalsIgnoreCase(MAX)) {
157160
max = Double.parseDouble(value);
158-
} else if (name.equalsIgnoreCase(NUMBER_BINS)) {
159-
numBins = Integer.parseInt(value);
160-
if (numBins>0) algorithm = FIXED_SIZE_ALGORITHM;
161-
} else if (name.equalsIgnoreCase(FALSEPOSTIVERATE)) {
161+
} else if (name.equalsIgnoreCase(FIXED_BIN_SIZE_SELECTION)) {
162+
binSelection = value;
163+
// numBins = Integer.parseInt(value);
164+
// if (numBins>0) algorithm = FIXED_SIZE_ALGORITHM;
165+
} else if (name.equalsIgnoreCase(BIN_SIZE)) {
166+
binSize = value;
167+
}
168+
else if (name.equalsIgnoreCase(FALSEPOSTIVERATE)) {
162169
falsePostiveRate = Double.parseDouble(value);
163170
}
164171
else if (name.equalsIgnoreCase(PRESERVE_EMPTY_BIN) ){
165172
showEmptyBin= Boolean.parseBoolean(value);
166173
}
167174
}
168175

176+
177+
if (binSelection.equalsIgnoreCase("numBins")){
178+
numBins = Integer.parseInt(binSize);
179+
}
180+
else if (binSelection.equalsIgnoreCase("binWidth") ) {
181+
binWidth = Double.parseDouble(binSize);
182+
183+
}
184+
if (numBins>0 || binWidth>0.0 ){
185+
algorithm = FIXED_SIZE_ALGORITHM;
186+
}
169187
}
170188

171189
private void addFormatInfoAtt(DataGroup dg, DataType dt) {
@@ -233,13 +251,15 @@ private Object[] calculateFixedBinSizeDataArray(double[] columnData) {
233251
}
234252

235253

236-
double binSize = (max-min)/numBins;
254+
double binSize =numBins>0? (max-min)/numBins:binWidth;
255+
256+
int nBins = numBins>0? numBins : (int) Math.ceil((max-min)/binSize);
237257

238258
// double delta =( max -min)/100*numBins;
239-
long[] numPointsInBin = new long[numBins];
240-
double[] binMin = new double[numBins];
259+
long[] numPointsInBin = new long[nBins];
260+
double[] binMin = new double[nBins];
241261

242-
double[] binMax = new double[numBins];
262+
double[] binMax = new double[nBins];
243263

244264
int iBin;
245265
for (int i = 0; i < columnData.length; i++) {
@@ -249,11 +269,11 @@ private Object[] calculateFixedBinSizeDataArray(double[] columnData) {
249269

250270
}
251271
else if (columnData[i] == max) { //put the last data in the last bin
252-
numPointsInBin[numBins - 1]++;
272+
numPointsInBin[nBins - 1]++;
253273
}
254274

255275
}
256-
for (int i=0; i<numBins; i++){
276+
for (int i=0; i<nBins; i++){
257277
binMin[i]=min+i*binSize;
258278
binMax[i]=binMin[i]+binSize;
259279
}

src/firefly/js/charts/dataTypes/HistogramCDT.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ function getServerCallParameters(histogramParams) {
6666
return [
6767
histogramParams.columnOrExpr,
6868
histogramParams.x && histogramParams.x.includes('log'),
69+
histogramParams.binWidth,
6970
histogramParams.numBins,
70-
histogramParams.falsePositiveRate
71+
histogramParams.fixedBinSizeSelection,
72+
histogramParams.falsePositiveRate,
73+
histogramParams.minCutoff,
74+
histogramParams.maxCutoff
7175
];
7276
}
7377

@@ -104,20 +108,23 @@ function fetchColData(dispatch, chartId, chartDataElementId) {
104108
if (histogramParams.x && histogramParams.x.includes('log')) {
105109
req.columnExpression = 'log('+req.columnExpression+')';
106110
}
107-
if (histogramParams.numBins) { // fixed size bins
108-
req.numBins = histogramParams.numBins;
111+
if (histogramParams.fixedBinSizeSelection) { // fixed size bins
112+
req.fixedBinSizeSelection=histogramParams.fixedBinSizeSelection;
113+
if (histogramParams.fixedBinSizeSelection==='numBins'){
114+
req.binSize = histogramParams.numBins;
115+
}else{
116+
req.binSize = histogramParams.binWidth;
117+
}
109118
}
110119
if (histogramParams.falsePositiveRate) { // variable size bins using Bayesian Blocks
111120
req.falsePositiveRate = histogramParams.falsePositiveRate;
112121
}
113-
/*
114122
if (histogramParams.minCutoff) {
115123
req.min = histogramParams.minCutoff;
116124
}
117125
if (histogramParams.maxCutoff) {
118126
req.max = histogramParams.maxCutoff;
119127
}
120-
*/
121128

122129
req.tbl_id = 'histogram-'+chartId;
123130

0 commit comments

Comments
 (0)