當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript d3-collection.nest函數代碼示例

本文整理匯總了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);		

	}
開發者ID:Ao21,項目名稱:rollup-test,代碼行數:20,代碼來源:index.ts

示例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
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:d3-collection-tests.ts

示例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;
     });
 }
開發者ID:GordonSmith,項目名稱:Visualization,代碼行數:38,代碼來源:groupby.ts


注:本文中的d3-collection.nest函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。