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

Vue Embedded AnalyticsResponsive Layout

Version 3.1.0

A dashboard laid out for a desktop screen is too wide for a phone. In view mode, Studio can lay the same widgets out differently as the canvas gets narrower. Use the responsiveLayoutBreakpoints property to define those layouts.

Single Column Layout Copy Link

The simplest mobile view stacks every widget in a single column. The example below starts out responsive, so on a small screen it already shows the single column layout. Click Mobile or Desktop to fix the canvas at that width, and Reset to return to the responsive layout.

Import the singleColumnLayout function from ag-studio to convert a desktop layout into a single column:

  • A heuristic orders the widgets by their visual position within the desktop layout.
  • Each widget spans the full width of the canvas.
  • Each widget keeps its desktop height.
<ag-studio
    :mode="mode"
    :theme="theme"
    :layout="layout"
    :responsiveLayoutBreakpoints="responsiveLayoutBreakpoints"
    /* other studio properties ... */>
</ag-studio>

this.mode = 'view';
this.theme = studioTheme.withParams({ studioMinWidth: 0 });
this.layout = {
    minWidth: 250
};
this.responsiveLayoutBreakpoints = [
    {
        maxWidth: 500,
        layout: singleColumnLayout,
    },
];

Two minimum widths limit how narrow things can get, and a mobile layout needs both lowered, as in the example above.

The outer Studio component has its own Min Width, which defaults to 600px and limits how narrow Studio itself can be. The page's Min Width limits how narrow the canvas inside it can be drawn, and a breakpoint below that width is never used.

Breakpoints Copy Link

Each breakpoint covers a range of canvas widths:

  • minWidth is the narrowest canvas width the breakpoint applies to. Omit it to leave the range open below.
  • maxWidth is the widest canvas width the breakpoint applies to. Omit it to leave the range open above.
  • layout is a function that returns the position and size of each widget for that range.

Studio uses the first breakpoint whose range contains the canvas width, so list narrower ranges before wider ones that also contain them. Where two ranges meet on the same pixel, the breakpoint listed first takes it.

Canvas widths that no breakpoint covers keep the desktop layout, so a range that should use it needs no breakpoint at all. Omitting layout does the same for a range you declare anyway, which is how to stop a later, wider breakpoint from covering it.

The canvas is never drawn narrower than the page's Min Width, so lowering that minimum is what brings a narrow breakpoint into range. Cover the widths it opens up: any width above the page minimum that no breakpoint covers renders the desktop layout at that width, however narrow it is.

responsiveLayoutBreakpointsCopy Link
AgResponsiveLayoutBreakpoint[]
Breakpoints that lay widgets out differently on narrower canvases while in view mode. The first breakpoint whose range contains the canvas width is the one used, so list narrower ranges before wider ones that also contain them. Either bound can be omitted to leave that end of the range open, and canvas widths no breakpoint covers keep the layout the dashboard was authored with. The canvas is never drawn narrower than the page's own minimum width, so a breakpoint below that width is never used. Lower the page's minimum width to bring it into range.

The layout function is called with two arguments:

  • A list of widgets, each with its desktop layout (xTrack, yTrack, xSpan and ySpan) and its minSize (xSpan and ySpan). The minimum size is converted to columns and rows at the narrowest canvas width that reaches the breakpoint, so one layout holds across the whole range.
  • The layout of the page at that width, including the number of columns, and rows if there is a height constraint.

The function returns one layout for each widget, in the same order as the list it was given. Positions and sizes are in columns and rows, as in the desktop layout.

Custom Layout Copy Link

Write your own layout function for anything other than a single column. In the example below, Mobile uses a single column, Tablet uses two columns, Desktop uses the desktop layout and Ultra Wide uses four columns. As in the previous example, Studio starts out responsive and Reset returns to that.

The example defines three breakpoints:

  • Canvases up to 480px wide use singleColumnLayout.
  • Canvases from 480px to 720px use a custom masonryLayout function with two columns.
  • Canvases wider than 1200px use masonryLayout with four columns.
  • Canvases between 720px and 1200px match no breakpoint, so they use the desktop layout.
<ag-studio
    :layout="layout"
    :responsiveLayoutBreakpoints="responsiveLayoutBreakpoints"
    /* other studio properties ... */>
</ag-studio>

this.layout = { minWidth: 250 };
this.responsiveLayoutBreakpoints = [
    { maxWidth: 480, layout: singleColumnLayout },
    { maxWidth: 720, layout: (...args) => masonryLayout(2, ...args) },
    { minWidth: 1200, layout: (...args) => masonryLayout(4, ...args) },
];

masonryLayout places the widgets in desktop order. Each widget spans as many columns as its desktop width needs, and goes wherever it can sit highest. Once every widget is placed, each one stretches down and sideways to fill any empty space next to it. It is a worked example of a layout function rather than part of Studio, so its implementation lives in the example above: open the example's code to read it alongside the breakpoints that call it.

Switching Between Desktop and Mobile Copy Link

Studio chooses the layout from the current width of the canvas and updates it whenever the canvas is resized. There is no API call to switch between the desktop and mobile layouts. The buttons in the examples above only change the width of the canvas inside Studio.

Studio must be in view mode. In edit mode, it always uses the desktop layout, whatever the width.

Widget Minimum Sizes Copy Link

Every widget has a minimum size. A widget's minimum width must fit within the width of the canvas, so widget minimum sizes need to align with the widths your breakpoints support.

The built-in widgets have small minimum sizes, so they fit the breakpoints shown on this page. If you define Custom Widgets, keep each widget's minSize width no wider than the page's Min Width, which is the narrowest the canvas is ever drawn. A custom layout function also receives each widget's minimum size, so it can give a wide widget more room, as masonryLayout does.

Mobile Overlay Copy Link

The example below shows one way to preview the mobile layout while editing a dashboard. Click Toggle Mobile Overlay to open a resizable popup that shows the dashboard in a single column. Edit the dashboard and the preview updates.

The popup contains a second Studio in view mode, with a breakpoint that uses singleColumnLayout. The main Studio's onStateUpdated event passes each change to the preview with setState. The preview sets the --ag-studio-min-width and --ag-studio-min-height CSS variables to 0px on its container, because it would otherwise inherit the main Studio's minimum size and could not shrink to the width of the popup.

Limitations Copy Link

  • Responsive layouts are view only. In edit mode, Studio always shows and edits the desktop layout.
  • Widget order follows the widget's position in the desktop layout. To change the order of widgets in a mobile layout, rearrange the desktop layout, or write a custom layout function.