Skip to content

Commit

Permalink
Merge pull request #112 from redbearsam/fix/data-extents
Browse files Browse the repository at this point in the history
Implemented fix for missing final date value
  • Loading branch information
Ro4052 authored Mar 22, 2019
2 parents 240e94e + ec00be8 commit 90007e9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
15 changes: 13 additions & 2 deletions packages/perspective-viewer-d3fc/src/js/axis/crossAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]))];
}
Expand Down
16 changes: 7 additions & 9 deletions packages/perspective-viewer-d3fc/src/js/charts/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions packages/perspective-viewer-d3fc/src/js/charts/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions packages/perspective-viewer-d3fc/src/js/charts/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 90007e9

Please sign in to comment.