From 06e8f71f7106556b266f6f59b1194abd9002c4e7 Mon Sep 17 00:00:00 2001
From: Saad <38024451+sdadn@users.noreply.github.com>
Date: Tue, 16 Apr 2024 08:05:37 -0500
Subject: [PATCH 01/11] added more examples for reflow
---
.../graph/CoreConcepts.b/Reflow.e.graph.mdx | 24 +++-
.../examples/reflow/BasicReflowExample.jsx | 10 +-
.../reflow/DynamicallyUpdatingData.jsx | 130 ++++++++++++++++++
.../examples/reflow/PanningExample.jsx | 2 +-
4 files changed, 157 insertions(+), 9 deletions(-)
create mode 100644 packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/Reflow.e.graph.mdx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/Reflow.e.graph.mdx
index 98bcebfb3..72ab44f9c 100644
--- a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/Reflow.e.graph.mdx
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/Reflow.e.graph.mdx
@@ -1,10 +1,24 @@
-import BasicReflowExample from './examples/reflow/BasicReflowExample';
-import PanningExample from './examples/reflow/PanningExample';
+import {Notice} from '@cerner/terra-docs'
+import BasicReflowExample from './examples/reflow/BasicReflowExample?dev-site-example';
+import PanningExample from './examples/reflow/PanningExample?dev-site-example';
+import DynamicallyUpdatingDataExample from './examples/reflow/DynamicallyUpdatingData?dev-site-example';
# Reflow
-Reflow can be used to dynamically update a graph.
+Reflow can be used to dynamically update a graph without causing a full redraw from scratch.
+It can be invoked by using the `GraphInstance.reflowMultipleDatasets` method.
+
+```js
+const graphInstance = Carbon.api.graph(graphConfig);
+graphInstance.reflowMultipleDatasets();
+```
+
+
+
+The original reflow method, `GraphInstance.reflow()`, is depreacted.
+
+
## Overview
@@ -14,3 +28,7 @@ Reflow can be used to dynamically update a graph.
### Panning
+
+### Dynamic Data
+
+
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/BasicReflowExample.jsx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/BasicReflowExample.jsx
index bc86376d5..8c5bcff11 100644
--- a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/BasicReflowExample.jsx
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/BasicReflowExample.jsx
@@ -29,7 +29,7 @@ const graphConfig = {
const dataset1 = {
key: 'uid_1',
label: {
- display: 'Data Label 1',
+ display: 'Dataset 1',
},
color: Carbon.helpers.COLORS.BLACK,
values: [
@@ -66,14 +66,14 @@ const BasicReflowExample = () => {
graph.reflowMultipleDatasets();
};
- const handleClickUpdateLimits = () => {
+ const handleClickUpdateLimits1 = () => {
graph.config.axis.y.domain.lowerLimit = -52;
graph.config.axis.y.domain.upperLimit = 52;
graph.reflowMultipleDatasets();
};
- const handleClickReset = () => {
+ const handleClickUpdateLimits2 = () => {
graph.config.axis.y.domain.lowerLimit = 0;
graph.config.axis.y.domain.upperLimit = 20;
@@ -83,8 +83,8 @@ const BasicReflowExample = () => {
return (
<>
-
-
+
+
AllowCalibration:
{allowCalibrationStatus}
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
new file mode 100644
index 000000000..09cc57299
--- /dev/null
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
@@ -0,0 +1,130 @@
+import React, { useState } from 'react';
+
+import Button from 'terra-button';
+
+import Carbon from '@cerner/carbon-graphs';
+
+// graph configuration object
+
+const graphConfig = {
+ bindTo: '#dynamic-data-upate-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: 'Dataset 1',
+ },
+ color: Carbon.helpers.COLORS.PINK,
+ 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 },
+ ],
+};
+
+
+// color and shape of the original dataset is retained
+const updatedDataset1 = {
+ key: 'uid_1',
+ values: [
+ { x: 81, y: 21 },
+ { x: 107, y: 6 },
+ { x: 109, y: 7 },
+ { x: 118, y: 5 },
+ { x: 117, y: 21 },
+ { x: 127, y: -20 },
+ { x: 137, y: -9 },
+ { x: 141, y: -6 },
+ { x: 144, y: 39 },
+ { x: 151, y: -14 },
+ { x: 156, y: -9 },
+ { x: 163, y: 4 },
+ { x: 164, y: 29 },
+ { x: 170, y: 30 },
+ { x: 172, y: 31 },
+ { x: 176, y: 34 },
+ { x: 185, y: 1 },
+ { x: 191, y: -2 },
+ { x: 193, y: 38 },
+ { x: 198, y: 40 },
+ ],
+};
+
+// graph rendering
+let graph;
+const DynamicallyUpdatingDataExample = () => {
+ 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 handleClickUpdateData = () => {
+
+ graph.config.axis.y.domain.lowerLimit = 0;
+ graph.config.axis.y.domain.upperLimit = 20;
+
+ graph.reflowMultipleDatasets({
+ panData: [
+ updatedDataset1,
+ ],
+ });
+ };
+
+ const handleClickReset = () => {
+// graph.destroy();
+// graph = Carbon.api.graph(graphConfig);
+ graph.unloadContent(Carbon.api.line(dataset1));
+ graph.loadContent(Carbon.api.line(dataset1));
+ };
+
+ return (
+ <>
+
+
+
+
+ AllowCalibration:
+ {allowCalibrationStatus}
+
+
+ >
+ );
+};
+
+export default DynamicallyUpdatingDataExample;
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
index 9492d5796..e61ba452f 100644
--- a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
@@ -32,7 +32,7 @@ const graphConfig = {
const dataset1 = {
key: 'uid_1',
label: {
- display: 'Data Label 1',
+ display: 'Dataset 1',
},
color: Carbon.helpers.COLORS.BLACK,
values: [
From 4588682838f609833ddee4b8a85c6a40ef8f4e7b Mon Sep 17 00:00:00 2001
From: Saad <38024451+sdadn@users.noreply.github.com>
Date: Tue, 16 Apr 2024 08:08:45 -0500
Subject: [PATCH 02/11] updated example
---
.../examples/reflow/DynamicallyUpdatingData.jsx | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
index 09cc57299..3fb4d36ed 100644
--- a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/DynamicallyUpdatingData.jsx
@@ -7,7 +7,7 @@ import Carbon from '@cerner/carbon-graphs';
// graph configuration object
const graphConfig = {
- bindTo: '#dynamic-data-upate-example',
+ bindTo: '#dynamic-data-update-example',
axis: {
x: {
label: 'x-axis',
@@ -49,8 +49,8 @@ const dataset1 = {
],
};
-
-// color and shape of the original dataset is retained
+// Updated values for dataset 1
+// Color, shape & label of the original dataset is retained if it is not updated
const updatedDataset1 = {
key: 'uid_1',
values: [
@@ -100,9 +100,7 @@ const DynamicallyUpdatingDataExample = () => {
graph.config.axis.y.domain.upperLimit = 20;
graph.reflowMultipleDatasets({
- panData: [
- updatedDataset1,
- ],
+ panData: [updatedDataset1],
});
};
@@ -122,7 +120,7 @@ const DynamicallyUpdatingDataExample = () => {
AllowCalibration:
{allowCalibrationStatus}
-
From 844a469228c16b2d18a9b9512d5f5a51a4cb772c Mon Sep 17 00:00:00 2001
From: Saad <38024451+sdadn@users.noreply.github.com>
Date: Tue, 16 Apr 2024 13:18:11 -0500
Subject: [PATCH 10/11] updated wdio tests
---
.../carbon-graphs/tests/wdio/Graphs/General/general-spec.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/carbon-graphs/tests/wdio/Graphs/General/general-spec.js b/packages/carbon-graphs/tests/wdio/Graphs/General/general-spec.js
index df31af013..d4f9ec7e6 100644
--- a/packages/carbon-graphs/tests/wdio/Graphs/General/general-spec.js
+++ b/packages/carbon-graphs/tests/wdio/Graphs/General/general-spec.js
@@ -71,7 +71,7 @@ Terra.describeViewports('General', ['tiny', 'medium', 'large'], () => {
Terra.validates.screenshot('x-axis_allowcalibration_disabled', { selector: '.carbon-graph-container' });
});
it('validates y-axis allowCalibration disabled graph', () => {
- browser.url('/raw/tests/cerner-terra-graphs-docs/graphs/general/allow-calibration');
+ browser.url('/raw/tests/cerner-terra-graphs-docs/general/allow-calibration');
Terra.validates.screenshot('y-axis_allowcalibration_disabled', { selector: '#allow-calibration-disabled-example' });
});
@@ -90,7 +90,7 @@ Terra.describeViewports('General', ['tiny', 'medium', 'large'], () => {
Terra.validates.screenshot('x-axis_allowcalibration_enabled', { selector: '.carbon-graph-container' });
});
it('validates y-axis allowCalibration enabled graph container', () => {
- browser.url('/raw/tests/cerner-terra-graphs-docs/graphs/general/allow-calibration');
+ browser.url('/raw/tests/cerner-terra-graphs-docs/general/allow-calibration');
Terra.validates.screenshot('y-axis_allowcalibration_enabled', { selector: '#allow-calibration-enabled-example' });
});
From ad12ceb43fd0d55196a5ed99dc7283966c3d674b Mon Sep 17 00:00:00 2001
From: Saad <38024451+sdadn@users.noreply.github.com>
Date: Tue, 16 Apr 2024 13:55:17 -0500
Subject: [PATCH 11/11] fixed console warning
---
.../graph/CoreConcepts.b/examples/reflow/PanningExample.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
index e61ba452f..4be6a0afb 100644
--- a/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
+++ b/packages/terra-graphs-docs/src/terra-dev-site/graph/CoreConcepts.b/examples/reflow/PanningExample.jsx
@@ -101,8 +101,8 @@ const PanningExample = () => {
return (
<>
-
} isIconOnly onClick={() => dispatch({ type: 'panLeft' })} />
-
} isIconOnly onClick={() => dispatch({ type: 'panRight' })} />
+
} text="pan left" isIconOnly onClick={() => dispatch({ type: 'panLeft' })} />
+
} text="pan right" isIconOnly onClick={() => dispatch({ type: 'panRight' })} />
>
);