-
Notifications
You must be signed in to change notification settings - Fork 7
added prop rotateAngle to avoid the overlapping x-axis tick values #322
Conversation
packages/carbon-graphs/CHANGELOG.md
Outdated
* Fixed | ||
* Fixed tick values overlapping on X-axis by rotating 15,30,45. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved in 3a9d13e
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 | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved in 3a9d13e
There was a problem hiding this comment.
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
.attr('id', 'x') | ||
.selectAll('text') | ||
.style('text-anchor', () => { | ||
if (config.axis.x.ticks.rotateAngle !== undefined) { |
There was a problem hiding this comment.
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
?
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. | |
There was a problem hiding this comment.
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.
| 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. | |
Questions about cases:
We should add validation for the datatype in this function:
|
There was a problem hiding this 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
packages/carbon-graphs/CHANGELOG.md
Outdated
* Fixed | ||
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
packages/carbon-graphs/CHANGELOG.md
Outdated
@@ -1,6 +1,8 @@ | |||
# ChangeLog | |||
|
|||
## Unreleased | |||
* Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
.
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) { |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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
&& validRotations.includes(config.axis.x.ticks.TickLabelRotations) | |
&& validRotations.has(config.axis.x.ticks.TickLabelRotations) |
packages/carbon-graphs/CHANGELOG.md
Outdated
* Fixed | ||
* Added prop `rotateAngle` to allow rotation of x-axis tick labels to prevent overlap. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity:
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.`); |
There was a problem hiding this comment.
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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 `0º` 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. | |
There was a problem hiding this comment.
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 0º
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 0º
or -45º
. Accepted values: 0
or -45
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
&& utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation) | |
&& !utils.validTickLabelRotations.has(control.config.axis.x.ticks.tickLabelsRotation) |
const rotation = control.config.axis.x.ticks.tickLabelsRotation; | ||
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`); |
There was a problem hiding this comment.
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.
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.'); |
There was a problem hiding this comment.
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
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' ; |
) { | ||
const rotation = control.config.axis.x.ticks.tickLabelsRotation; | ||
console.warn(`tickLabelsRotation Using ${rotation} rotation for x-axis labels to avoid overlapping.`); | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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:
if (tickLabelsRotation === -45) { | |
if (tickLabelsRotation !== 0) { |
* @readonly | ||
* @enum {number} | ||
*/ | ||
const validTickLabelRotations = new Set([0, -45]); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
* 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) { |
There was a problem hiding this comment.
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})`); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fit('tickLabelsRotation values will be 0 or -45', () => { | |
it('tickLabelsRotation values will be 0 or -45', () => { |
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(), | ||
], |
There was a problem hiding this comment.
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
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'); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
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
} if (rotation < 0) { | |
} if (rotation !== 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: 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); | ||
}); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('uses the default value of zero if tickLabelsRotation it is invalid', () => { | |
it('uses the default value of zero of tickLabelsRotation it is invalid', () => { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('uses the default value of zero if tickLabelsRotation it is undefind', () => { | |
it('uses the default value of zero if tickLabelsRotation is undefind', () => { |
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
# X-Axis Tick Label orientation | ||
|
||
This is a simple timeseries line graph with x-axis ticks label orientation `tickLabelsRotation = -45`. |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ?
if (tickLabelsRotation !== 0) { | ||
// Adding extra padding for rotated labels | ||
grouper.attr('transform', `rotate(${tickLabelsRotation})`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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})`); | |
} |
## Unreleased | ||
* Added | ||
* Added examples for the Xaxis Overlapping tick values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 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 !
There was a problem hiding this 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.
-
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.
Summary
What was changed:
added new prop called
rotateAngle
to avoid the x-axis overlapping tick values.with prop
rotateAngle: -45
with prop
rotateAngle: 40
Why it was changed:
Testing
This change was tested using:
Reviews
In addition to engineering reviews, this PR needs:
Additional Details
This PR resolves:
UXPLATFORM-XXXX
Thank you for contributing to Terra.
@cerner/terra