本文整理匯總了TypeScript中d3-collection.nest函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript nest函數的具體用法?TypeScript nest怎麽用?TypeScript nest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了nest函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: prep
prep(initData) {
initData = initData.filter((d) => { return d.YEAR == 2016 });
let entries = nest()
.key((e: any) => { return e.CATEGORY; })
.key((e: any) => { return e.FUNDING_CATEGORY; })
.entries(initData);
let root = hierarchy({ values: entries }, (d) => {
return d.values;
}).sum((d) => {
if (d.TYPE === 'Total') {
return d.AMOUNT;
}
});
console.log(root);
}
示例2:
{ yield: 27.00, variety: 'Manchuria', year: 1931, site: 'University Farm' },
{ yield: 48.87, variety: 'Manchuria', year: 1931, site: 'Waseca' },
{ yield: 27.43, variety: 'Manchuria', year: 1931, site: 'Morris' },
{ yield: 43.07, variety: 'Glabron', year: 1931, site: 'University Farm' },
{ yield: 55.20, variety: 'Glabron', year: 1931, site: 'Waseca' },
{ yield: 26.00, variety: 'Manchuria', year: 1932, site: 'University Farm' },
{ yield: 47.87, variety: 'Manchuria', year: 1932, site: 'Waseca' },
{ yield: 26.43, variety: 'Manchuria', year: 1932, site: 'Morris' },
{ yield: 42.07, variety: 'Glabron', year: 1932, site: 'University Farm' },
{ yield: 54.20, variety: 'Glabron', year: 1932, site: 'Waseca' }
];
// Create Nest ========================================================
let nestL2: d3Collection.Nest<Yield, undefined>;
nestL2 = d3Collection.nest<Yield>();
let nestL1Rollup: d3Collection.Nest<Yield, number>;
nestL1Rollup = d3Collection.nest<Yield, number>();
// Configure Nest =====================================================
// key(...) and sortKeys(...) -----------------------------------------
nestL2 = nestL2
.key(d => {
return d.year.toString();
});
// with 2nd key with sortkey(...)
nestL2 = nestL2
示例3: computeData
computeData(): ReadonlyArray<object> {
const data = super.computeData();
if (data.length === 0 || !this.exists()) return data;
const columnLabels: string[] = this.validGroupBy().map(gb => gb.label());
const computedFields = this.validComputedFields().map(cf => {
return { label: cf.fieldID(), aggrFunc: cf.aggrFunc() };
});
const retVal = d3Nest()
.key((row: { [key: string]: any }) => {
let key = "";
for (const groupByLabel of columnLabels) {
key += ":" + row[groupByLabel];
}
return key;
})
.entries(data as object[]).map(_row => {
const row: {
[key: string]: any
} = _row;
delete row.key;
for (const groupByLabel of columnLabels) {
row[groupByLabel] = row.values[0][groupByLabel];
}
for (const cf of computedFields) {
row[cf.label] = cf.aggrFunc(row.values);
}
return row;
})
;
const outFields = this.outFields();
return retVal.map(row => {
const retVal = {};
for (const field of outFields) {
retVal[field.id] = row[field.id];
}
return retVal;
});
}