We just wrapped up AG Studio Launch Week See what we shipped

JavaScript Embedded AnalyticsPopups

Version 3.1.0

The createPopup API opens a popup inside Studio that shows a component of your own. Studio owns the popup and closes it when Studio is destroyed.

Use createPopup when the content belongs with the report: a detail view of something in Studio, or a short form about it. The popup is rendered inside Studio, can be made movable and resizable, and does not block the report, so the user can keep working in Studio while it is open and your application can update it as they do. Use your application's own modal instead when the content must block the rest of the page or must stay open after Studio is destroyed.

The example above opens a Sport Details popup from a button outside Studio. The popup shows the medal counts, number of athletes and top countries for one sport. Click a row in Medals by Sport and the open popup updates to show that sport. Until a sport is selected, or when the selection is cleared, the popup shows the sport with the most medals. The popup's component has its own Close button.

Opening a Popup Copy Link

Call createPopup with the component to show and the params to pass to it:

api.createPopup({
    comp: PopupContent,
    compParams: { detail: getSportDetail('Swimming') },
    title: 'Sport Details',
});

comp is a class implementing AgTypeScriptComponent. Studio calls its init method with compParams, then shows the element returned by getGui.

Component names registered on the components property cannot be used as comp.

The popup is rendered inside Studio, or inside the element set on the popupParent property.

  • title sets the text shown in the title bar.
  • movable lets the user drag the popup by its title bar.
  • resizable lets the user resize the popup by dragging its edges and corners.
  • maximizable adds a title bar button that expands the popup to fill Studio.

movable, resizable and maximizable are off by default.

The popup opens at 600 by 400 pixels and does not grow to fit its content. Set width and height when your component needs a different size. When the popup is resizable, minWidth and minHeight set how small the user can make it.

Closing the Popup Copy Link

The popup stays open when the user clicks outside it, and the rest of the page stays interactive. It closes when:

  • The user presses Escape while focus is inside the popup.
  • The user clicks the close button in the title bar.
  • closePopup is called, either on the instance returned by createPopup or from the component.
  • Studio is destroyed.

To let the component close the popup, for example from its own button, supply compParams as a callback. The callback receives a closePopup function, which you can pass on to the component:

api.createPopup({
    comp: PopupContent,
    compParams: ({ closePopup }) => ({ detail: getSportDetail('Swimming'), closePopup }),
    title: 'Sport Details',
});

closedCallback runs once each time the popup closes, however it was closed. It receives the keyboard event when Escape closed the popup, and undefined otherwise. The example uses it to forget the closed instance, so the next click on Open Popup opens a new one.

Several popups can be open at the same time. Each one stays open until it is closed.

Updating the Popup Copy Link

createPopup returns an instance with two methods:

  • refresh(params) passes new params to the component.
  • closePopup() closes the popup.

To receive the new params, implement the optional refresh(params) method on the component. Without it, refresh has no effect.

The example keeps the instance and refreshes the popup from onStateUpdated when the sport selected in Medals by Sport changes. refresh takes the params themselves, not a callback. If the component needs closePopup, pass the instance's closePopup in the new params:

const popup = api.createPopup({
    comp: PopupContent,
    compParams: ({ closePopup }) => ({ detail: getSportDetail('Swimming'), closePopup }),
    title: 'Sport Details',
});

popup.refresh({ detail: getSportDetail('Athletics'), closePopup: popup.closePopup });

API Reference Copy Link

createPopupCopy Link
Function
Open a popup showing a component of your own. The popup is rendered inside Studio, or inside the element given by the popupParent property, and Studio owns it: the popup closes and your component is destroyed when Studio is destroyed. The popup stays open until something closes it: clicking outside it leaves it open, nothing is dimmed, and the rest of the page stays interactive. The Escape key and the close button in its title bar close it. To close it from inside your component, supply compParams as a callback and call the closePopup() function it receives. closedCallback runs once each time the popup closes, whichever of those closed it. The popup is sized as it opens and does not grow to fit its content, so set width and height when your component needs more or less room than the default 600 by 400 pixels. Several popups can be open at once, each staying open until it is closed.

Properties available on the AgCreatePopupParams<TParams> interface.

any
The component shown inside the popup. Either a TypeScript class implementing AgTypeScriptComponent, or a component of the framework you are using (React, Angular or Vue). Component names registered on the components property are not supported here.
compParamsCopy Link
TParams | ((context: AgPopupCompParamsContext) => TParams)
The parameters passed to the component when it is created. Either the parameters themselves, or a callback that returns them. The callback is given a closePopup() function, so that the component can close the popup itself, for example from its own Close button.
string
The text shown in the popup title bar.
movableCopy Link
boolean
default: false
Whether the user can move the popup by dragging its title bar.
maximizableCopy Link
boolean
default: false
Whether the title bar offers a button that expands the popup to fill Studio.
resizableCopy Link
boolean
default: false
Whether the user can resize the popup by dragging its edges and corners.
number
default: 600
The width of the popup in pixels when it opens. The popup is sized as it opens and does not grow to fit its content, so set this when your component needs more or less room than the default. The user can still change the size afterwards if resizable or maximizable is enabled.
heightCopy Link
number
default: 400
The height of the popup in pixels when it opens. The popup is sized as it opens and does not grow to fit its content, so set this when your component needs more or less room than the default. The user can still change the size afterwards if resizable or maximizable is enabled.
minWidthCopy Link
number
default: 250
The smallest width in pixels the user can resize the popup down to. The default never exceeds width, so a popup opened narrower than 250 pixels is not forced back up to 250 the first time it is resized.
minHeightCopy Link
number
default: 250
The smallest height in pixels the user can resize the popup down to. The default never exceeds height, so a popup opened shorter than 250 pixels is not forced back up to 250 the first time it is resized.
closedCallbackCopy Link
Function
Called once when the popup closes, whatever closed it. The argument is the keyboard event when the Escape key closed the popup, and undefined otherwise: the title bar close button, closePopup() and Studio being destroyed all report no event.