# Referencing Calculated Columns

Canonical page: https://www.adaptabletools.com/docs/handbook-calculated-column-referencing

- Once created a Calculated Column can be used and managed like any other Column in AG Grid
- Calculated Columns can also be referenced in AG Grid Charts
- Calculated Columns can also be referenced in other Calculated Columns
- AdapTable provides 2 UI components to allow run-time users to follow (and edit) a Calculated Column's formula 
  - **Formula Trace** shows - Excel-style - how a Calculated Column value is derived
  - The **Compact Expression Editor** lets the Expression be edited inline

Calculated Columns are treated like any other AdapTable (or AG Grid) Column.

Accordingly, a Calculated Column's Expression can reference other Calculated Columns in the Grid if required.

- There is no limitation on how many Calculated Columns are chained - [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) will evaluate each in turn
- However at some point performance might be impacted if you have a large chain with complicated calculations

**Example: Calculated Columns: Referencing**

Calculated Columns: Reference other Calc Cols

- This demo contains 3 Calculated Columns, one of which is evaluated based on the other 2
  - `Issues Open/Total Ratio` - shows ratio between open and total number of issues
  - `PR Open/Total Ratio` - shows ratio between open and total number of pull-requests
  - `Score` - is calculated by computing the average value of the previous 2 ratio Calculated Columns (a higher score is better)

- Change a value in `Open Issues` or `Closed Issues` and see how the `Score` Calculated Column also updates
- Change `Score` to take the maximum value between 'Issues Open/Total Ratio' and 'PR Open/Total Ratio'

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Referencing Calculated Columns',
  initialState: {
    Dashboard: {
      ModuleButtons: ['CalculatedColumn'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout', 'CalculatedColumn'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'open_issues_count',
            'closed_issues_count',
            'open-total-issue-ratio',
            'open-total-pr-ratio',
            'score',
            'licence',
            'created_at',
            'github_stars',
          ],
          Name: 'Standard Layout',
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Issues Open/Total Ratio',
          ColumnId: 'open-total-issue-ratio',
          Expression: '[open_issues_count] / ([open_issues_count] +[closed_issues_count])',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
        {
          FriendlyName: 'PR Open/Total Ratio',
          ColumnId: 'open-total-pr-ratio',
          Expression: '[open_pr_count] / ([open_pr_count] + [closed_pr_count])',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
        {
          FriendlyName: 'Score',
          ColumnId: 'score',
          Expression: 'AVG([open-total-pr-ratio], [open-total-issue-ratio]) * 100',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatC olumn-open-total-issue-ratio',
          Scope: {
            ColumnIds: [
              'open-total-issue-ratio',
              'open-total-pr-ratio',
              'score',
            ],
          },
          DisplayFormat: {
            Formatter: 'NumberFormatter',
            Options: {
              FractionDigits: 2,
            },
          },
        },
      ],
    },
  },
};
```

This page covers **referencing** other Calculated Columns, **Formula Trace**, and using calculated values across the Grid. For creating columns, the Wizard, and Initial State, see [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md).

## Tracing Calculated Columns

AdapTable includes an Excel-style **Formula Trace** which lets run-time users see - and inline edit - how a Calculated Column value is derived.

There are 2 ways to open Formula Trace for a Calculated Column cell:

- **Double-click** the cell
- Select the **Show Formula** item in the cell's [Context Menu](https://www.adaptabletools.com/docs/ui-context-menu/index.md)

Both triggers are enabled by default, but each can be turned off - see [Formula Trace Options](#formula-trace-options) below

When opened, Formula Trace displays a popup - anchored to the cell - containing the Column's [Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) with every referenced Column shown in its own colour.

At the same time, AdapTable highlights the referenced data in the Grid using the **same colours** (in the manner of Excel):

- for `Standard` Calculated Columns the referenced **cells** in the row are outlined and tinted
- for `Aggregated` (and other multi-row) Calculated Columns the referenced Column **headers** are highlighted

For `Standard` Calculated Columns the popup also shows each referenced Column's **name above its actual cell value** for that row, followed by the computed result (e.g. `= 42`) - so you can see the calculation "worked through" for the current row

### Editing a Formula

The Formula Trace popup contains an **Edit** button which opens the **Compact Expression Editor**.

This is a small, moveable and resizable version of the full [Expression Editor](https://www.adaptabletools.com/docs/ui-expression-editor/index.md), giving quick access to the Expression without opening the full Wizard.

It provides the same power as the full Editor, including:

- the **Functions** dropdown listing all available [Expression Functions](https://www.adaptabletools.com/docs/adaptable-ql-expression-functions/index.md)
- live **validation**
- **colour-coded** Column references (matching the Formula Trace highlights)

Edits are applied **live** as you type - the Calculated Column re-evaluates immediately.

An invalid Expression will show `#INVALID` in the cells until it is corrected

The Compact Editor also provides 2 buttons:

- **Revert** - restores the Expression to how it was when the Editor was opened
- **Open Full Editor** - closes the Compact Editor and opens the full Calculated Column Wizard

The Compact Expression Editor is available for all 6 Calculated Column types: `Standard`, `Aggregated`, `Cumulative`, `Quantile`, `Window` and `Observable`

### Showing Formula Trace via the API

Formula Trace can also be opened programmatically using the [`Calculated Column API`](https://www.adaptabletools.com/docs/reference/calculatedcolumnapi.md):

- `showFormulaTrace(columnId, primaryKeyValue)` - opens the Formula Trace popup for the given Calculated Column cell
- `hideFormulaTrace()` - closes the popup (and clears the Grid highlights)

**Example: Using Calculated Columns: Formula Trace**

Calculated Columns: Formula Trace and the Compact Editor

- This demo contains 3 Calculated Columns:
  - `Total PRs` (Standard) - sums the `Open PRs` and `Closed PRs` Columns
  - `Issues Open/Total Ratio` (Standard) - divides `Open Issues` by total Issues
  - `Sum Pop by Lang` (Aggregated) - sums `Github Watchers` grouped by `Language`
- After 5 seconds the demo calls `showFormulaTrace` to open the Formula Trace popup for the first `Total PRs` cell (see `onAdaptableReady.ts`)

- Wait for the Formula Trace popup to appear, or double-click any `Total PRs` cell yourself
- Note how the two referenced cells (`Open PRs`, `Closed PRs`) are highlighted in matching colours
- Click the Edit button in the popup and change the Expression in the Compact Editor - the Column updates live
- Double-click a `Sum Pop by Lang` cell and note the referenced Column **header** is highlighted instead

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Using Calculated Columns',
  initialState: {
    Dashboard: {
      ModuleButtons: ['CalculatedColumn'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout', 'CalculatedColumn'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'open_pr_count',
            'closed_pr_count',
            'total_pr_count',
            'open_issues_count',
            'closed_issues_count',
            'open-total-issue-ratio',
            'language',
            'github_watchers',
            'sum-popularity-by-lang',
            'github_stars',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Total PRs',
          ColumnId: 'total_pr_count',
          Expression: '[open_pr_count] + [closed_pr_count]',
          CalculatedColumnSettings: {
            DataType: 'number',
            Filterable: true,
          },
        },
        {
          FriendlyName: 'Issues Open/Total Ratio',
          ColumnId: 'open-total-issue-ratio',
          Expression: '[open_issues_count] / ([open_issues_count] + [closed_issues_count])',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
        {
          ColumnId: 'sum-popularity-by-lang',
          FriendlyName: 'Sum Pop by Lang',
          Expression: 'SUM{[github_watchers], GROUP_BY([language])}',
          CalculatedColumnSettings: {
            DataType: 'number',
            Groupable: true,
          },
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  // After a short delay, programmatically open the Formula Trace popup for the
  // first row's `Total PRs` cell, so users scrolling the page see the UI without
  // having to double-click a cell themselves.
  setTimeout(() => {
    const firstRowNode = adaptableApi.gridApi.getFirstRowNode();
    if (!firstRowNode) {
      return;
    }
    const primaryKeyValue =
      adaptableApi.gridApi.getPrimaryKeyValueForRowNode(firstRowNode);
    adaptableApi.calculatedColumnApi.showFormulaTrace(
      'total_pr_count',
      primaryKeyValue
    );
  }, 5000);
};
```

### Configuring Formula Trace

Formula Trace is configured via the `formulaTrace` property in [Calculated Column Options](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md).

There are 2 properties available to set the formula trace behaviour:

### `enableDoubleClick`

Whether double-clicking a Calculated Column cell opens Formula Trace

By default, users can open Formula Trace by double-clicking any Calculated Column cell.

Set this to *false* to disable the double-click trigger (e.g. if double-click is used for something else in your application).

```ts {4}
  calculatedColumnOptions: {
    formulaTrace: {
      enableDoubleClick: false,
    },
  },
```

### `showContextMenuItem`

Whether the "Show Formula" item appears in the cell Context Menu

By default, a `Show Formula` item is added to the [Context Menu](https://www.adaptabletools.com/docs/ui-context-menu/index.md) for Calculated Column cells.

Set this to *false* to remove that Context Menu item.

```ts {4}
  calculatedColumnOptions: {
    formulaTrace: {
      showContextMenuItem: false,
    },
  },
```

## Flashing Calculated Columns

Calculated Columns can [flash their cells](https://www.adaptabletools.com/docs/handbook-flashing-cell/index.md) when their contents change.

Calculated Columns are not directly editable but they will update if a referenced column's value changes

It is possible for one Calculated Column to reference another Calculated Column and still flash when changed.

**Example: Calculated Columns: Flashing**

Calculated Columns flash when a referenced column changes

- This example shows 2 Calculated Columns which flash when values in their referenced columns change:
  - `Total Stars + Watchers` has an **`ANY_CHANGE()`** rule and flashes when one of its referenced Columns (`Github Stars` and `Github Watchers`) tick
  - `Stars Index (÷ 1000)` references the first Calculated Column with a rule **`[stars-index] > 50`**, so the chained column flashes when its value changes (and the rule matches)

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts      [template]
  columnDefs.ts         [template]
  gridOptions.ts        [template]
  index.ts              [template]
  onAdaptableReady.ts
  rowData.ts            [template]
  styles.css            [template]
  tickingDataHelper.ts  [template]
index.html              [template]
package.json            [template]
tsconfig.json           [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Calculated Column Flashing',
  flashingCellOptions: {
    defaultFlashDuration: 600,
    defaultUpChangeStyle: {
      BackColor: '#86d586',
    },
    defaultDownChangeStyle: {
      BackColor: '#e18989',
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['CalculatedColumn', 'FlashingCell'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          AutoSizeColumns: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'total-stars-watchers',
            'stars-index',
          ],
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Total Stars + Watchers',
          ColumnId: 'total-stars-watchers',
          Expression: '[github_stars] + [github_watchers]',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
        {
          FriendlyName: 'Stars Index (÷ 1000)',
          ColumnId: 'stars-index',
          Expression: '[total-stars-watchers] / 1000',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
      ],
    },
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flash-total-stars-watchers',
          Scope: {
            ColumnIds: ['total-stars-watchers'],
          },
          Rule: 'ANY_CHANGE()',
        },
        {
          Name: 'flash-stars-index-high',
          Scope: {
            ColumnIds: ['stars-index'],
          },
          Rule: '[stars-index] > 50',
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'format-calc-columns',
          Scope: {
            ColumnIds: ['total-stars-watchers', 'stars-index'],
          },
          DisplayFormat: {
            Formatter: 'NumberFormatter',
            Options: {
              FractionDigits: 0,
            },
          },
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';
import {tickNumericData} from './tickingDataHelper';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  tickNumericData(adaptableApi, 400, ['github_stars', 'github_watchers']);
};
```

## Calculated Columns and Alerts

Calculated Columns can trigger [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md).

This is most commonly a [Data Change Alert](https://www.adaptabletools.com/docs/handbook-alerting-data-change/index.md) with a [Boolean Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression-standard/index.md) evaluated against the changed cell value

Similar to Flashing Cells its possible for one Calculated Column to reference another Calculated Column and still trigger the Alert.

**Example: Calculated Columns: Alerts**

Data Change Alerts on Calculated Columns

- This example shows 2 Calculated Columns which trigger Data Change Alerts when values in their referenced columns change:
  - `Total Stars + Watchers` triggers an Alert (with a Notification) using the rule **`[total-stars-watchers] > 200000`** 
  - `Stars Index (÷ 1000)` references the first Calculated Column and a second Alert uses the rule **`[stars-index] > 150`** on that chained column

- Watch notifications appear when **`github_stars`** or **`github_watchers`** tick and their calculated values satisfy the Alert rules

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts      [template]
  columnDefs.ts         [template]
  gridOptions.ts        [template]
  index.ts              [template]
  onAdaptableReady.ts
  rowData.ts            [template]
  styles.css            [template]
  tickingDataHelper.ts  [template]
index.html              [template]
package.json            [template]
tsconfig.json           [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Calculated Column Alerts',
  initialState: {
    Dashboard: {
      ModuleButtons: ['CalculatedColumn', 'Alert'],
      Tabs: [
        {
          Name: 'Toolbars',
          Toolbars: ['Alert'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Alert'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          AutoSizeColumns: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'total-stars-watchers',
            'stars-index',
          ],
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Total Stars + Watchers',
          ColumnId: 'total-stars-watchers',
          Expression: '[github_stars] + [github_watchers]',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
        {
          FriendlyName: 'Stars Index (÷ 1000)',
          ColumnId: 'stars-index',
          Expression: '[total-stars-watchers] / 1000',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
      ],
    },
    Alert: {
      AlertDefinitions: [
        {
          Name: 'High total stars + watchers',
          MessageType: 'Warning',
          MessageHeader: 'High engagement',
          MessageText: 'Combined stars and watchers exceeded 200,000',
          Scope: {
            ColumnIds: ['total-stars-watchers'],
          },
          Rule: '[total-stars-watchers] > 200000',
          AlertProperties: {
            DisplayNotification: true,
            HighlightCell: true,
          },
        },
        {
          Name: 'High stars index',
          MessageType: 'Info',
          MessageHeader: 'Stars index',
          MessageText: 'Chained calculated value is above 150',
          Scope: {
            ColumnIds: ['stars-index'],
          },
          Rule: '[stars-index] > 150',
          AlertProperties: {
            DisplayNotification: true,
            HighlightCell: true,
          },
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'format-calc-columns',
          Scope: {
            ColumnIds: ['total-stars-watchers', 'stars-index'],
          },
          DisplayFormat: {
            Formatter: 'NumberFormatter',
            Options: {
              FractionDigits: 0,
            },
          },
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';
import {tickNumericData} from './tickingDataHelper';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  tickNumericData(adaptableApi, 500, ['github_stars', 'github_watchers']);
};
```

### Recalculating Dependent Calculated Columns

Flashing and Alerting in Calculated Columns is made possible as follows:

When a source column changes, AdapTable recalculates any dependent Calculated Columns and emits a synthetic **`calculatedColumnChange`** event for each derived value that actually moved.

This means that any objects scoped to a Calculated Column (e.g. [Flashing Cells](https://www.adaptabletools.com/docs/handbook-flashing-cell/index.md) or [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md)) can react when a column **referenced in its Expression** is edited or ticked.

This happens even though the Calculated Column itself, by its very nature, is not editable.

## Calculated Columns in Charts

As "normal" Columns, Calculated Columns can also be referenced in [Charts](https://www.adaptabletools.com/docs/handbook-charts/index.md).

If a Chart contains a Calculated Column, then any changes to a Column which is referenced in the Calculated Columns's Expression, will cause the chart to re-render.

**Example: Charts Calculated Column**

Charts using Calculated Columns

- This example demonstrates how Calculated Columns can be used in [Charts](https://www.adaptabletools.com/docs/handbook-charts/index.md)
- We create a Calculated Column called `Total PRs` which sums the `Open PRs` and `Closed PRs` columns
- We then create a small Pie Chart which displays the names of the first 5 frameworks and the Total PRs
- Any change to the underlying value of one of the Calculated Column Expression's constituent columns will cause the Chart to redraw

- Set the `Open PRs` Column in the first row (for Vue) to be 22400 and see how the Chart changes

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template, with charts]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template + shown below]
index.html             [template]
package.json           [template] + ag-charts-enterprise
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableButton,
  AdaptableOptions,
  CellUpdateRequest,
  CustomToolbarButtonContext,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Charts for Calculated Columns',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'ButtonToolbar',
        title: 'Buttons',
        toolbarButtons: [
          {
            label: 'Update First Row',
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              const firstNode = context.adaptableApi.gridApi.getFirstRowNode();
              const primaryKeyValue = firstNode!.id;

              const open_pr_count = firstNode!.data['open_pr_count'];
              const cellUpdateRequest: CellUpdateRequest = {
                columnId: 'open_pr_count',
                newValue: open_pr_count + 100,
                primaryKeyValue: primaryKeyValue,
                rowNode: firstNode,
              };
              context.adaptableApi.gridApi.setCellValue(cellUpdateRequest);
            },
            buttonStyle: {
              tone: 'accent',
              variant: 'raised',
            },
          },
        ],
      },
    ],
  },
  chartingOptions: {
    chartContainers: [
      {
        name: 'Above Grid',
        element: '#demoOutputAbove',
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {Name: 'Charting', Toolbars: ['Charting', 'ButtonToolbar', 'Buttons']},
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Charting'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Total PRs',
          ColumnId: 'total_pr_count',
          Expression: '[open_pr_count] + [closed_pr_count]',
          CalculatedColumnSettings: {
            DataType: 'number',
            Filterable: true,
          },
        },
      ],
    },
    Charting: {
      ChartDefinitions: [
        {
          Name: 'Top Frameworks',
          Model: {
            modelType: 'range',
            chartId: 'frameworks-pie',
            chartType: 'pie',
            chartThemeName: 'ag-vivid-dark',
            chartOptions: {
              pie: {
                background: {
                  visible: true,
                },
                padding: {
                  top: 20,
                  right: 20,
                  bottom: 20,
                  left: 20,
                },
                title: {
                  enabled: true,
                  text: 'Total PRs by Framework',
                },
                series: {
                  title: {
                    enabled: true,
                    text: '',
                  },
                  calloutLabel: {
                    enabled: true,
                  },
                  sectorLabel: {
                    enabled: true,
                  },
                },
              },
            },
            cellRange: {
              rowStartIndex: 0,
              rowEndIndex: 4,
              columns: ['name', 'total_pr_count'],
            },
            suppressChartRanges: false,
            unlinkChart: false,
          },
        },
      ],
    },

    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'total_pr_count',
            'open_pr_count',
            'closed_pr_count',
            'github_stars',
            'github_watchers',
            'language',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'has_projects',
            'has_pages',
            'week_issue_change',
            'open_issues_count',
            'closed_issues_count',
          ],
          ColumnSorts: [{ColumnId: 'github_stars', SortOrder: 'Desc'}],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,

    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  enableCharts: true,
  chartThemes: ['ag-vivid', 'ag-vivid-dark'],
  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo, ChartDefinition} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  const topChartContainer = document.getElementById(
    'demoOutputAbove'
  ) as HTMLDivElement;
  const chartDefs: ChartDefinition[] =
    adaptableApi.chartingApi.getChartDefinitions();
  adaptableApi.chartingApi.showChartDefinition(chartDefs[0], topChartContainer);
};
```

**`src/styles.css`**

```css
#demoOutputAbove {
  display: flex;
}
```
