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

added prop rotateAngle to avoid the overlapping x-axis tick values #322

Merged
merged 10 commits into from
Nov 24, 2023

Conversation

udaymattam
Copy link
Contributor

@udaymattam udaymattam commented Nov 6, 2023

Summary

What was changed:
added new prop called rotateAngle to avoid the x-axis overlapping tick values.
with prop rotateAngle: -45
Screenshot 2023-11-07 at 4 13 32 PM

with prop rotateAngle: 40
Screenshot 2023-11-07 at 4 14 07 PM

Why it was changed:

Testing

This change was tested using:

  • WDIO
  • Jest
  • Visual testing (please attach a screenshot or recording)
  • Other (please describe below)
  • No tests are needed

Reviews

In addition to engineering reviews, this PR needs:

  • UX review
  • Accessibility review
  • Functional review

Additional Details

This PR resolves:

UXPLATFORM-XXXX


Thank you for contributing to Terra.
@cerner/terra

Comment on lines 4 to 5
* Fixed
* Fixed tick values overlapping on X-axis by rotating 15,30,45.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fixed
* Fixed tick values overlapping on X-axis by rotating 15,30,45.
* Added
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 3a9d13e

@@ -881,6 +881,8 @@ const getY2AxisYPosition = (config) => calculateVerticalPadding(config);
const createAxes = (axis, scale, config, canvasSVG) => {
getAxesScale(axis, scale, config);
prepareHAxis(scale, axis, config, prepareHorizontalAxis);
// eslint-disable-next-line no-use-before-define
const rotateAngle = config.rotateAngle ? calculateRotateAngleBasedOnWidth(config) : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vague. Since this is an x-axis prop, we can change this toconfig.axis.x.ticks.rotationAngle.

https://engineering.cerner.com/terra-ui/graphs/cerner-terra-graphs-docs/core-configuration/documentation/axes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 3a9d13e

Comment on lines 936 to 942
if (containerWidth < thresholdSmall) {
return -45; // rotate by -45 degrees for small screens
} if (containerWidth < thresholdMedium) {
return -30; // rotate by -30 degrees for medium screens
}
return -15; // rotate by -15 degrees for larger screens
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the solution we agreed upon was to make the prop an integer and let consumers choose the angle as per their own requirements. What if a consumer wants to rotate it by 60º? Or what if they would like to rotate it in the other direction like positive 45º? By hardcoding the values and specifying them per screen size, we risk interpreting their data in ways they do not want it to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 3a9d13e

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdadn we had meetings after that meeting where we decided that we should restrict the available values to the default horizontal or -45º

cc: @mjpalazzo

@sdadn
Copy link
Contributor

sdadn commented Nov 8, 2023

The tick values now overlap with the axis label. I think we'll need to dynamically adjust the padding of the axis label to account for the change in height.

CleanShot 2023-11-07 at 19 33 09@2x

.attr('id', 'x')
.selectAll('text')
.style('text-anchor', () => {
if (config.axis.x.ticks.rotateAngle !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rotateAngle is grammatically incorrect and also unclear without reading the documentation. Can we rename this to tickLabelsRotation?

Suggested change
if (config.axis.x.ticks.rotateAngle !== undefined) {
if (config.axis.x.ticks.tickLabelsRotation !== undefined) {

@@ -80,7 +81,8 @@ axis: {
| show | boolean | `true` | no | Toggle for showing the axis. |
| suppressTrailingZeros | boolean | `false` | no | Toggle to suppress tick values's trailing zeros when default d3 tick formatting is used. For X axis, this property works only when X axis type is set to AXIS_TYPE.DEFAULT. Specifying `~` in the tick format takes precedence over `suppressTrailingZeros` property. |
| ticks | object | `null` | no | See [Ticks](./Ticks). |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| rotateAngle | integer | - | no | allows consumer to add a rotateAngle to x-axis to avoid the overlapping (angle will be in between `+90` to `-90` Positive values move in clock wise direction & negative values moves in anticlock wise direction).Only for x-axis. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid saying "consumer" wherever possible.

Suggested change
| rotateAngle | integer | - | no | allows consumer to add a rotateAngle to x-axis to avoid the overlapping (angle will be in between `+90` to `-90` Positive values move in clock wise direction & negative values moves in anticlock wise direction).Only for x-axis. |
| rotateAngle | integer | - | no | (Only for x-axis) Sets the rotation of the tick labels from `+90º` to `-90º`. Positive values rotate the label clockwise while negative values rotate the label anti-clockwise. |

@sdadn
Copy link
Contributor

sdadn commented Nov 8, 2023

Questions about cases:

  • What happens when the prop is not an integer (string, bool, float etc) ?
  • What happens when the values exceeds +/- 90º ?
  • Is unit of the angle only in degrees? What about radians?

We should add validation for the datatype in this function:

const beforeInit = (control) => {

Copy link

@eawww eawww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two main issues I see:

  • Rotation values should be limited to the default and 45º anti-clockwise (-45º). More values may be added in the future. For now, those are should be the only two values available to consumers.
  • The rotated values overlapping the x-axis label

Comment on lines 4 to 5
* Fixed
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fixed
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap.
* Fixed
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap.

Can we add space for consistency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also correct the prop name

Copy link
Contributor

@sdadn sdadn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Just wondering if the padding is too much (cc: @eawww ) and this will also need unit tests.

@@ -1,6 +1,8 @@
# ChangeLog

## Unreleased
* Fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fixed
* Added

@@ -1122,6 +1137,14 @@ 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.TickLabelRotations === -45) {
// Add extra padding for rotated tick labels
const extraPadding = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should save this in the constants file for easy maintanence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also get UX opinion on the appropriate padding.
cc: @eawww

showShapes: true,
showVGrid: true,
showHGrid: true,
locale: Carbon.helpers.LOCALE.de_DE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the locale german?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was not intentional, I was trying to recreate the issue with tick values(date formatted) having long text in it.

new Date(2016, 0, 10).toISOString(),
new Date(2016, 0, 11).toISOString(),
],
TickLabelRotations: -45,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prop should be tickLabelsRotation.

Suggested change
TickLabelRotations: -45,
tickLabelsRotation: -45,

const dummy = d3.select('body').append('div');
const svg = dummy.append('svg');
const grouper = svg.append('g');

if (TickLabelRotations && TickLabelRotations === -45) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a double condition here? This should be sufficient

Suggested change
if (TickLabelRotations && TickLabelRotations === -45) {
if (TickLabelRotations === -45) {

const validRotations = Object.values(utils.TickLabelRotations);
if (
utils.isDefined(config.axis.x.ticks.TickLabelRotations)
&& validRotations.includes(config.axis.x.ticks.TickLabelRotations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the usage of the set, this will be

Suggested change
&& validRotations.includes(config.axis.x.ticks.TickLabelRotations)
&& validRotations.has(config.axis.x.ticks.TickLabelRotations)

Comment on lines 4 to 5
* Fixed
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also correct the prop name

// Add extra padding for rotated tick labels
const extraPadding = 5;
group.selectAll('.tick text').attr('transform', `rotate(${config.axis.x.ticks.TickLabelRotations})`);
const rotatedHeight = group.node().getBoundingClientRect().height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity:

Suggested change
const rotatedHeight = group.node().getBoundingClientRect().height;
const rotatedTickLabelsHeight = group.node().getBoundingClientRect().height;

&& validRotations.includes(config.axis.x.ticks.TickLabelRotations)
) {
const rotation = config.axis.x.ticks.TickLabelRotations;
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we warning when consumers are deliberately using the prop to set the rotation?

console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`);
return rotation === utils.TickLabelRotations.NEGATIVE_45 ? 'end' : 'middle';
}
console.warn('Warning: Invalid tickLabelsRotation angle. Using default rotation (0 or -45) for x-axis labels.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.warn('Warning: Invalid tickLabelsRotation angle. Using default rotation (0 or -45) for x-axis labels.');
console.warn('Warning: Invalid tickLabelsRotation angle. Valid values are 0 or -45');

We should also be doing this validation in the beforeInit function in Graph.js

const beforeInit = (control) => {

@@ -80,7 +81,8 @@ axis: {
| show | boolean | `true` | no | Toggle for showing the axis. |
| suppressTrailingZeros | boolean | `false` | no | Toggle to suppress tick values's trailing zeros when default d3 tick formatting is used. For X axis, this property works only when X axis type is set to AXIS_TYPE.DEFAULT. Specifying `~` in the tick format takes precedence over `suppressTrailingZeros` property. |
| ticks | object | `null` | no | See [Ticks](./Ticks). |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| TickLabelRotations | integer | - | no | Sets the rotation of the tick labels to `-45º`. Only for x-axis. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| TickLabelRotations | integer | - | no | Sets the rotation of the tick labels to `-45º`. Only for x-axis. |
| TickLabelRotations | integer | - | no | Sets the rotation of the tick labels to `` or `-45º`. Only for x-axis. |

@@ -80,7 +81,8 @@ axis: {
| show | boolean | `true` | no | Toggle for showing the axis. |
| suppressTrailingZeros | boolean | `false` | no | Toggle to suppress tick values's trailing zeros when default d3 tick formatting is used. For X axis, this property works only when X axis type is set to AXIS_TYPE.DEFAULT. Specifying `~` in the tick format takes precedence over `suppressTrailingZeros` property. |
| ticks | object | `null` | no | See [Ticks](./Ticks). |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| type | string | `AXIS_TYPE.DEFAULT` | no | See [type](#type). Normal number value or time-based. Only for x-axis. |
| tickLabelsRotation | integer | - | no | Sets the rotation of the tick labels to `0º` or `-45º`. Only for x-axis. |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the default be 0?

Also, while the integer type implies that the corresponding integer should be used, formatting and -45º as code here is misleading because those aren't the values they'll be using.

Could say something like:
Sets the rotation of the x-axis tick labels to or -45º. Accepted values: 0 or -45

Copy link
Contributor

@sdadn sdadn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there unit tests for this change?

@@ -120,6 +120,13 @@ const beforeInit = (control) => {
console.warn('allowCalibration for x-axis is a new feature that is currently a work in progress and may have stability issues. Use it at your own risk.');
getAxesDataRange({}, constants.X_AXIS, control.config);
}
if (
utils.isDefined(control.config.axis.x.ticks.tickLabelsRotation)
&& utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want this to give a warning when a consumer uses a non-existing value

Suggested change
&& utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation)
&& !utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation)

Comment on lines 127 to 128
const rotation = control.config.axis.x.ticks.tickLabelsRotation;
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant is not necessary. And the message should warn when consumers use an incorrect value.

Suggested change
const rotation = control.config.axis.x.ticks.tickLabelsRotation;
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`);
console.warn(`${control.config.axis.x.ticks.tickLabelsRotation} is an invalid value for tickLabelsRotation. Valid values are: 0, -45. Resorting to the default value of 0`);

const rotation = config.axis.x.ticks.tickLabelsRotation;
return rotation === -45 ? 'end' : 'middle';
}
console.warn('Warning: Invalid tickLabelsRotation angle. Valid values are (0 or -45) for x-axis labels.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this warning here

Comment on lines 900 to 905
if (
utils.isDefined(config.axis.x.ticks.tickLabelsRotation)
&& utils.validTickLabelRotations.has(config.axis.x.ticks.tickLabelsRotation)
) {
const rotation = config.axis.x.ticks.tickLabelsRotation;
return rotation === -45 ? 'end' : 'middle';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (
utils.isDefined(config.axis.x.ticks.tickLabelsRotation)
&& utils.validTickLabelRotations.has(config.axis.x.ticks.tickLabelsRotation)
) {
const rotation = config.axis.x.ticks.tickLabelsRotation;
return rotation === -45 ? 'end' : 'middle';
if (config.axis.x.ticks.tickLabelsRotation === 0)
{
return 'middle' ;

packages/carbon-graphs/src/js/helpers/axis.js Show resolved Hide resolved
) {
const rotation = control.config.axis.x.ticks.tickLabelsRotation;
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a condition where if config.axis.x.ticks.tickLabelsRotation is undefined, then it should be set to 0 as the default value.

const dummy = d3.select('body').append('div');
const svg = dummy.append('svg');
const grouper = svg.append('g');

if (tickLabelsRotation === -45) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it future proof for additional values:

Suggested change
if (tickLabelsRotation === -45) {
if (tickLabelsRotation !== 0) {

* @readonly
* @enum {number}
*/
const validTickLabelRotations = new Set([0, -45]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -1,6 +1,9 @@
# ChangeLog

## Unreleased
* Added
* Added a Prop `rotateAngle` for overlapping X-axis tick values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this entry

Suggested change
* Added a Prop `rotateAngle` for overlapping X-axis tick values.

const rotation = config.axis.x.ticks.tickLabelsRotation;
if (rotation === 0) {
return 'middle';
} if (rotation === -45) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding -45 defeats the purpose of utilizing the set array. We should minimize refactoring done in the future if we need to add more angles. The conditions should be:

tickLabelsRotation = 0 -> return middle
else return end

tickLabelsRotation is undefined and tickLabelsRotation is invalid value -> tickLabelsRotation should be covered by the logic added in Graph.js.

}
return 'middle';
})
.attr('transform', () => `rotate(${config.axis.x.ticks.tickLabelsRotation === -45 ? -45 : 0})`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ternary is unnecessary, we can use the value directly.

@@ -1122,6 +1139,13 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't hardcode -45

Suggested change
if (config.axis.x.ticks && config.axis.x.ticks.tickLabelsRotation === -45) {
if (config.axis.x.ticks && config.axis.x.ticks.tickLabelsRotation !== 0) {

graph = new Graph(getAxes(localeAxisObj));
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(0);
});
fit('tickLabelsRotation values will be 0 or -45', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fit('tickLabelsRotation values will be 0 or -45', () => {
it('tickLabelsRotation values will be 0 or -45', () => {

Comment on lines 2974 to 2989
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(),
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this

Suggested change
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(),
],
format: '%b %Y',
show: true,

// 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

graph = new Graph(getAxes(localeAxisObj));
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(-45);
});
fit('tickLabelsRotation default zero', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fit('tickLabelsRotation default zero', () => {
it('uses the default value of zero if tickLabelsRotation it is invalid', () => {

// 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test it tickLabelsRotation is 0

tickLabelsRotation: 0,
};
graph = new Graph(getAxes(localeAxisObj));
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localeAxisObj is input. We should test for the graphs object in all test cases.

Suggested change
expect(localeAxisObj.x.ticks.tickLabelsRotation).toBe(0);
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);

const rotation = config.axis.x.ticks.tickLabelsRotation;
if (rotation === 0) {
return 'middle';
} if (rotation < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angles can be positive too

Suggested change
} if (rotation < 0) {
} if (rotation !== 0) {

Comment on lines 2935 to 2962
it('tickLabelsRotation values will be 0 or -45', () => {
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 = {
tickLabelsRotation: 0,
};
graph = new Graph(getAxes(localeAxisObj));
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);
});
it('tickLabelsRotation values will be 0 or -45', () => {
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 = {
tickLabelsRotation: -45,
};
graph = new Graph(getAxes(localeAxisObj));
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(-45);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these tests have the same title?

graph = new Graph(getAxes(localeAxisObj));
expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(-45);
});
it('uses the default value of zero if tickLabelsRotation it is invalid', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('uses the default value of zero if tickLabelsRotation it is invalid', () => {
it('uses the default value of zero of tickLabelsRotation it is invalid', () => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you generate wdio screenshots for this test?

@@ -316,4 +316,5 @@ export default {
DEFAULT_LEGEND_LINE_WIDTH: 28,
DEFAULT_LEGEND_LINE_WIDTH_WITH_SYMBOL: 18,
LEGEND_LINE_POSITION: 1.5,
DEFAULT_OVERLAPPING_PADDING: 5,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reviewed by UX:
cc: @eawww

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this is relative to the bottom of the tick labels, the typical value seems to be half of this. I'd like to see what 2.5 looks like.


expect(graph.config.axis.x.ticks.tickLabelsRotation).toBe(0);
});
it('uses the default value of zero if tickLabelsRotation it is undefind', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('uses the default value of zero if tickLabelsRotation it is undefind', () => {
it('uses the default value of zero if tickLabelsRotation is undefind', () => {

Copy link
Contributor

@sdadn sdadn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the above comments are minor and don't break functionality, I'm approving this for now assuming that they get resolved.

Copy link

@eawww eawww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it still needs a consumer facing example. The tests don't appear on the main aggregated doc site.

Copy link

@eawww eawww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "No Data" appears to be in Spanish. It appears in other languages on other examples. Is this a fun quirky feature or an i18n issue?
image


# X-Axis Tick Label orientation

This is a simple timeseries line graph with x-axis ticks label orientation `tickLabelsRotation = -45`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simple timeseries line graph with x-axis ticks label orientation `tickLabelsRotation = -45`. Tick label rotation is used to prevent labels from overlapping in a narrow viewport or due to long tick labels.

@@ -316,4 +316,5 @@ export default {
DEFAULT_LEGEND_LINE_WIDTH: 28,
DEFAULT_LEGEND_LINE_WIDTH_WITH_SYMBOL: 18,
LEGEND_LINE_POSITION: 1.5,
DEFAULT_OVERLAPPING_PADDING: 5,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this is relative to the bottom of the tick labels, the typical value seems to be half of this. I'd like to see what 2.5 looks like.

Comment on lines 123 to 128
if (!utils.isDefined(control.config.axis.x.ticks.tickLabelsRotation)) {
control.config.axis.x.ticks.tickLabelsRotation = 0;
} else if (!utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation)) {
console.warn(`${control.config.axis.x.ticks.tickLabelsRotation} is an invalid value for tickLabelsRotation. Valid values are: 0, -45. Resorting to the default value of 0`);
control.config.axis.x.ticks.tickLabelsRotation = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!utils.isDefined(control.config.axis.x.ticks.tickLabelsRotation)) {
control.config.axis.x.ticks.tickLabelsRotation = 0;
} else if (!utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation)) {
console.warn(`${control.config.axis.x.ticks.tickLabelsRotation} is an invalid value for tickLabelsRotation. Valid values are: 0, -45. Resorting to the default value of 0`);
control.config.axis.x.ticks.tickLabelsRotation = 0;
}
const isInvalidTickLabelRotations = !utils.isDefined(control.config.axis.x.ticks.tickLabelsRotation) || !utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation);
if (isInvalidTickLabelRotations) {
control.config.axis.x.ticks.tickLabelsRotation = 0;
console.warn(`${control.config.axis.x.ticks.tickLabelsRotation} is an invalid value for tickLabelsRotation. Valid values are: 0, -45. Resorting to the default value of 0`);
}

Can we simplify like above ?

Comment on lines 1237 to 1240
if (tickLabelsRotation !== 0) {
// Adding extra padding for rotated labels
grouper.attr('transform', `rotate(${tickLabelsRotation})`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tickLabelsRotation !== 0) {
// Adding extra padding for rotated labels
grouper.attr('transform', `rotate(${tickLabelsRotation})`);
}
if (tickLabelsRotation) {
// Adding extra padding for rotated labels
grouper.attr('transform', `rotate(${tickLabelsRotation})`);
}

Comment on lines 3 to 5
## Unreleased
* Added
* Added examples for the Xaxis Overlapping tick values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Unreleased
* Added
* Added examples for the Xaxis Overlapping tick values.
## Unreleased
* Added
* Added examples for the X Axis Overlapping tick values.

Need a line break for consistency !

Copy link

@eawww eawww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Met with @udaymattam and discussed the last changes needed:

  • Space between the bottom of the x-axis tick labels and the x-axis label should be half of what it is now to be consistent with other examples.
    image

  • There should be a test to ensure that, when the Legend is present at the bottom, it is still positioned the same relative to the x-axis label.

Since I'll be out until next week for the US holiday, putting conditional approval on here so long as the two above changes are made.

@eawww
Copy link

eawww commented Nov 22, 2023

Worked with Uday to fine tune the padding between the tick labels and axis labels. Here is a screenshot of the result
image

We also ensured the legend still had appropriate padding. After these changes, this looks good to me!

@github-actions github-actions bot temporarily deployed to preview-pr-322 November 23, 2023 05:32 Destroyed
@udaymattam udaymattam merged commit f13b8ba into main Nov 24, 2023
9 checks passed
@udaymattam udaymattam deleted the x-axis-overlaping branch November 24, 2023 11:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants