Skip to content

Commit b18f5c4

Browse files
authored
fix: CHARTS-6412 Update timeline example to wait for rendering (#58)
1 parent 6ab691e commit b18f5c4

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

examples/charts/authenticated-realm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Charts can be embedded either using a simple IFRAME snippet, or by using the Cha
1212

1313
This sample shows how to use the JavaScript Embedding SDK to render **authenticated** embedded charts, specifically via configuring **MongoDB Realm** as an authentication provider. The sample app is already set up to authenticate with a Realm Application hosted by the Charts Development team.
1414

15-
This sample also demonstrates data filtering by role, thanks to Realm's extensive rules system. See more details [here](https://docs.mongodb.com/stitch/mongodb/define-roles-and-permissions/). Simply login with either australianEmployee@mongodb.com or canadianEmployee@mongodb.com, and take note of the different results!
15+
This sample also demonstrates data filtering by role, thanks to Realm's extensive rules system. See more details [here](https://docs.mongodb.com/realm/mongodb/define-roles-and-permissions/). Simply login with either australianEmployee@mongodb.com or canadianEmployee@mongodb.com, and take note of the different results!
1616

1717
#### The features included in this demo are as follows:
1818

@@ -83,7 +83,7 @@ Choose or create a Realm Cloud app which will be used to authenticate users who
8383

8484
### Optionally, Prepare your Dataset
8585

86-
If you want to use your Realm app to filter data for each user, (Like we have done in our sample) set up an [Atlas service](https://www.mongodb.com/cloud/atlas) and corresponding [Rules](https://docs.mongodb.com/stitch/mongodb/define-roles-and-permissions/) that filter the data as desired. Injected Filters and [Dashboard filtering](https://www.mongodb.com/blog/post/filter-your-dashboards-with-mongodb-charts) are other Charts features one can use to attain similar functionality.
86+
If you want to use your Realm app to filter data for each user, (Like we have done in our sample) set up an [Atlas service](https://www.mongodb.com/cloud/atlas) and corresponding [Rules](https://docs.mongodb.com/realm/mongodb/define-roles-and-permissions/) that filter the data as desired. Injected Filters and [Dashboard filtering](https://www.mongodb.com/blog/post/filter-your-dashboards-with-mongodb-charts) are other Charts features one can use to attain similar functionality.
8787

8888
### Prepare MongoDB Charts
8989

examples/charts/timeline-charts-example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
📄 _[See the MongoDB Charts Embedding Docs for more details](https://docs.mongodb.com/charts/saas/embedding-charts/)_
66

7+
🎮 _[Play with a live demo of this sample here](https://codesandbox.io/s/github/mongodb-js/charts-embed-sdk/tree/master/examples/charts/timeline-charts-example)_
8+
79
The example code in this directory is building a small react app, implementing a chart timeline using the Charts Embedding SDK.
810

911
What the application is doing is showing the distribution of Olympic medals through the years.

examples/charts/timeline-charts-example/src/App.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ button {
4848
background-image: url("/pause.png");
4949
}
5050

51+
.show {
52+
visibility: visible;
53+
}
54+
55+
.hide {
56+
visibility: hidden;
57+
}
58+
5159
.charts {
5260
height: 100%;
5361
max-height: 850px;

examples/charts/timeline-charts-example/src/Dashboard.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const geoChart = sdk.createChart({
2323
export default function Dashboard() {
2424
const refBarChart = useRef(null);
2525
const refGeoChart = useRef(null);
26+
27+
const [isBarChartRendered, setIsBarChartRendered] = useState(false);
28+
const [isGeoChartRendered, setIsGeoChartRendered] = useState(false);
2629
const [year, setYear] = useState(lastOlympicsYear);
2730
const [playing, setPlaying] = useState(false);
2831

@@ -32,9 +35,12 @@ export default function Dashboard() {
3235
const timerIdRef = React.useRef();
3336
const replayRef = React.useRef(false);
3437

38+
const chartsRendered = isBarChartRendered & isGeoChartRendered;
39+
3540
const renderBarChart = useCallback(async (ref) => {
3641
try {
3742
await barChart.render(ref);
43+
setIsBarChartRendered(true);
3844
} catch (e) {
3945
console.error(e);
4046
}
@@ -43,6 +49,7 @@ export default function Dashboard() {
4349
const renderGeoChart = useCallback(async (ref) => {
4450
try {
4551
await geoChart.render(ref);
52+
setIsGeoChartRendered(true);
4653
} catch (e) {
4754
console.error(e);
4855
}
@@ -137,7 +144,7 @@ export default function Dashboard() {
137144

138145
const buttonClass = `action-button ${
139146
playing ? "pause-button" : "play-button"
140-
}`;
147+
} ${chartsRendered ? "show" : "hide"}`;
141148

142149
return (
143150
<>
@@ -150,7 +157,8 @@ export default function Dashboard() {
150157
<div className="slider">
151158
<PrettySlider
152159
valueLabelDisplay="on"
153-
aria-label="pretto slider"
160+
aria-label="pretty slider"
161+
disabled={!chartsRendered}
154162
min={firstOlympicsYear}
155163
max={lastOlympicsYear}
156164
step={4}

0 commit comments

Comments
 (0)