Skip to content

Commit

Permalink
fix(core): fix default axes creation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SerenaG committed Mar 5, 2020
1 parent 03969c3 commit e4fb861
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
39 changes: 7 additions & 32 deletions packages/core/src/components/axes/two-dimensional-axes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Internal Imports
import { Component } from "../component";
import { AxisPositions, ScaleTypes } from "../../interfaces";
import { AxisPositions, ScaleTypes, AxesOptions } from "../../interfaces";
import { Axis } from "./axis";
import { Tools } from "../../tools";
import { DOMUtils } from "../../services";
Expand All @@ -19,40 +19,15 @@ export class TwoDimensionalAxes extends Component {

render(animate = false) {
const axes = {};

const axisPositions = Object.keys(AxisPositions);
const axesOptions = Tools.getProperty(this.model.getOptions(), "axes");

if (axesOptions) {
let primaryAxisOptions, secondaryAxisOptions;
axisPositions.forEach(axisPosition => {
const axisOptions = axesOptions[AxisPositions[axisPosition]];
if (axisOptions) {
axes[AxisPositions[axisPosition]] = true;

if (axisOptions.primary === true) {
primaryAxisOptions = axisOptions;
} else if (axisOptions.secondary === true) {
secondaryAxisOptions = axisOptions;
}
}
});
} else {
this.model.getOptions().axes = {
left: {
primary: true,
includeZero: true
},
bottom: {
secondary: true,
type: this.model.getDisplayData().labels ? ScaleTypes.LABELS : undefined,
includeZero: true
}
};

axes[AxisPositions.LEFT] = true;
axes[AxisPositions.BOTTOM] = true;
}
axisPositions.forEach(axisPosition => {
const axisOptions = axesOptions[AxisPositions[axisPosition]];
if (axisOptions) {
axes[AxisPositions[axisPosition]] = true;
}
});

this.configs.axes = axes;

Expand Down
20 changes: 19 additions & 1 deletion packages/core/src/services/scales-cartesian.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Internal Imports
import * as Configuration from "../configuration";
import { Service } from "./service";
import { AxisPositions, CartesianOrientations, ScaleTypes } from "../interfaces";
import { AxisPositions, CartesianOrientations, ScaleTypes, AxesOptions } from "../interfaces";
import { Tools } from "../tools";

// D3 Imports
Expand Down Expand Up @@ -74,7 +74,25 @@ export class CartesianScales extends Service {
return this.rangeAxisPosition;
}

setDefaultAxes() {
const axesOptions = Tools.getProperty(this.model.getOptions(), "axes");
if (!axesOptions) {
(this.model.getOptions().axes as AxesOptions) = {
left: {
primary: true,
includeZero: true,
},
bottom: {
secondary: true,
includeZero: true,
scaleType: this.model.getDisplayData().labels ? ScaleTypes.LABELS : undefined
}
};
}
}

update(animate = true) {
this.setDefaultAxes();
this.determineOrientation();
const axisPositions = Object.keys(AxisPositions).map(axisPositionKey => AxisPositions[axisPositionKey]);
axisPositions.forEach(axisPosition => {
Expand Down

0 comments on commit e4fb861

Please sign in to comment.