Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
updated test & resolved commets
Browse files Browse the repository at this point in the history
  • Loading branch information
UM100080 authored and UM100080 committed Nov 20, 2023
1 parent f0183ce commit beb094a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 63 deletions.
6 changes: 3 additions & 3 deletions packages/carbon-graphs/src/js/helpers/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,14 +904,14 @@ const createAxes = (axis, scale, config, canvasSVG) => {
const rotation = config.axis.x.ticks.tickLabelsRotation;
if (rotation === 0) {
return 'middle';
} if (rotation === -45) {
} if (rotation < 0) {
return 'end';
} if (!utils.validTickLabelRotations.has(rotation)) {
return 'middle';
}
return 'middle';
})
.attr('transform', () => `rotate(${config.axis.x.ticks.tickLabelsRotation === -45 ? -45 : 0})`);
.attr('transform', () => `rotate(${config.axis.x.ticks.tickLabelsRotation})`);
canvasSVG
.append('g')
.classed(styles.axis, true)
Expand Down Expand Up @@ -1139,7 +1139,7 @@ const getXAxisHeight = (config) => {
const dummy = d3.select('body').append('div');
const svg = dummy.append('svg');
const group = svg.append('g').call(axis);
if (config.axis.x.ticks && config.axis.x.ticks.tickLabelsRotation === -45) {
if (config.axis.x.ticks && config.axis.x.ticks.tickLabelsRotation !== 0) {
// Add extra padding for rotated tick labels
group.selectAll('.tick text').attr('transform', `rotate(${config.axis.x.ticks.tickLabelsRotation})`);
const rotatedTickLabelsHeight = group.node().getBoundingClientRect().height;
Expand Down
74 changes: 14 additions & 60 deletions packages/carbon-graphs/tests/unit/controls/Graph/GraphAxes-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2941,28 +2941,12 @@ describe('Graph - Axes', () => {
upperLimit: new Date(2017, 6).toISOString(),
};
localeAxisObj.x.ticks = {
format: '%b %Y',
show: true,
lowerStepTickValues: [
new Date(2017, 1).toISOString(),
new Date(2017, 5).toISOString(),
new Date(2017, 9).toISOString(),
],
midpointTickValues: [
new Date(2017, 3).toISOString(),
new Date(2017, 7).toISOString(),
new Date(2017, 11).toISOString(),
],
upperStepTickValues: [
new Date(2016, 11).toISOString(),
new Date(2018, 1).toISOString(),
],
tickLabelsRotation: 0,
};
graph = new Graph(getAxes(localeAxisObj));
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(0);
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);
});
fit('tickLabelsRotation values will be 0 or -45', () => {
it('tickLabelsRotation values will be 0 or -45', () => {
const localeAxisObj = utils.deepClone(axisTimeSeries);
localeAxisObj.x = {
type: 'timeseries',
Expand All @@ -2971,60 +2955,30 @@ describe('Graph - Axes', () => {
upperLimit: new Date(2017, 6).toISOString(),
};
localeAxisObj.x.ticks = {
format: '%b %Y',
show: true,
lowerStepTickValues: [
new Date(2017, 1).toISOString(),
new Date(2017, 5).toISOString(),
new Date(2017, 9).toISOString(),
],
midpointTickValues: [
new Date(2017, 3).toISOString(),
new Date(2017, 7).toISOString(),
new Date(2017, 11).toISOString(),
],
upperStepTickValues: [
new Date(2016, 11).toISOString(),
new Date(2018, 1).toISOString(),
],
tickLabelsRotation: -45,
};
graph = new Graph(getAxes(localeAxisObj));
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(-45);
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(-45);
});
fit('tickLabelsRotation default zero', () => {
it('uses the default value of zero if tickLabelsRotation it is invalid', () => {
const localeAxisObj = utils.deepClone(axisTimeSeries);
localeAxisObj.x = {
type: 'timeseries',
label: 'Some X Label',
lowerLimit: new Date(2017, 0).toISOString(),
upperLimit: new Date(2017, 6).toISOString(),
};
localeAxisObj.x.ticks = {
format: '%b %Y',
show: true,
lowerStepTickValues: [
new Date(2017, 1).toISOString(),
new Date(2017, 5).toISOString(),
new Date(2017, 9).toISOString(),
],
midpointTickValues: [
new Date(2017, 3).toISOString(),
new Date(2017, 7).toISOString(),
new Date(2017, 11).toISOString(),
],
upperStepTickValues: [
new Date(2016, 11).toISOString(),
new Date(2018, 1).toISOString(),
],
tickLabelsRotation: 23,
};
// Spy on console.warn
spyOn(console, 'warn');
// Call the code that logs the warning
graph = new Graph(getAxes(localeAxisObj));

expect(console.warn).toHaveBeenCalledWith('23 is an invalid value for tickLabelsRotation. Valid values are: 0, -45. Resorting to the default value of 0');
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);
});
it('uses the default value of zero if tickLabelsRotation it is undefind', () => {
const localeAxisObj = utils.deepClone(axisTimeSeries);
localeAxisObj.x.ticks = {
// tickLabelsRotation is undefind
};
graph = new Graph(getAxes(localeAxisObj));

expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);
});
});
describe('when graph is destroyed', () => {
Expand Down

0 comments on commit beb094a

Please sign in to comment.