demo D193
Statistics without a panel in Angular
Every figure available to your own interface, as an object
grid.statistics.*
This grid exposes every figure it computes as a plain object, for your own interface with no panel involved. It lets you take the statistics into a custom dashboard or export, so the numbers are available wherever you need them.
This is the Angular version. A standalone component takes the whole configuration through one config input, surfaces grid events as outputs, and exposes the live grid on a getter for anything the inputs do not cover.
The configuration
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
const columns = [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number' },
{ field: 'bid', title: 'Bid', type: 'number' },
{ field: 'volume', title: 'Volume', type: 'number' },
{ field: 'notional', title: 'Notional', type: 'number',
format: { style: 'currency', currency: 'USD' }, total: 'sum' },
];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<lattice-grid [config]="grid" (filter-changed)="report()" style="display:block;height:460px"></lattice-grid>' +
'<pre style="margin-top:12px">{{ out }}</pre>',
})
export class AppComponent implements AfterViewInit {
@ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
out = '';
grid = {
rowKey: 'id',
columnDefaults: { filter: true },
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns,
rows: [/* trading book records */],
};
// Read the statistics API straight from the live grid. Every figure is over
// the filtered rows, so filter a desk and they all follow.
report() {
const grid = this.gridRef && this.gridRef.grid;
if (!grid) return;
const s = grid.statistics;
this.out = JSON.stringify({
profile: s.profile('notional'),
correlation: s.correlation('price', 'bid'),
regression: s.regression('price', 'bid'),
spearman: s.spearman('price', 'bid'),
weightedMedian: s.weightedQuantile('price', 'volume', 0.5),
}, null, 2);
}
ngAfterViewInit() { this.report(); }
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});