Skip to content

Commit 1a942cc

Browse files
khangusleeMuthukrishnan Krishnamurthy
andauthored
feat: CHARTS-6400 Add getData example to embedded unauthenticated chart example (#60)
* chore: Update charts embed sdk version * style: Clean up CSS file to bunch up related selectors together * chore: Add json-viewer package * feat: Display chart data in JSON viewer on the unauthenticated chart embedding example * doc: Add comment above get chart data event listener in example code * doc: Place json viewer inline with chart info div * Updated sdk version 2.2.0 Co-authored-by: Muthukrishnan Krishnamurthy <[email protected]>
1 parent 4b216bc commit 1a942cc

File tree

5 files changed

+187
-58
lines changed

5 files changed

+187
-58
lines changed
Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
:root {
2+
--bg-light-mode-color: #ffffff;
3+
--bg-dark-mode-color: #21313c;
4+
--font-dark-mode-color: #ffffff;
5+
}
16
html,
27
body {
38
height: 100%;
49
font-family: "Heebo";
510
transition: background-color 0.5s ease;
611
}
712

8-
.chart-title {
9-
text-align: center;
10-
color: #89989b;
11-
}
12-
13-
.body-content {
14-
display: flex;
13+
span {
14+
white-space: pre;
1515
}
1616

1717
th {
@@ -20,19 +20,10 @@ th {
2020
text-align: right;
2121
}
2222

23-
.chartInfo {
24-
font-size: 20px;
25-
width: 520px;
26-
}
27-
2823
td {
2924
padding-left: 20px;
3025
}
3126

32-
.chartsContainer {
33-
display: flex;
34-
}
35-
3627
main {
3728
box-sizing: border-box;
3829
padding: 1rem;
@@ -41,6 +32,7 @@ main {
4132
flex-direction: column;
4233
}
4334

35+
/* Navigation Bar */
4436
#nav {
4537
flex-shrink: 0;
4638
padding: 1rem;
@@ -58,31 +50,70 @@ main {
5850
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
5951
}
6052

53+
.theme-label {
54+
line-height: 35px;
55+
padding-left: 10px;
56+
}
57+
58+
.dark-mode {
59+
background-color: var(
60+
--bg-dark-mode-color
61+
); /* to match the chart's background */
62+
color: var(--font-dark-mode-color);
63+
}
64+
65+
body span.theme-label::before {
66+
content: "☀️";
67+
}
68+
69+
body.dark-mode span.theme-label::before {
70+
content: "🌙";
71+
}
72+
73+
/* Body */
74+
.body-content {
75+
display: flex;
76+
}
77+
78+
/* Chart */
6179
#chart {
6280
border-top: none;
6381
flex-grow: 1;
6482
height: 100%;
6583
width: 80%;
6684
}
6785

68-
.theme-label {
69-
line-height: 35px;
70-
padding-left: 10px;
86+
/* Chart Info */
87+
.chartInfo {
88+
font-size: 20px;
89+
width: 520px;
7190
}
7291

73-
span {
74-
white-space: pre;
92+
.chart-title {
93+
text-align: center;
94+
color: #89989b;
7595
}
7696

77-
.dark-mode {
78-
background-color: #21313c; /* to match the chart's background */
79-
color: #ffffff;
97+
#chartDataButton {
98+
margin-top: 1em;
99+
padding: 0.5rem 1rem;
100+
width: 100%;
80101
}
81102

82-
body span.theme-label::before {
83-
content: "☀️";
103+
/* JSON Viewer */
104+
#jsonViewer {
105+
visibility: hidden;
106+
transition: background-color 0.5s ease;
107+
--background-color: var(--bg-light-mode-color);
108+
--string-color: #00a35c;
109+
--preview-color: #ffc010;
110+
--property-color: #0498ec;
111+
--number-color: #b45af2;
112+
--boolean-color: #ef5752;
84113
}
85114

86-
body.dark-mode span.theme-label::before {
87-
content: "🌙";
115+
body.dark-mode #jsonViewer {
116+
--background-color: var(--bg-dark-mode-color);
117+
--string-color: #00ed64;
118+
--preview-color: #ffec9e;
88119
}

examples/charts/unauthenticated/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555
<span id="themeEmoji" class="theme-label"></span>
5656
</label>
5757
</div>
58+
5859
<div class="body-content">
5960
<div id="chart"></div>
6061
<div class="chartInfo">
61-
<h3 class="chart-title">CHART DATA</h3>
62+
<h3 class="chart-title">CHART OPTIONS</h3>
6263
<table>
6364
<tr>
6465
<th>Current Max Data Age (in secs)</th>
@@ -73,8 +74,15 @@ <h3 class="chart-title">CHART DATA</h3>
7374
<td id="currentFilter">None</td>
7475
</tr>
7576
</table>
77+
78+
<button id="chartDataButton">
79+
<span id="chartDataButtonText">Show</span> Chart Data
80+
</button>
81+
82+
<json-viewer id="jsonViewer">{}</json-viewer>
7683
</div>
7784
</div>
85+
7886
</main>
7987
<script src="src/index.js"></script>
8088
</body>

examples/charts/unauthenticated/package-lock.json

Lines changed: 67 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/charts/unauthenticated/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "parcel build index.html"
99
},
1010
"dependencies": {
11-
"@mongodb-js/charts-embed-dom": "^2.1.0",
11+
"@alenaksu/json-viewer": "^0.3.4",
12+
"@mongodb-js/charts-embed-dom": "^2.2.0",
1213
"parcel": "^1.12.4"
1314
},
1415
"devDependencies": {

0 commit comments

Comments
 (0)