MCPcopy Create free account
hub / github.com/microsoft/SandDance / topLookup

Function topLookup

packages/sanddance-specs/src/top.ts:8–50  ·  view source on GitHub ↗
(column: Column, count: number, source: string, legend: string, lookupName: string, fieldName: string, indexName: string)

Source from the content-addressed store, hash-verified

6import { Data } from 'vega-typings';
7
8export function topLookup(column: Column, count: number, source: string, legend: string, lookupName: string, fieldName: string, indexName: string) {
9 const data: Data[] = [
10 {
11 name: lookupName,
12 source,
13 transform: [
14 {
15 type: 'aggregate',
16 groupby: [safeFieldName(column.name)],
17 },
18 {
19 type: 'window',
20 ops: ['count'],
21 as: [indexName],
22 },
23 {
24 type: 'filter',
25 expr: `datum[${JSON.stringify(indexName)}] <= ${count}`,
26 },
27 ],
28 },
29 {
30 name: legend,
31 source,
32 transform: [
33 {
34 type: 'lookup',
35 from: lookupName,
36 key: safeFieldName(column.name),
37 fields: [column.name].map(safeFieldName),
38 values: [column.name].map(safeFieldName),
39 as: [fieldName],
40 },
41 {
42 type: 'formula',
43 expr: `datum[${JSON.stringify(fieldName)}] == null ? '${Other}' : datum[${JSON.stringify(fieldName)}]`,
44 as: fieldName,
45 },
46 ],
47 },
48 ];
49 return data;
50}

Callers 1

addColorFunction · 0.90

Calls 1

safeFieldNameFunction · 0.90

Tested by

no test coverage detected