本文整理汇总了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;
});
}