Skip to content

Commit

Permalink
fix(config): add additional property to control extension
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdickerson committed Dec 18, 2019
1 parent 43cd481 commit 2da3404
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/core/src/components/axes/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,20 @@ export class Axis extends Component {

if (axisOptions.scaleType === ScaleTypes.TIME) {
if (Tools.getProperty(options, "timeScale", "addSpaceOnEdges")) {
const timeRangeToExtend = Tools.getProperty(options, "timeScale", "timeRangeToExtend")
const startDate = new Date(domain[0]);
const endDate = new Date(domain[1]);
if (differenceInYears(endDate, startDate) > 3) {
if (differenceInYears(endDate, startDate) > timeRangeToExtend) {
return [subYears(startDate, 1), addYears(endDate, 1)];
}
if (differenceInMonths(endDate, startDate) > 3) {
if (differenceInMonths(endDate, startDate) > timeRangeToExtend) {
return [subMonths(startDate, 1), addMonths(endDate, 1)];
}
if (differenceInDays(endDate, startDate) > 3) {
if (differenceInDays(endDate, startDate) > timeRangeToExtend) {
return [subDays(startDate, 1), addDays(endDate, 1)];
} else if (differenceInHours(endDate, startDate) > 3) {
} else if (differenceInHours(endDate, startDate) > timeRangeToExtend) {
return [subHours(startDate, 1), addHours(endDate, 1)];
} else if (differenceInMinutes(endDate, startDate) > 3) {
} else if (differenceInMinutes(endDate, startDate) > timeRangeToExtend) {
return [subMinutes(startDate, 1), addMinutes(endDate, 1)];
}
// Other
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export const barChartTooltip: BarTooltipOptions = Tools.merge({}, axisChartToolt
const axes: AxesOptions = { };

const timeScale: TimeScaleOptions = {
addSpaceOnEdges: true
addSpaceOnEdges: true,
// Only extends the axes if the timerange is greater than this amount
timeRangeToExtend: 3
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/interfaces/axis-scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export interface AxesOptions {
*/
export interface TimeScaleOptions {
addSpaceOnEdges?: boolean;
timeRangeToExtend?: number;
}

0 comments on commit 2da3404

Please sign in to comment.