diff --git a/packages/perspective-viewer-d3fc/src/js/axis/crossAxis.js b/packages/perspective-viewer-d3fc/src/js/axis/crossAxis.js index 0702c465f3..62c4a5e115 100644 --- a/packages/perspective-viewer-d3fc/src/js/axis/crossAxis.js +++ b/packages/perspective-viewer-d3fc/src/js/axis/crossAxis.js @@ -42,17 +42,28 @@ const flattenArray = array => { } }; +const getMinimumGap = (data, dataMap) => + data + .map(dataMap) + .sort((a, b) => a - b) + .filter((d, i, a) => i === 0 || d !== a[i - 1]) + .reduce((acc, d, i, src) => (i === 0 || acc <= d - src[i - 1] ? acc : d - src[i - 1])); + export const domain = settings => { let valueName = "crossValue"; let settingName = "crossValues"; - const extentTime = fc.extentTime().accessors([d => new Date(d[valueName])]); + const extentTime = fc + .extentTime() + .accessors([d => new Date(d[valueName])]) + .padUnit("domain"); const _domain = function(data) { const flattenedData = flattenArray(data); switch (axisType(settings, settingName)) { case AXIS_TYPES.time: - return extentTime(flattenedData); + const dataWidth = getMinimumGap(flattenedData, d => new Date(d[valueName]).getTime()); + return extentTime.pad([dataWidth / 2, dataWidth / 2])(flattenedData); default: return [...new Set(flattenedData.map(d => d[valueName]))]; } diff --git a/packages/perspective-viewer-d3fc/src/js/charts/bar.js b/packages/perspective-viewer-d3fc/src/js/charts/bar.js index 0aef221720..f886a4e4c3 100644 --- a/packages/perspective-viewer-d3fc/src/js/charts/bar.js +++ b/packages/perspective-viewer-d3fc/src/js/charts/bar.js @@ -27,16 +27,11 @@ function barChart(container, settings) { .settings(settings) .scale(color); + const bars = barSeries(settings, color).orient("horizontal"); const series = fc .seriesSvgMulti() .mapping((data, index) => data[index]) - .series( - data.map(() => - barSeries(settings, color) - .align("left") - .orient("horizontal") - ) - ); + .series(data.map(() => bars)); const yDomain = crossAxis .domain(settings)(data) @@ -68,8 +63,11 @@ function barChart(container, settings) { .xNice() .plotArea(withGridLines(series).orient("horizontal")); - chart.yPaddingInner && chart.yPaddingInner(0.5); - chart.yPaddingOuter && chart.yPaddingOuter(0.25); + if (chart.yPaddingInner) { + chart.yPaddingInner(0.5); + chart.yPaddingOuter(0.25); + bars.align("left"); + } const zoomChart = zoomableChart() .chart(chart) diff --git a/packages/perspective-viewer-d3fc/src/js/charts/column.js b/packages/perspective-viewer-d3fc/src/js/charts/column.js index 40a165f913..b51084a1d9 100644 --- a/packages/perspective-viewer-d3fc/src/js/charts/column.js +++ b/packages/perspective-viewer-d3fc/src/js/charts/column.js @@ -26,16 +26,11 @@ function columnChart(container, settings) { .settings(settings) .scale(color); + const bars = barSeries(settings, color).orient("vertical"); const series = fc .seriesSvgMulti() .mapping((data, index) => data[index]) - .series( - data.map(() => - barSeries(settings, color) - .align("left") - .orient("vertical") - ) - ); + .series(data.map(() => bars)); const xDomain = crossAxis.domain(settings)(data); const xScale = crossAxis.scale(settings); @@ -62,8 +57,11 @@ function columnChart(container, settings) { .yNice() .plotArea(withGridLines(series).orient("vertical")); - chart.xPaddingInner && chart.xPaddingInner(0.5); - chart.xPaddingOuter && chart.xPaddingOuter(0.25); + if (chart.xPaddingInner) { + chart.xPaddingInner(0.5); + chart.xPaddingOuter(0.25); + bars.align("left"); + } const zoomChart = zoomableChart() .chart(chart) diff --git a/packages/perspective-viewer-d3fc/src/js/charts/heatmap.js b/packages/perspective-viewer-d3fc/src/js/charts/heatmap.js index 0a7556bf74..603519081b 100644 --- a/packages/perspective-viewer-d3fc/src/js/charts/heatmap.js +++ b/packages/perspective-viewer-d3fc/src/js/charts/heatmap.js @@ -58,10 +58,16 @@ function heatmapChart(container, settings) { .yOrient("left") .plotArea(withGridLines(series)); - chart.xPaddingInner && chart.xPaddingInner(0); - chart.xPaddingOuter && chart.xPaddingOuter(0); - chart.yPaddingInner && chart.yPaddingInner(0); - chart.yPaddingOuter && chart.yPaddingOuter(0); + if (chart.xPaddingInner) { + chart.xPaddingInner(0); + chart.xPaddingOuter(0); + series.xAlign("right"); + } + if (chart.yPaddingInner) { + chart.yPaddingInner(0); + chart.yPaddingOuter(0); + series.yAlign("top"); + } const zoomChart = zoomableChart() .chart(chart) diff --git a/packages/perspective-viewer-d3fc/src/js/series/heatmapSeries.js b/packages/perspective-viewer-d3fc/src/js/series/heatmapSeries.js index 950ad4bf1f..5bb8d88335 100644 --- a/packages/perspective-viewer-d3fc/src/js/series/heatmapSeries.js +++ b/packages/perspective-viewer-d3fc/src/js/series/heatmapSeries.js @@ -22,7 +22,5 @@ export function heatmapSeries(settings, color) { .yValue(d => d.mainValue) .colorValue(d => d.colorValue) .colorInterpolate(color.interpolator()) - .xAlign("right") - .yAlign("top") .widthFraction(1.0); }