Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/firefly/js/charts/ChartUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function colWithName(cols, name) {
function getNumericCols(cols) {
const ncols = [];
cols.forEach((c) => {
if (c.type.match(/^[dfil]/) != null) { // int, float, double, long .. or their short form.
if (c.type.match(/^[dfil]/) !== null) { // int, float, double, long .. or their short form.
ncols.push(c);
}
});
Expand Down Expand Up @@ -153,7 +153,7 @@ export function getDefaultXYPlotParams(tbl_id) {
// otherwise use the first one-two numeric columns
if (!isCatalog) {
const numericCols = getNumericCols(tableData.columns);
if (numericCols.length > 2) {
if (numericCols.length >= 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good fix too! Thanks!

xCol = numericCols[0];
yCol = numericCols[1];
} else if (numericCols.length > 1) {
Expand Down
39 changes: 30 additions & 9 deletions src/firefly/js/charts/XYPlotCntlr.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,48 @@ function getDataBoundaries(xyPlotData) {
}
}

function getPaddedRange(min, max, isLog, factor) {
const range = max - min;
let paddedMin = min;
let paddedMax = max;

if (range > 0) {
if (isLog) {
const minLog = Math.log10(min);
const maxLog = Math.log10(max);
const padLog = (maxLog - minLog) / factor;
paddedMin = Math.pow(10, (minLog-padLog));
paddedMax = Math.pow(10, (maxLog+padLog));
} else {
const pad = range / factor;
paddedMin = min - pad;
paddedMax = max + pad;
}
}
return {paddedMin, paddedMax};
}

/**
* Pad and round data boundaries
* @param {Object} xyPlotParams - object with XY plot params
* @param {Object} boundaries - object with xMin, xMax, yMin, yMax props
* @param {Number} factor - part of the range to add on both sides
*/
function getPaddedBoundaries(boundaries, factor=100) {
function getPaddedBoundaries(xyPlotParams, boundaries, factor=100) {
if (!isEmpty(boundaries)) {
let {xMin, xMax, yMin, yMax} = boundaries;
const xRange = xMax - xMin;

const xRange = xMax - xMin;
if (xRange > 0) {
const xPad = xRange/factor;
xMin = xMin - xPad;
xMax = xMax + xPad;
const xOptions = get(xyPlotParams, 'x.options');
const xLog = xOptions && xOptions.includes('log') && xMin>0;
({paddedMin:xMin, paddedMax:xMax} = getPaddedRange(xMin, xMax, xLog, factor));
}
const yRange = yMax - yMin;
if (yRange > 0) {
const yPad = yRange/factor;
yMin = yMin - yPad;
yMax = yMax + yPad;
const yOptions = get(xyPlotParams, 'y.options');
const yLog = yOptions && yOptions.includes('log') && yMin>0;
({paddedMin:yMin, paddedMax:yMax} = getPaddedRange(yMin, yMax, yLog, factor));
}
if (xRange > 0 || yRange > 0) {
return {xMin, xMax, yMin, yMax};
Expand Down Expand Up @@ -449,7 +470,7 @@ function getUpdatedParams(xyPlotParams, tableModel, dataBoundaries) {
const userSetBoundaries = get(xyPlotParams, 'userSetBoundaries', {});
const boundaries = Object.assign({}, userSetBoundaries);
if (Object.keys(boundaries).length < 4 && !isEmpty(dataBoundaries)) {
const paddedDataBoundaries = getPaddedBoundaries(dataBoundaries);
const paddedDataBoundaries = getPaddedBoundaries(xyPlotParams, dataBoundaries);
const [xMin, xMax, yMin, yMax] = ['xMin', 'xMax', 'yMin', 'yMax'].map( (v) => {
return (Number.isFinite(boundaries[v]) ? boundaries[v] : paddedDataBoundaries[v]);
});
Expand Down
Loading