Skip to content

Commit 7a4c569

Browse files
authored
DM-10832 Heatmap (density) plot in multitrace chart, pr #411
Heatmap (density) plot in multitrace chart
2 parents 1215c1c + 42002e4 commit 7a4c569

File tree

16 files changed

+541
-41
lines changed

16 files changed

+541
-41
lines changed

src/firefly/html/demo/ffapi-highlevel-charttest.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ <h2>
2323
</h2>
2424
</div>
2525

26+
<div id="table-lg" style="width: 800px; height: 550px; border: solid 1px;"></div>
27+
<br/><br/>
28+
<div id="heatmapHere" style="width: 800px; height: 550px; border: solid 1px;"></div>
29+
<br/><br/>
2630
<div id="histogramHere" style="width: 800px; height: 550px; border: solid 1px"></div>
2731
<br/><br/>
2832
<div id="xyplotHere" style="width: 800px; height: 550px; border: solid 1px;"></div>
2933
<br/><br/>
3034
<div id="plotly" style="resize: both; overflow: auto; padding: 5px; width: 800px; height: 550px; border: solid 1px gray;"></div>
3135
<br/><br/>
3236
<div id="table-1" style="width: 800px; height: 550px; border: solid 1px;"></div>
37+
<br/><br/>
3338

3439
<script type="text/javascript">
3540
if (!window.firefly) window.firefly= {};
@@ -170,6 +175,47 @@ <h2>
170175

171176
firefly.showPlot('plotly', {chartId: 'plotly-tbl', chartType: 'plot.ly', data: [trace1], fireflyData: [{dataType: 'fireflyScatter'}]});
172177

178+
179+
var tblReqLg = firefly.util.table.makeIrsaCatalogRequest('allwise_p3as_psd', 'WISE', 'allwise_p3as_psd',
180+
{ position: '10.68479;41.26906;EQ_J2000',
181+
SearchMethod: 'Cone',
182+
radius: 1200
183+
},
184+
{tbl_id: 'test-tbl-lg'});
185+
firefly.showTable('table-lg', tblReqLg);
186+
187+
var dataHM = [
188+
{
189+
type: 'heatmap',
190+
name: 'w1-w2',
191+
x: "tables::test-tbl-lg,w1mpro",
192+
y: "tables::test-tbl-lg,w2mpro",
193+
colorscale: 'Blues'
194+
},
195+
{
196+
type: 'heatmap',
197+
name: 'w1-w3',
198+
x: "tables::test-tbl-lg,w1mpro",
199+
y: "tables::test-tbl-lg,w3mpro",
200+
colorscale: 'Reds',
201+
reversescale: true
202+
},
203+
{
204+
type: 'heatmap',
205+
name: 'w1-w4',
206+
x: "tables::test-tbl-lg,w1mpro",
207+
y: "tables::test-tbl-lg,w4mpro",
208+
colorscale: 'Greens'
209+
}
210+
];
211+
var fireflyDataHM = [
212+
{dataType: 'fireflyHeatmap'},
213+
{dataType: 'fireflyHeatmap'},
214+
{dataType: 'fireflyHeatmap'}
215+
];
216+
217+
firefly.showPlot('heatmapHere', {chartId: 'plotly-tbl-lg', chartType: 'plot.ly', data: dataHM, fireflyData: fireflyDataHM});
218+
173219
}
174220
}
175221

src/firefly/java/edu/caltech/ipac/firefly/data/DecimateInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class DecimateInfo implements Serializable, Comparable {
2626
private double yMin = Double.NaN;
2727
private double yMax = Double.NaN;
2828

29+
private int deciEnableSize = -1;
30+
2931
public DecimateInfo() {
3032
}
3133

@@ -104,6 +106,10 @@ public void setYMax(double yMax) {
104106
this.yMax = yMax;
105107
}
106108

109+
public int getDeciEnableSize() { return this.deciEnableSize; }
110+
111+
public void setDeciEnableSize(int deciEnableSize) { this.deciEnableSize = deciEnableSize; }
112+
107113
public boolean isValid() {
108114
return !StringUtils.isEmpty(xColumnName) && !StringUtils.isEmpty(yColumnName);
109115
}
@@ -137,6 +143,9 @@ public static DecimateInfo parse(String str) {
137143
if (values.length > 7 && !StringUtils.isEmpty(values[7])) {
138144
dinfo.setYMax(StringUtils.getDouble(values[7]));
139145
}
146+
if (values.length > 8 && !StringUtils.isEmpty(values[8])) {
147+
dinfo.setDeciEnableSize(StringUtils.getInt(values[8], -1));
148+
}
140149

141150
return dinfo.isValid() ? dinfo : null;
142151
}
@@ -152,6 +161,7 @@ public String toString() {
152161
s += "," + (Double.isNaN(xMax) ? "" : xMax);
153162
s += "," + (Double.isNaN(yMin) ? "" : yMin);
154163
s += "," + (Double.isNaN(yMax) ? "" : yMax);
164+
s += "," + (deciEnableSize > -1 ? "" : deciEnableSize);
155165
return s;
156166
}
157167

src/firefly/java/edu/caltech/ipac/firefly/server/util/QueryUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ public static DataGroup doDecimation(DataGroup dg, DecimateInfo decimateInfo) th
638638

639639
int maxPoints = decimateInfo.getMaxPoints() == 0 ? DECI_DEF_MAX_POINTS : decimateInfo.getMaxPoints();
640640

641-
boolean doDecimation = dg.size() >= DECI_ENABLE_SIZE;
641+
int deciEnableSize = decimateInfo.getDeciEnableSize() > -1 ? decimateInfo.getDeciEnableSize() : DECI_ENABLE_SIZE;
642+
boolean doDecimation = dg.size() >= deciEnableSize;
642643

643644
DataType[] columns = new DataType[doDecimation ? 5 : 3];
644645
Class xColClass = Double.class;
@@ -739,7 +740,7 @@ public static DataGroup doDecimation(DataGroup dg, DecimateInfo decimateInfo) th
739740
if (yDeciMax < yMax) { yMax = yDeciMax; checkLimits = true; }
740741
}
741742

742-
if (outRows < DECI_ENABLE_SIZE) {
743+
if (outRows < deciEnableSize) {
743744
// no decimation needed
744745
// because the number of rows in the output
745746
// is less than decimation limit

src/firefly/js/charts/ChartUtil.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ import {Expression} from '../util/expr/Expression.js';
1919
import {logError, flattenObject} from '../util/WebUtil.js';
2020
import {UI_PREFIX} from './ChartsCntlr.js';
2121
import {ScatterOptions} from './ui/options/ScatterOptions.jsx';
22+
import {HeatmapOptions} from './ui/options/HeatmapOptions.jsx';
2223
import {FireflyHistogramOptions} from './ui/options/FireflyHistogramOptions.jsx';
2324
import {HistogramOptions} from './ui/options/PlotlyHistogramOptions.jsx';
2425
import {BasicOptions} from './ui/options/BasicOptions.jsx';
2526
import {ScatterToolbar, BasicToolbar} from './ui/PlotlyToolbar';
2627
import {SelectInfo} from '../tables/SelectInfo.js';
2728
import {getTraceTSEntries as scatterTSGetter} from './dataTypes/FireflyScatter.js';
2829
import {getTraceTSEntries as histogramTSGetter} from './dataTypes/FireflyHistogram.js';
30+
import {getTraceTSEntries as heatmapTSGetter} from './dataTypes/FireflyHeatmap.js';
2931

3032
export const SCATTER = 'scatter';
33+
export const HEATMAP = 'heatmap';
3134
export const HISTOGRAM = 'histogram';
3235

3336
export const SELECTED_COLOR = '#ffc800';
@@ -272,6 +275,7 @@ export function getRowIdx(traceData, pointIdx) {
272275
*/
273276
export function getPointIdx(traceData, rowIdx) {
274277
const rowIdxArray = get(traceData, 'firefly.rowIdx');
278+
// use double equal in case we compare string to Number
275279
return rowIdxArray ? rowIdxArray.findIndex((e) => e == rowIdx) : rowIdx;
276280
}
277281

@@ -286,13 +290,15 @@ export function getOptionsUI(chartId) {
286290
return HistogramOptions;
287291
} else if (dataType === 'fireflyHistogram') {
288292
return FireflyHistogramOptions;
293+
} else if (dataType === 'fireflyHeatmap') {
294+
return HeatmapOptions;
289295
} else {
290296
return BasicOptions;
291297
}
292298
}
293299

294300
export function getToolbarUI(chartId, activeTrace=0) {
295-
const {data, fireflyData} = getChartData(chartId);
301+
const {data} = getChartData(chartId);
296302
const type = get(data, [activeTrace, 'type'], '');
297303
if (type.includes('scatter')) {
298304
return ScatterToolbar;
@@ -501,6 +507,8 @@ function getTraceTSEntries({chartDataType, traceTS, chartId, traceNum}) {
501507
return scatterTSGetter({traceTS, chartId, traceNum});
502508
} else if (chartDataType === 'fireflyHistogram') {
503509
return histogramTSGetter({traceTS, chartId, traceNum});
510+
} else if (chartDataType === 'fireflyHeatmap') {
511+
return heatmapTSGetter({traceTS, chartId, traceNum});
504512
} else {
505513
return {};
506514
}
@@ -558,12 +566,18 @@ const TRACE_COLORS = [ '#333333', '#ff3333', '#00ccff','#336600',
558566
export function getNewTraceDefaults(type='', traceNum=0) {
559567
if (type.includes(SCATTER)) {
560568
return {
561-
[`data.${traceNum}.type`] : type, //make sure trace type is set
569+
[`data.${traceNum}.type`]: type, //make sure trace type is set
562570
[`data.${traceNum}.marker.color`]: TRACE_COLORS[traceNum] || undefined,
563571
[`data.${traceNum}.marker.line`]: 'none',
564572
[`data.${traceNum}.showlegend`]: true,
565-
['layout.xaxis.range'] : undefined, //clear out fixed range
566-
['layout.yaxis.range'] : undefined, //clear out fixed range
573+
['layout.xaxis.range']: undefined, //clear out fixed range
574+
['layout.yaxis.range']: undefined //clear out fixed range
575+
};
576+
} else if (type.includes(HEATMAP)) {
577+
return {
578+
[`data.${traceNum}.showlegend`]: true,
579+
['layout.xaxis.range']: undefined, //clear out fixed range
580+
['layout.yaxis.range']: undefined //clear out fixed range
567581
};
568582
} else {
569583
return {

src/firefly/js/charts/ChartsCntlr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function setActiveTrace(action) {
438438
const {selectInfo, highlightedRow} = getTblById(tbl_id) || {};
439439
if (selectInfo) {
440440
const selectInfoCls = SelectInfo.newInstance(selectInfo);
441-
const selIndexes = Array.from(selectInfoCls.getSelected()).map((e)=>getPointIdx(data[activeTrace], e));;
441+
const selIndexes = Array.from(selectInfoCls.getSelected()).map((e)=>getPointIdx(data[activeTrace], e));
442442
if (selIndexes.length > 0) {
443443
selected = newTraceFrom(data[activeTrace], selIndexes, SELECTED_PROPS);
444444
}

0 commit comments

Comments
 (0)