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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[terra-graphs-docs] Update reflow docs (#353)
- Loading branch information
Showing
5 changed files
with
229 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"files": [ | ||
"docs", | ||
"lib", | ||
"src", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"NOTICE" | ||
|
16 changes: 16 additions & 0 deletions
16
...es/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/Reflow.e.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,16 @@ | ||
import BasicReflowExample from './examples/reflow/BasicReflowExample'; | ||
import PanningExample from './examples/reflow/PanningExample'; | ||
|
||
|
||
# Reflow | ||
|
||
Reflow can be used to dynamically update a graph. | ||
|
||
## Overview | ||
|
||
<BasicReflowExample/> | ||
|
||
## Examples | ||
|
||
### Panning | ||
<PanningExample/> |
97 changes: 97 additions & 0 deletions
97
...raphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/BasicReflowExample.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,97 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import Button from 'terra-button'; | ||
|
||
import Carbon from '@cerner/carbon-graphs'; | ||
|
||
// graph configuration object | ||
|
||
const graphConfig = { | ||
bindTo: '#basic-reflow-example', | ||
axis: { | ||
x: { | ||
label: 'x-axis', | ||
lowerLimit: 80, | ||
upperLimit: 280, | ||
rangeRounding: false, | ||
}, | ||
y: { | ||
label: 'y-axis', | ||
lowerLimit: -5, | ||
upperLimit: 20, | ||
}, | ||
}, | ||
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: 103, y: -4 }, | ||
{ x: 109, y: -2 }, | ||
{ x: 128, y: 3 }, | ||
{ x: 145, y: 28 }, | ||
{ x: 151, y: 7 }, | ||
{ x: 164, y: 10 }, | ||
{ x: 177, y: 1 }, | ||
{ x: 192, y: 6 }, | ||
{ x: 203, y: -21 }, | ||
{ x: 209, y: -3 }, | ||
{ x: 246, y: 3 }, | ||
], | ||
}; | ||
|
||
// graph rendering | ||
let graph; | ||
const BasicReflowExample = () => { | ||
const [allowCalibrationStatus, SetAllowCalibrationStatus] = useState(graphConfig.allowCalibration.toString()); | ||
|
||
React.useEffect(() => { | ||
graph = Carbon.api.graph(graphConfig); | ||
graph.loadContent(Carbon.api.line(dataset1)); | ||
}, []); | ||
|
||
const handleClickToggleCalibration = () => { | ||
graph.config.allowCalibration = !graph.config.allowCalibration; | ||
SetAllowCalibrationStatus(graph.config.allowCalibration.toString()); | ||
|
||
graph.reflowMultipleDatasets(); | ||
}; | ||
|
||
const handleClickUpdateLimits = () => { | ||
graph.config.axis.y.domain.lowerLimit = -52; | ||
graph.config.axis.y.domain.upperLimit = 52; | ||
|
||
graph.reflowMultipleDatasets(); | ||
}; | ||
|
||
const handleClickReset = () => { | ||
graph.config.axis.y.domain.lowerLimit = 0; | ||
graph.config.axis.y.domain.upperLimit = 20; | ||
|
||
graph.reflowMultipleDatasets(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button text="Toggle Calibration" onClick={handleClickToggleCalibration} /> | ||
<Button text="Update Axis Limits" onClick={handleClickUpdateLimits} /> | ||
<Button text="Reset" onClick={handleClickReset} /> | ||
<div> | ||
AllowCalibration: | ||
{allowCalibrationStatus} | ||
</div> | ||
<div id="basic-reflow-example" /> | ||
</> | ||
); | ||
}; | ||
|
||
export default BasicReflowExample; |
111 changes: 111 additions & 0 deletions
111
...ra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.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,111 @@ | ||
import React from 'react'; | ||
|
||
import Button from 'terra-button'; | ||
import { IconLeft, IconRight } from 'terra-icon'; | ||
|
||
import Carbon from '@cerner/carbon-graphs'; | ||
|
||
// graph configuration object | ||
|
||
const graphConfig = { | ||
bindTo: '#panning-example', | ||
axis: { | ||
x: { | ||
label: 'x-axis', | ||
lowerLimit: 80, | ||
upperLimit: 280, | ||
rangeRounding: false, | ||
}, | ||
y: { | ||
label: 'y-axis', | ||
lowerLimit: -5, | ||
upperLimit: 20, | ||
}, | ||
}, | ||
panning: { | ||
enabled: 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: 103, y: -4 }, | ||
{ x: 109, y: -2 }, | ||
{ x: 128, y: 3 }, | ||
{ x: 145, y: 28 }, | ||
{ x: 151, y: 7 }, | ||
{ x: 164, y: 10 }, | ||
{ x: 177, y: 1 }, | ||
{ x: 192, y: 6 }, | ||
{ x: 203, y: -21 }, | ||
{ x: 209, y: -3 }, | ||
{ x: 246, y: 3 }, | ||
], | ||
}; | ||
|
||
// graph rendering | ||
let graph; | ||
const panningFactor = 10; | ||
|
||
const PanningExample = () => { | ||
React.useEffect(() => { | ||
graph = Carbon.api.graph(graphConfig); | ||
graph.loadContent(Carbon.api.line(dataset1)); | ||
}, []); | ||
|
||
const reducer = (panState, action) => { | ||
let newLowerLimit = graph.config.axis.x.lowerLimit; | ||
let newUpperLimit = graph.config.axis.x.upperLimit; | ||
|
||
switch (action.type) { | ||
case 'panLeft': | ||
newLowerLimit = graph.config.axis.x.lowerLimit - panningFactor; | ||
newUpperLimit = graph.config.axis.x.upperLimit - panningFactor; | ||
break; | ||
case 'panRight': | ||
newLowerLimit = graph.config.axis.x.lowerLimit + panningFactor; | ||
newUpperLimit = graph.config.axis.x.upperLimit + panningFactor; | ||
break; | ||
default: | ||
return { | ||
newLowerLimit, | ||
newUpperLimit, | ||
}; | ||
} | ||
|
||
return { | ||
newLowerLimit, | ||
newUpperLimit, | ||
}; | ||
}; | ||
|
||
const [panState, dispatch] = React.useReducer(reducer, panningFactor); | ||
|
||
React.useLayoutEffect(() => { | ||
if (!graph) { return; } | ||
|
||
graph.config.axis.x.lowerLimit = panState.newLowerLimit; | ||
graph.config.axis.x.upperLimit = panState.newUpperLimit; | ||
|
||
graph.reflowMultipleDatasets(); | ||
}, [panState]); | ||
|
||
return ( | ||
<> | ||
<Button icon={<IconLeft />} isIconOnly onClick={() => dispatch({ type: 'panLeft' })} /> | ||
<Button icon={<IconRight />} isIconOnly onClick={() => dispatch({ type: 'panRight' })} /> | ||
<div id="panning-example" /> | ||
</> | ||
); | ||
}; | ||
|
||
export default PanningExample; |