Skip to content

Commit

Permalink
fix(axis): remove confusing timeRangeToExtend property
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdickerson committed Jan 17, 2020
1 parent 3b92c4b commit 0456e24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
24 changes: 12 additions & 12 deletions packages/core/src/components/axes/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ export class Axis extends Component {
}

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

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

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/interfaces/axis-scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ export interface AxesOptions {
* customize time series scales
*/
export interface TimeScaleOptions {
addSpaceOnEdges?: boolean;
timeRangeToExtend?: number;
addSpaceOnEdges?: number;
}

0 comments on commit 0456e24

Please sign in to comment.