• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript d3-array.bisector函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中d3-array.bisector函数的典型用法代码示例。如果您正苦于以下问题:TypeScript bisector函数的具体用法?TypeScript bisector怎么用?TypeScript bisector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bisector函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: compareToTimeKey

export const getIndexAtTimeKey = <Value>(
  keyAccessor: (value: Value) => TimeKey,
  compareValues?: Comparator
) => {
  const comparator = compareToTimeKey(keyAccessor, compareValues);
  const collectionBisector = bisector(comparator);

  return (collection: Value[], key: TimeKey): number | null => {
    const index = collectionBisector.left(collection, key);

    if (index >= collection.length) {
      return null;
    }

    if (comparator(collection[index], key) !== 0) {
      return null;
    }

    return index;
  };
};
开发者ID:elastic,项目名称:kibana,代码行数:21,代码来源:time_key.ts


示例2: Date

num = d3Array.bisect(readonlyStringyNumbersArray, '21');
num = d3Array.bisect(readonlyStringyNumbersArray, '21', 1);
num = d3Array.bisect(readonlyStringyNumbersArray, '21', 1, 4);

num = d3Array.bisect(readonlyDateArray, new Date(2011, 2, 1));
num = d3Array.bisect(readonlyDateArray, new Date(2011, 2, 1), 1);
num = d3Array.bisect(readonlyDateArray, new Date(2011, 2, 1), 1, 2);

// bisector() ------------------------------------------------------------------

mixedObjectArray.sort((a, b) => a.date.valueOf() - b.date.valueOf());

let mixedObjectDateBisectorObject: d3Array.Bisector<MixedObject, Date>;

// define using accessor
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(el => el.date);

// define using comparator
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>((el, x) =>
    el.date.valueOf() - x.valueOf());

// bisect left
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14));
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14), 1);
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14), 3, 4);

num = mixedObjectDateBisectorObject.left(readonlyMixedObjectArray, new Date(2015, 3, 14));
num = mixedObjectDateBisectorObject.left(readonlyMixedObjectArray, new Date(2015, 3, 14), 1);
num = mixedObjectDateBisectorObject.left(readonlyMixedObjectArray, new Date(2015, 3, 14), 3, 4);

// bisect right
开发者ID:itslenny,项目名称:DefinitelyTyped,代码行数:31,代码来源:d3-array-tests.ts


示例3: bisector

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { bisector } from 'd3-array';

import { LogEntries as LogEntriesQuery } from '../../../common/graphql/types';
import { compareToTimeKey, getIndexAtTimeKey, TimeKey } from '../../../common/time';

export type LogEntry = LogEntriesQuery.Entries;

export type LogEntryMessageSegment = LogEntriesQuery.Message;

export const getLogEntryKey = (entry: LogEntry) => entry.key;

const logEntryTimeBisector = bisector(compareToTimeKey(getLogEntryKey));

export const getLogEntryIndexBeforeTime = logEntryTimeBisector.left;
export const getLogEntryIndexAfterTime = logEntryTimeBisector.right;
export const getLogEntryIndexAtTime = getIndexAtTimeKey(getLogEntryKey);

export const getLogEntryAtTime = (entries: LogEntry[], time: TimeKey) => {
  const entryIndex = getLogEntryIndexAtTime(entries, time);

  return entryIndex !== null ? entries[entryIndex] : null;
};
开发者ID:salihkardan,项目名称:kibana,代码行数:28,代码来源:log_entry.ts


示例4: Date

num = d3Array.bisect(['0', '2', '3', '4', '7', '8'], '21', 1);
num = d3Array.bisect(['0', '2', '3', '4', '7', '8'], '21', 1, 4);

num = d3Array.bisect([new Date(2010, 1, 1), new Date(2011, 1, 1), new Date(2012, 1, 1), new Date(2013, 1, 1)], new Date(2011, 2, 1));
num = d3Array.bisect([new Date(2010, 1, 1), new Date(2011, 1, 1), new Date(2012, 1, 1), new Date(2013, 1, 1)], new Date(2011, 2, 1), 1);
num = d3Array.bisect([new Date(2010, 1, 1), new Date(2011, 1, 1), new Date(2012, 1, 1), new Date(2013, 1, 1)], new Date(2011, 2, 1), 1, 2);

// bisector() ------------------------------------------------------------------

mixedObjectArray.sort(function (a, b) { return a.date.valueOf() - b.date.valueOf(); });

let mixedObjectDateBisectorObject: d3Array.Bisector<MixedObject, Date>;

// define using accessor
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(function (el) {
    return el.date;
});

// define using comparator
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(function (el, x) {
    return el.date.valueOf() - x.valueOf();
});

// bisect left
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14));
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14), 1);
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14), 3, 4);

// bisect right
num = mixedObjectDateBisectorObject.right(mixedObjectArray, new Date(2015, 3, 14));
num = mixedObjectDateBisectorObject.right(mixedObjectArray, new Date(2015, 3, 14), 1);
开发者ID:DmitryEfimenko,项目名称:DefinitelyTyped,代码行数:31,代码来源:d3-array-tests.ts


示例5: bisector

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { bisector } from 'd3-array';

import { compareToTimeKey, TimeKey } from '../time';

export interface SearchResult {
  gid: string;
  fields: TimeKey;
  matches: SearchResultFieldMatches;
}

export interface SearchResultFieldMatches {
  [field: string]: string[];
}

export const getSearchResultKey = (result: SearchResult) =>
  ({
    gid: result.gid,
    tiebreaker: result.fields.tiebreaker,
    time: result.fields.time,
  } as TimeKey);

const searchResultTimeBisector = bisector(compareToTimeKey(getSearchResultKey));
export const getSearchResultIndexBeforeTime = searchResultTimeBisector.left;
export const getSearchResultIndexAfterTime = searchResultTimeBisector.right;
开发者ID:elastic,项目名称:kibana,代码行数:30,代码来源:log_search_result.ts


示例6: getStreamItemTimeKey

}

export function getStreamItemTimeKey(item: StreamItem) {
  switch (item.kind) {
    case 'logEntry':
      return item.logEntry.key;
  }
}

export function getStreamItemId(item: StreamItem) {
  switch (item.kind) {
    case 'logEntry':
      return `${item.logEntry.key.time}:${item.logEntry.key.tiebreaker}:${item.logEntry.gid}`;
  }
}

export function parseStreamItemId(id: string) {
  const idFragments = id.split(':');

  return {
    gid: idFragments.slice(2).join(':'),
    tiebreaker: parseInt(idFragments[1], 10),
    time: parseInt(idFragments[0], 10),
  };
}

const streamItemTimeBisector = bisector(compareToTimeKey(getStreamItemTimeKey));

export const getStreamItemBeforeTimeKey = (streamItems: StreamItem[], key: TimeKey) =>
  streamItems[Math.min(streamItemTimeBisector.left(streamItems, key), streamItems.length - 1)];
开发者ID:elastic,项目名称:kibana,代码行数:30,代码来源:item.ts



注:本文中的d3-array.bisector函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript d3-array.cross函数代码示例发布时间:2022-05-24
下一篇:
TypeScript d3-array.bisectRight函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap