This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
added prop rotateAngle to avoid the overlapping x-axis tick values #322
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ade981b
Added prop rotateAngle
3a9d13e
prop type changed as integer
756d613
enum[0,-45] rotations added
79d79eb
updated comments
f0183ce
default zero rotation
beb094a
updated test & resolved commets
bc666bc
clean code
cf44461
consumer facing example
95fdf8a
constants
e57dbf0
legend & label padding
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,12 @@ const getEpocFromDateString = (dateISO) => parseInt(new Date(dateISO).getTime(), | |
* @returns {object typeof Date} - Date object based on epoc | ||
*/ | ||
const getDateFromEpoc = (epocDate) => new Date(epocDate); | ||
/** | ||
* Enum for tick label rotations. | ||
* @readonly | ||
* @enum {number} | ||
*/ | ||
const validTickLabelRotations = new Set([0, -45]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
||
/** | ||
* @enum {Function} | ||
|
@@ -242,4 +248,5 @@ export default { | |
notEmpty, | ||
parseDateTime, | ||
sanitize, | ||
validTickLabelRotations, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...hs-docs/src/example-datasets/graphConfigObjects/General/generalDefaultXAxisOverlapping.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Carbon from '@cerner/carbon-graphs/lib/js/carbon'; | ||
|
||
const getLineTimeseriesConfig = (id) => ({ | ||
bindTo: id, | ||
axis: { | ||
x: { | ||
type: Carbon.helpers.AXIS_TYPE.TIME_SERIES, | ||
label: 'Datetime', | ||
lowerLimit: new Date(2016, 0, 1).toISOString(), | ||
upperLimit: new Date(2016, 0, 12).toISOString(), | ||
ticks: { | ||
values: [ | ||
new Date(2016, 0, 1).toISOString(), | ||
new Date(2016, 0, 2).toISOString(), | ||
new Date(2016, 0, 3).toISOString(), | ||
new Date(2016, 0, 4).toISOString(), | ||
new Date(2016, 0, 5).toISOString(), | ||
new Date(2016, 0, 6).toISOString(), | ||
new Date(2016, 0, 7).toISOString(), | ||
new Date(2016, 0, 8).toISOString(), | ||
new Date(2016, 0, 9).toISOString(), | ||
new Date(2016, 0, 10).toISOString(), | ||
new Date(2016, 0, 11).toISOString(), | ||
], | ||
tickLabelsRotation: -45, | ||
format: '%Y, %X', | ||
}, | ||
}, | ||
y: { | ||
label: 'Line Set A', | ||
lowerLimit: 10, | ||
upperLimit: 30, | ||
}, | ||
y2: { | ||
show: false, | ||
label: 'Line Set B', | ||
lowerLimit: 0, | ||
upperLimit: 250, | ||
}, | ||
}, | ||
showLabel: true, | ||
showLegend: true, | ||
showShapes: true, | ||
showVGrid: true, | ||
showHGrid: true, | ||
locale: Carbon.helpers.LOCALE.en_US, | ||
}); | ||
|
||
export default getLineTimeseriesConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...graph/CoreConfiguration.b/Examples/Axes.1/XAxisTickLabelOrientation.8.graph.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import LineGraph from '../../../example/Graphs-Carbon/General/Axes/XAxisTickLabelOrientation?dev-site-example'; | ||
import GraphConfig from '@cerner/terra-graphs-docs/lib/example-datasets/graphConfigObjects/General/generalDefaultXAxisOverlapping.js?dev-site-codeblock'; | ||
require('details-polyfill'); | ||
|
||
# X-Axis Tick Label orientation | ||
|
||
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. | ||
|
||
## Getting Started | ||
|
||
- Install with [npmjs](https://www.npmjs.com): | ||
- `npm i @cerner/carbon-graphs --save-dev` | ||
|
||
## Usage | ||
```js | ||
import Carbon from '@cerner/carbon-graphs/dist/js/carbon-graphs.js'; | ||
import '@cerner/carbon-graphs/dist/css/carbon-graphs.css'; | ||
``` | ||
|
||
## Example | ||
<LineGraph /> | ||
|
||
<details> | ||
<summary style={{fontSize: 24 }}> | ||
<b>Data</b> | ||
</summary> | ||
|
||
### Graph Config object | ||
<GraphConfig /> | ||
|
||
</details> |
23 changes: 23 additions & 0 deletions
23
...src/terra-dev-site/graph/example/Graphs-Carbon/General/Axes/XAxisTickLabelOrientation.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import Carbon from '@cerner/carbon-graphs/lib/js/carbon'; | ||
import utils from '@cerner/carbon-graphs/lib/js/helpers/utils'; | ||
import '@cerner/terra-graphs-docs/lib/terra-graphs-src/components/Graph.module.scss'; | ||
import ExampleGraphContainer from '@cerner/terra-graphs-docs/lib/terra-dev-site/ExampleGraphContainer/ExampleGraphContainer'; | ||
import getGraphConfig from '@cerner/terra-graphs-docs/lib/example-datasets/graphConfigObjects/General/generalDefaultXAxisOverlapping'; | ||
|
||
/* | ||
Please refer to the documentation below to see the graphConfig and data objects | ||
*/ | ||
|
||
const graphConfig = utils.deepClone(getGraphConfig('#XAxisTickLabelOrientation')); | ||
|
||
const XAxisTickLabelOrientationGeneralExample = () => { | ||
React.useEffect(() => { | ||
Carbon.api.graph(graphConfig); | ||
}, []); | ||
return ( | ||
<ExampleGraphContainer id="XAxisTickLabelOrientation" /> | ||
); | ||
}; | ||
|
||
export default XAxisTickLabelOrientationGeneralExample; |
19 changes: 19 additions & 0 deletions
19
...aphs-docs/src/terra-dev-site/test/graphs/General/Axes/XAxisTickValuesOverlapping.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import utils from '@cerner/carbon-graphs/lib/js/helpers/utils'; | ||
import LineGraph from '@cerner/terra-graphs-docs/lib/terra-graphs-src/components/Line/LineGraph'; | ||
import '@cerner/terra-graphs-docs/lib/terra-dev-site/ExampleGraphContainer/ExampleGraphContainer.module.scss'; | ||
import getGraphConfig from '@cerner/terra-graphs-docs/lib/example-datasets/graphConfigObjects/General/generalDefaultXAxisOverlapping'; | ||
import exampleData from '@cerner/terra-graphs-docs/lib/example-datasets/dataObjects/General/datasetTimeseries1'; | ||
|
||
const graphConfig = utils.deepClone(getGraphConfig('#xAxisTicksVlauesOverlapping')); | ||
const dataset = [utils.deepClone(exampleData)]; | ||
|
||
const timeoutArray = [0, 750, 750 * 2, 750 * 3, 750 * 4, 750 * 5, 750 * 6]; | ||
|
||
export default () => ( | ||
<> | ||
<div id="tooltip" className="initial-tooltip" /> | ||
<LineGraph graphID="xAxisTicksVlauesOverlapping" graphConfig={graphConfig} dataset={dataset} timeout={timeoutArray} /> | ||
; | ||
</> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.