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

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sdadn committed Apr 5, 2024
1 parent cb25a75 commit 41adbd1
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import NoDataGeneralExample from './examples/GraphWithNoData?dev-site-example';
import CustomLegendDomExample from './examples/GraphWithCustomLegendDom?dev-site-example';
import AllowCalibrationDisabledExample from './examples/AllowCalibrationDisabled?dev-site-example';
import AllowCalibrationEnabledExample from './examples/AllowCalibrationEnabled?dev-site-example';

# Graph Configuration Object

Expand All @@ -8,7 +10,10 @@ It hold various properties to configure a grid.

- [Valid Graphs](#valid-graphs)
- [Configuration Structure](#configuration-structure)
- [Configuration Properties](#configuration-properties)
- [Configuration Properties Summary](#configuration-properties-summary)
- [Configuration Properties Details](#configuration-properties-details)
- [allowCalibration](#allowcalibration)
- [bindLegendTo](#bindlegendto)
- [clickPassThrough](#clickpassthrough)
- [dimension](#dimension)
- [legendPadding](#legendpadding)
Expand Down Expand Up @@ -71,13 +76,13 @@ const graphConfig = {
}
```

## Configuration Properties
## Configuration Properties Summary

| Property Name | Expected | Default | Required | Description |
|------------------------|----------|------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| axis | object | - | yes | See [Axis](./Axes). |
| bindTo | string | - | yes | DOM ID to bind the graph container to. |
| allowCalibration | boolean | `true` | no | Toggle to allow calibration to adjust the y axis. |
| [allowCalibration](#allowcalibration) | boolean | `true` | no | Toggle to automatically adjust the y axis based on the dataset. |
| bindLegendTo | string | `null` | no | Container id for custom legend placement. See [bindLegendTo](#bindLegendTo). |
| clickPassThrough | object | `{}` | no | See [clickPassThrough](#clickpassthrough). |
| dateline | array | `[]` | no | See [Dateline](./Dateline). |
Expand All @@ -98,6 +103,19 @@ const graphConfig = {
| showXLabel | boolean | `true` | no | Toggle to show the x-axis label. An x-axis label will be required by default in 3.0.0. Set this property to `false` for specific use cases where the x-axis label needs to be hidden. |
| ticksCount | number | `3`-`7` depending on the input range | no | See [ticksCount](#tickscount). |

## Configuration Properties Details

- ### `allowCalibration`

The `allowCalibration` prop allows the y-axes to be automatically updated based on the dataset.

<AllowCalibrationDisabledExample/>

When enabled, the maximum and minimum points of the dataset are used to determine the new limits, regardless of if the datapoints are visible in the viewport.

<AllowCalibrationEnabledExample/>


- ### `bindLegendTo`

Container ID for custom legend placement.
Expand Down Expand Up @@ -158,6 +176,7 @@ Container ID for custom legend placement.
| left | number | no | `8` | Left padding of legend container. |
| right | number | no | `8` | Right padding of legend container. |


- ### `ticksCount`
**type:** number

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import Carbon from '@cerner/carbon-graphs';

// graph configuration object

const graphConfig = {
bindTo: '#allow-calibration-disabled-example',
axis: {
x: {
show: true,
label: 'x-axis',
lowerLimit: 80,
upperLimit: 280,
},
y: {
show: true,
label: 'y-axis',
lowerLimit: -5,
upperLimit: 20,
},
},
allowCalibration: false,
};

// graph dataset

const dataset1 = {
key: 'uid_1',
label: {
display: 'Data Label 1',
},
color: Carbon.helpers.COLORS.BLACK,
values: [
{ x: 87, y: -2 },
{ x: 95, y: 1 },
{ x: 160, y: -7 },
{ x: 200, y: 28 },
{ x: 213, y: 11 },
{ x: 246, y: 1 },
],
};

// graph rendering

const NoDataGeneralExample = () => {
React.useEffect(() => {
const graph = Carbon.api.graph(graphConfig);
graph.loadContent(Carbon.api.line(dataset1));
}, []);
return <div id="allow-calibration-disabled-example" />;
};

export default NoDataGeneralExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import Carbon from '@cerner/carbon-graphs';

// graph configuration objects

const graphConfig1 = {
bindTo: '#allow-calibration-enabled-example',
axis: {
x: {
show: true,
label: 'x-axis',
lowerLimit: 80,
upperLimit: 280,
},
y: {
show: true,
label: 'y-axis',
lowerLimit: -5,
upperLimit: 20,
},
},
// allowCalibration is true by default
// allowCalibration: true,
};

const graphConfig2 = {
bindTo: '#allow-calibration-enabled-example2',
axis: {
x: {
show: true,
label: 'x-axis',
lowerLimit: 80,
upperLimit: 100,
},
y: {
show: true,
label: 'y-axis',
lowerLimit: -5,
upperLimit: 20,
},
},
// allowCalibration is true by default
// allowCalibration: true,
};

// graph dataset

const dataset1 = {
key: 'uid_1',
label: {
display: 'Data Label 1',
},
color: Carbon.helpers.COLORS.BLACK,
values: [
{ x: 87, y: -2 },
{ x: 95, y: 1 },
{ x: 160, y: -7 },
{ x: 200, y: 28 },
{ x: 213, y: 11 },
{ x: 246, y: 1 },
],
};

// graph rendering

const NoDataGeneralExample = () => {

Check failure on line 66 in packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConfiguration.b/examples/AllowCalibrationEnabled.jsx

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines

React.useEffect(() => {
const graph1 = Carbon.api.graph(graphConfig1);
graph1.loadContent(Carbon.api.line(dataset1));

Check failure on line 71 in packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConfiguration.b/examples/AllowCalibrationEnabled.jsx

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
const graph2 = Carbon.api.graph(graphConfig2);
graph2.loadContent(Carbon.api.line(dataset1));
}, []);

return (
<>
<div id="allow-calibration-enabled-example" />
<div id="allow-calibration-enabled-example2" />
</>
);
};

export default NoDataGeneralExample;
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const dataset1 = {

// graph rendering

const NoDataGeneralExample = () => {
const CustomLegendDomExample = () => {
React.useEffect(() => {
const graph = Carbon.api.graph(graphConfig);
graph.loadContent(Carbon.api.line(dataset1));
Expand All @@ -58,4 +58,4 @@ const NoDataGeneralExample = () => {
);
};

export default NoDataGeneralExample;
export default CustomLegendDomExample;

0 comments on commit 41adbd1

Please sign in to comment.