Skip to content

Commit 43e977d

Browse files
jwilliams-mongojeff-allen-mongo
authored andcommitted
(DOCSP-10346): As a developer, I can control refresh and caching beha… (#349)
* (DOCSP-10346): As a developer, I can control refresh and caching behaviour for embedded charts * (DOCSP-10346): Copy review feedback * (DOCSP-10346): minor corrections * (DOCSP-10346): default background no longer transparent
1 parent c288bc2 commit 43e977d

File tree

4 files changed

+214
-45
lines changed

4 files changed

+214
-45
lines changed

source/embedded-chart-options.txt

Lines changed: 129 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Embedded Chart Options
1313
:class: singlecol
1414

1515
You can customize the appearance and behavior your embedded charts with a
16-
variety of options. Options are avaiable to charts charts embedded with the
16+
variety of options. Options are available to charts charts embedded with the
1717
:ref:`Embedding SDK <embedding-charts-sdk>` and embedded within :ref:`iframes
1818
<embedding-charts-iframe>`.
1919

@@ -49,8 +49,7 @@ variety of options. Options are avaiable to charts charts embedded with the
4949
chartId: "8d4dff93-e7ca-4ccd-a622-e20e8a100197",
5050
baseUrl: "https://charts.mongodb.com/charts-embedding-examples-hmewt",
5151
height: 300,
52-
width: 400,
53-
refreshInterval: 300
52+
width: 400
5453
});
5554

5655
The following options are available to ``createChart``:
@@ -93,10 +92,27 @@ variety of options. Options are avaiable to charts charts embedded with the
9392
- A :ref:`filter <embed-options-filter>` to apply to the chart.
9493
- no
9594

96-
* - ``refreshInterval``
95+
* - ``autoRefresh``
96+
- boolean
97+
- Specifies whether the chart automatically refreshes. If
98+
omitted, charts do not automatically refresh.
99+
100+
Use this option with the ``maxDataAge`` option to
101+
configure how often the chart refreshes.
102+
- no
103+
104+
* - ``maxDataAge``
97105
- number
98-
- How often to refresh the chart, in seconds. The minimum refresh
99-
interval is 10 seconds. ``autorefresh`` is off by default.
106+
- Specifies the maximum age of data to load from the cache
107+
when loading or refreshing the chart. If omitted,
108+
|charts| renders the chart with data from the cache if
109+
the data is less than one hour old.
110+
111+
To learn how |charts| loads data from the cache when
112+
loading or refreshing the chart based on the
113+
``autoRefresh`` and ``maxDataAge`` values, see
114+
:ref:`auto-refresh-behavior`.
115+
100116
- no
101117

102118
* - ``theme``
@@ -164,12 +180,14 @@ variety of options. Options are avaiable to charts charts embedded with the
164180
.. example::
165181

166182
The following code snippets set the theme of a Chart instance named
167-
``chart`` to ``dark`` and its refresh interval to 30 seconds.
183+
``chart`` to ``dark`` and it to refresh automatically every
184+
30 seconds.
168185

169186
.. code-block:: javascript
170187

171188
chart.setTheme("dark");
172-
chart.setRefreshInterval(30);
189+
chart.setAutoRefresh(true);
190+
chart.setMaxDataAge(30);
173191

174192
.. list-table::
175193
:header-rows: 1
@@ -178,9 +196,23 @@ variety of options. Options are avaiable to charts charts embedded with the
178196
* - Method
179197
- Description
180198

181-
* - ``setRefreshInterval(seconds: number)``
182-
- Sets how long the embedded chart waits before refreshing.
183-
The minimum interval is 10 seconds. To disable, set to 0.
199+
* - ``setAutoRefresh``
200+
- Specifies whether the chart automatically refreshes. If
201+
omitted, charts do not automatically refresh.
202+
203+
Use this method with the ``setMaxDataAge`` method to
204+
configure how often the chart refreshes.
205+
206+
* - ``setMaxDataAge``
207+
- Specifies the maximum age of data to load from the cache
208+
when loading or refreshing the chart. If omitted,
209+
|charts| renders the chart with data from the cache if
210+
the data is less than one hour old.
211+
212+
To learn how |charts| loads data from the cache when
213+
loading or refreshing the chart based on the
214+
``setAutoRefresh`` and ``setMaxDataAge`` values, see
215+
:ref:`auto-refresh-behavior`.
184216

185217
* - ``setFilter(filter: object)``
186218
- Applies a :ref:`query filter <filter-embedded-charts>` to the
@@ -197,7 +229,7 @@ variety of options. Options are avaiable to charts charts embedded with the
197229
- Sets the current theme of the embedded chart. When setting the
198230
theme to ``dark``, you need to ensure that your chart's
199231
background color has appropriate contrast so that the information
200-
remains visible. By default, a chart's background is transparent.
232+
remains visible.
201233

202234
.. seealso::
203235

@@ -217,58 +249,75 @@ variety of options. Options are avaiable to charts charts embedded with the
217249
specify a refresh interval for your chart, as well as a light or
218250
dark display theme.
219251

220-
Specify a Refresh Interval
221-
--------------------------
252+
Configure Auto Refresh and Data Caching Behavior
253+
------------------------------------------------
254+
255+
Use the ``autorefresh`` query parameter to configure the chart
256+
to refresh automatically.
222257

223-
Use the ``autorefresh`` query parameter to define the interval,
224-
in seconds, at which the chart refreshes with the latest data from
225-
its :ref:`data source <data-sources>`. Use the options on the
226-
:guilabel:`Unauthenticated` tab on the :guilabel:`Embed Chart` dialog
227-
to customize the ``autorefresh`` value in the iframe snippet.
258+
Use the ``maxDataAge`` query parameter to:
228259

229-
If you do not specify the ``autorefresh`` option, your embedded chart
230-
loads once when the iframe loads and does not automatically refresh.
260+
- Determine the interval at which the chart refreshes if
261+
``autorefresh`` is ``true``.
262+
- Configure the maximum age of data to load from the cache when
263+
loading or manually refreshing the chart if ``autorefresh``
264+
is ``false`` or omitted.
265+
266+
To learn how |charts| loads data from the cache when loading
267+
or refreshing the chart based on the ``autorefresh`` and
268+
``maxDataAge`` values, see :ref:`auto-refresh-behavior`.
269+
270+
Use the options on the
271+
:guilabel:`Unauthenticated` tab on the :guilabel:`Embed Chart`
272+
dialog to customize the ``autorefresh`` value in the iframe
273+
snippet.
231274

232275
Example
233276
~~~~~~~
234277

235-
The following iframe embeds a chart which automatically refreshes
236-
every 30 seconds as defined by the ``autorefresh=30`` query parameter:
278+
The following iframe embeds a chart which automatically
279+
refreshes every 30 seconds as defined by the
280+
``autorefresh=true`` and the ``maxDataAge=30`` query
281+
parameters:
237282

238283
.. code-block:: html
239284

240285
<iframe style="border: none;border-radius: 2px;box-shadow: 0 2px
241286
10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="
242287
{charts-host}/embed/charts?id=b3ca720f-4b4a-40b4-a726-e7dc0c49aa1c&
243-
autorefresh=30"></iframe>
288+
autorefresh=true&maxDataAge=30"></iframe>
244289

245290
Considerations
246291
~~~~~~~~~~~~~~
247292

248-
- The minimum automatic refresh interval is 10 seconds. If you specify
249-
an ``autorefresh`` value less than 10, the chart refreshes every 10
250-
seconds.
293+
- The minimum cache duration is 10 seconds. If ``autorefresh``
294+
is ``true`` and you specify a ``maxDataAge`` value less than
295+
10, the chart refreshes every 10 seconds.
251296

252-
- If you specify an ``autorefresh`` value which is not an integer or
253-
less than 0, an :ref:`error <embedded-errors>` is returned.
297+
- If you specify an ``maxDataAge`` value which is not an
298+
integer or less than ``-1``, an :ref:`error
299+
<embedded-errors>` is returned.
254300

255301
- If your data source requires a
256-
:ref:`Verified Signature <embed-with-iframe-procedure>`, the signature
257-
validity (including the expiry date) is checked on each refresh. If
258-
the signature's expiry date passed, the host web page must
259-
regenerate a new signature to continue rendering charts. For
260-
code examples using verified signatures, see
261-
`MongoDB Charts Embedding Examples <https://github.com/mongodb/charts-embedding-examples>`__
302+
:ref:`Verified Signature <embed-with-iframe-procedure>`, the
303+
signature validity (including the expiry date) is checked on
304+
each refresh. If the signature's expiry date passed, the host
305+
web page must regenerate a new signature to continue
306+
rendering charts. For code examples using verified
307+
signatures, see
308+
`MongoDB Charts Embedding Examples
309+
<https://github.com/mongodb/ charts-embedding-examples>`__
262310
on GitHub.
263311

264312
.. example::
265313

266-
If you specify an automatic refresh interval of one minute and the
267-
expiry date of the signature is in 1 hour, the chart refreshes
268-
every minute for an hour. Once one hour has elapsed, the chart
269-
will not render and an error will be displayed as the signature is
270-
no longer valid. The host web page must regenerate a new signature
271-
to resume rendering the chart.
314+
If ``autorefresh`` is ``true``, the cache duration is one
315+
minute (``maxDataAge=60``), and the expiry date of the
316+
signature is in one hour, the chart refreshes every minute
317+
for an hour. Once one hour has elapsed, the chart will not
318+
render and an error will be displayed as the signature is
319+
no longer valid. The host web page must regenerate a new
320+
signature to resume rendering the chart.
272321

273322
Specify a Display Theme
274323
-----------------------
@@ -323,9 +372,17 @@ variety of options. Options are avaiable to charts charts embedded with the
323372
<https://developer.mozilla.org/en-US/docs/Web/CSS/background>`__
324373
in the MDN Web Docs for more information.
325374

326-
- Remove the ``background`` property to display the chart with a
327-
transparent background, allowing your application's background to
375+
- Change the ``background`` property to ``transparent`` to
376+
display the chart with a transparent background, allowing
377+
your application's background to
328378
display through the chart.
379+
380+
- Remove the ``background`` property to use the default
381+
background color of the theme you choose:
382+
383+
- ``#FFFFFF`` for the ``light`` theme (default), or
384+
385+
- ``#21313C`` for the ``dark`` theme.
329386

330387
Chart Border
331388
~~~~~~~~~~~~
@@ -413,4 +470,32 @@ variety of options. Options are avaiable to charts charts embedded with the
413470
theme=light&
414471
attribution=false
415472
"></iframe>
416-
473+
474+
.. _auto-refresh-behavior:
475+
476+
Auto Refresh and Data Caching Behavior
477+
--------------------------------------
478+
479+
The following table describes how |charts| loads data from the cache
480+
when loading or refreshing the chart based on the ``autorefresh`` or
481+
``autoRefresh`` and ``maxDataAge`` values.
482+
483+
.. note::
484+
485+
The casing of the ``autoRefresh`` option differs based on whether
486+
you embed a chart using the Embedding SDK or an iframe:
487+
488+
.. list-table::
489+
:header-rows: 1
490+
:widths: 50 50
491+
492+
* - Embedding Method
493+
- Auto Refresh Option
494+
495+
* - Embedding SDK
496+
- ``autoRefresh``
497+
498+
* - iframe
499+
- ``autorefresh``
500+
501+
.. include:: /includes/autorefresh-maxdataage-values.rst

source/embedding-charts-sdk.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Embed Charts with the Embedding SDK
1212
:depth: 2
1313
:class: singlecol
1414

15+
.. |autorefresh| replace:: ``autoRefresh``
16+
1517
.. include:: /includes/sdk-beta.rst
1618

1719
You can embed a chart into a web application with the Charts Embedding
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.. list-table::
2+
:header-rows: 1
3+
:widths: 33 33 33
4+
5+
* - ``autorefresh`` or ``autoRefresh`` Value
6+
- ``maxDataAge`` Value
7+
- |charts| Behavior
8+
9+
* - omitted or ``false``
10+
- omitted
11+
- The chart does not automatically refresh.
12+
13+
When you initially load or manually refresh the chart, |charts|
14+
renders the chart with data from the cache if the data is less
15+
than one hour old. If the data from the cache is more than one
16+
hour old, |charts-short| queries the data source for the latest
17+
data, refreshes the cache, and renders the chart using this data.
18+
19+
* - omitted or ``false``
20+
- ``-1``
21+
- The chart does not automatically refresh.
22+
23+
When you initially load or manually refresh the chart, |charts|
24+
renders the chart using data from the cache. |charts-short| only
25+
queries the data source for the latest data if the cache has
26+
no data for the chart.
27+
28+
* - omitted or ``false``
29+
- ``0``
30+
- The chart does not automatically refresh.
31+
32+
When you initially load or manually refresh the chart, |charts|
33+
queries the data source for the latest data, and renders the
34+
chart using this data. |charts-short| doesn't read data from the
35+
cache.
36+
37+
* - omitted or ``false``
38+
- Number greater than ``0``
39+
- The chart does not automatically refresh.
40+
41+
When you initially load or manually refresh the chart, |charts|
42+
renders the chart with data from the cache if the data younger
43+
than the ``maxDataAge`` value, in seconds. If the data from the
44+
cache is older than the ``maxDataAge`` value, in seconds,
45+
|charts-short| queries the data source for the latest data,
46+
refreshes the cache, and renders the chart using this data.
47+
48+
* - ``true``
49+
- omitted
50+
- The chart automatically refreshes every hour.
51+
52+
When you initially load, manually refresh, or automatically
53+
refresh the chart, |charts| renders the chart with data from the
54+
cache if the data is less than one hour old. If the data from the
55+
cache is more than one hour old, |charts-short| queries the data
56+
source for the latest data, refreshes the cache, and renders the
57+
chart using this data.
58+
59+
* - ``true``
60+
- Number greater than or equal to ``10``
61+
- The chart automatically refreshes at the ``maxDataAge`` interval
62+
you specify, in seconds.
63+
64+
When you initially load, manually refresh, or automatically
65+
refresh the chart, |charts| renders the chart with data from the
66+
cache if the data younger than the ``maxDataAge`` value, in
67+
seconds. If the data from the cache is older than the
68+
``maxDataAge`` value, in seconds, |charts-short| queries the data
69+
source for the latest data, refreshes the cache, and renders the
70+
chart using this data.
71+
72+
* - ``true``
73+
- Number less than ``10``
74+
- The chart automatically refreshes at the minimum period of 10
75+
seconds.
76+
77+
When you initially load, manually refresh, or automatically
78+
refresh the chart, |charts| renders the chart with data from the
79+
cache if the data younger than the minimum ``maxDataAge`` value
80+
of 10 seconds. If the data from the cache is older than 10
81+
seconds, |charts-short| queries the data source for the latest
82+
data, refreshes the cache, and renders the chart using this data.

source/includes/steps-embed-chart-iframe.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ref: iframe-enable-embedding
44
title: Enable embedding for your chart.
55
content: |
66
a. Follow the steps in the :ref:`Enable Embedding for Your Chart
7-
<embedding-procedure>` procedure. Select either the :guilabel:`Unauthenticated`
7+
<embed-with-iframe-procedure>` procedure. Select either the :guilabel:`Unauthenticated`
88
tab or the :guilabel:`Verified Signature` tab.
99
1010
#. Copy the iframe embedding code from the modal window before you close

0 commit comments

Comments
 (0)