Skip to main content
Version: 2.1

Cube Data Source

Introduction

Cube is a semantic layer for analytics APIs and data applications that helps teams define metrics once and serve them consistently across dashboards and applications. This topic explains how to connect Cube data sources in your Reveal application to visualize and analyze your data.

Prerequisites

Before configuring the Cube data source in Reveal, make sure you have the following:

  • A reachable Cube REST API endpoint, such as https://your-cube-host/cubejs-api/v1
  • At least one published cube model that Reveal users can query
  • A bearer token strategy, such as JWT, if your Cube deployment requires authentication

Server Configuration

Installation

Step 1 - Install the Reveal Cube connector package.

For ASP.NET applications, you need to install a separate NuGet package to enable Cube support:

dotnet add package Reveal.Sdk.Data.Cube

Step 2 - Register the Cube data source in your application.

builder.Services.AddControllers().AddReveal(builder =>
{
builder.DataSources.RegisterCube();
});

Connection Configuration

// Create a data source provider
public class DataSourceProvider : IRVDataSourceProvider
{
public async Task<RVDataSourceItem> ChangeDataSourceItemAsync(IRVUserContext userContext, string dashboardId, RVDataSourceItem dataSourceItem)
{
// Required: Update the underlying data source
await ChangeDataSourceAsync(userContext, dataSourceItem.DataSource);

if (dataSourceItem is RVCubeDataSourceItem cubeItem)
{
// Configure specific item properties if needed
if (cubeItem.Id == "cube_orders")
{
cubeItem.Cube = "orders";
}
}

return dataSourceItem;
}

public Task<RVDashboardDataSource> ChangeDataSourceAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
if (dataSource is RVCubeDataSource cubeDataSource)
{
// Configure connection properties
cubeDataSource.Url = "https://your-cube-host/cubejs-api/v1";
}

return Task.FromResult(dataSource);
}
}
Important

Any changes made to the data source in the ChangeDataSourceAsync method are not carried over into the ChangeDataSourceItemAsync method. You must update the data source properties in both methods. We recommend calling the ChangeDataSourceAsync method within the ChangeDataSourceItemAsync method passing the data source item's underlying data source as the parameter as shown in the examples above.

Authentication

Cube authentication is typically handled with a bearer token, such as a JWT issued for the Cube API. For more information, see the Authentication topic.

public class AuthenticationProvider : IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;

if (dataSource is RVCubeDataSource)
{
// Use Bearer Token
userCredential = new RVBearerTokenDataSourceCredential("your_jwt_token", "your_userid");
}

return Task.FromResult(userCredential);
}
}

Client-Side Implementation

On the client side, you only need to specify basic properties like ID, title, and subtitle for the data source. The actual connection configuration happens on the server.

Creating Data Sources

Step 1 - Add an event handler for the RevealView.onDataSourcesRequested event.

const revealView = new RevealView("#revealView");
revealView.onDataSourcesRequested = (callback) => {
// Add data source here
callback(new RevealDataSources([], [], false));
};

Step 2 - In the RevealView.onDataSourcesRequested event handler, create a new instance of the RVCubeDataSource object. Set the title and subtitle properties. After you have created the RVCubeDataSource object, add it to the data sources collection.

revealView.onDataSourcesRequested = (callback) => {
const cubeDS = new RVCubeDataSource();
cubeDS.title = "Cube";
cubeDS.subtitle = "Data Source";

callback(new RevealDataSources([cubeDS], [], false));
};

Creating Data Source Items

Data source items represent specific Cube models within your Cube data source that users can select for visualization. On the client side, you only need to specify ID, title, and subtitle.

revealView.onDataSourcesRequested = (callback) => {
// Create the data source
const cubeDS = new RVCubeDataSource();
cubeDS.title = "My Cube Datasource";
cubeDS.subtitle = "Cube";

// Create a data source item
const cubeDSI = new RVCubeDataSourceItem(cubeDS);
cubeDSI.id = "cube_orders";
cubeDSI.title = "My Cube Datasource Item";
cubeDSI.subtitle = "Cube";

callback(new RevealDataSources([cubeDS], [cubeDSI], false));
};

Additional Resources

API Reference