Lattice Grid Buy a licence

demo D199

Statistics of a selection

Drag a rectangle; it is summarised as one set of figures

grid.selection.statistics()

Building…
Loading a live grid…

The configuration

import * as ng from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import createLatticeGrid from '@toclocoinc/lattice-grid/modules/angular';

const { LatticeGridComponent } = createLatticeGrid({ ng, createGrid });

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" (range-changed)="report()" style="display:block;height:440px"></lattice-grid>' +
    '<div style="margin-top:12px;font-family:monospace">{{ out }}</div>',
})
export class AppComponent {
  @ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
  out = 'Select a block of numeric cells';

  grid = {
    rowKey: 'id',
    selection: { mode: 'multiple', ranges: true },
    columns,
    rows: [/* trading book records */],
  };

  // Drag a range of numeric cells: selection.statistics() returns the count,
  // median, quartiles and standard deviation for the block, read from the live
  // grid whenever the range changes.
  report() {
    const grid = this.gridRef && this.gridRef.grid;
    const s = grid && grid.selection.statistics();
    this.out = s
      ? s.cells + ' cells, median ' + s.median + ', q1 ' + s.q1 + ', q3 ' + s.q3 + ', sd ' + s.stddev
      : 'Select a block of numeric cells';
  }
}

bootstrapApplication(AppComponent);