@d3fc/d3fc-extent

中文文档
4.0.2发布于 2020/08/30MITESM + CJS零依赖近 30 天下载 6.2万

Extends the d3 extent functionality to allow multiple accessors, padding and date support

原始使用文档
文档目录5 节
  1. Installing
  2. API Reference
  3. Linear
  4. Time
  5. Date

d3fc-extent

Extends the D3 extent functionality (found in d3-array) to allow padding, multiple accessors and date support

Main D3FC package

Installing

npm install @d3fc/d3fc-extent

API Reference

Linear

Calculates the extent of an array of data which can be used to set the range on a scale. Can also optionally pad the data in various ways as described below. Internally makes use of d3-array's min and max methods.


import { extentLinear } from 'd3fc-extent';

const data = [{ x: 1 }, { x: 2 }, { x: 4 }, { x: 8 }, { x: 16 }];

const extent = extentLinear()
  .accessors([d => d.x])
  .pad([1, 4])
  .padUnit('domain');

extent(data);

// [0, 20]

fc.extentLinear()

Constructs a new linear extent calculator.

linear.accessors([accessors])

If accessors is specified, sets the array of value accessors to the specified array and returns this extent instance. The accessors are applied to each data value before computing the extent. The value returned by the accessors must be a scalar value or an array of scalar values. Defaults to an identity function (i.e. d => d). If accessors is not specified, returns the current array of value accessors, which defaults [].

linear.pad([values])

If values is specified, sets the amount of padding applied to the minimum and maximum values of the extent, to the specified array [minPad, maxPad] and returns this extent instance. The unit of these values is set by padUnit. If values is not specified, returns the current array of padding values, which defaults [0, 0].

linear.padUnit([value])

If value is specified, sets the unit of the pad values applied to minimum and maximum values and returns this extent instance. Possible values are -

  • 'percent' - the default behavior of applying the values as a percentage of the extent e.g. pad values of [0.5, 0.5] would double the calculated extent.
  • 'domain' - the padding values specified are applied directly to the calculated extent. If value is not specified, returns the current array of padding unit, which defaults percent.

linear.symmetricalAbout([value])

If value is specified, sets the value around which the extent will be centered around and returns this extent instance. Can also be set to null to disable centering. Note this is applied before padding. If value is not specified, returns the current center value, which defaults null.

linear.include([values])

If values is specified, sets the array of additional values to include within the calculated extent to the specified array and returns this extent instance. This allows for always including an origin (e.g. [0]) or specifying a minimum extent to always be displayed (e.g. [10, 20]). Note included values are applied before symmetricalAbout. If values is not specified, returns the current array of included values, which defaults [].

Time

Calculates the extent of an array of data which can be used to set the range on a scale. Can also optionally pad the data in various ways as described below. Equivalent in functionality to linear but for Date values.


import extentTime from 'd3fc-extent';

const data = [{ x: new Date(2016, 0, 1) }, { x: new Date(2016, 0, 11) }];

const extent = extentTime()
  .accessors([d => d.x])
  .pad([0, 0.2]);

extent(data);

// [ 2016-01-01T00:00:00.000Z, 2016-01-13T00:00:00.000Z ]

fc.extentTime()

Constructs a new time extent calculator.

time.accessors([accessors])

If accessors is specified, sets the array of value accessors to the specified array and returns this extent instance. The accessors are applied to each data value before computing the extent. The value returned be the accessors must be a Date or an array of Dates. Defaults to an identity function (i.e. d => d). If accessors is not specified, returns the current array of value accessors, which defaults [].

time.pad([values])

If values is specified, sets the amount of padding applied to the minimum and maximum values of the extent, to the specified array [minPad, maxPad] and returns this extent instance. The unit of these values is set by padUnit. If values is not specified, returns the current array of padding values, which defaults [0, 0].

time.padUnit([value])

If value is specified, sets the unit of the pad values applied to minimum and maximum values and returns this extent instance. Possible values are -

  • 'percent' - the default behavior of applying the values as a percentage of the extent e.g. pad values of [0.5, 0.5] would double the calculated extent.
  • 'domain' - the padding values specified in milliseconds are applied directly to the calculated extent. If value is not specified, returns the current array of padding unit, which defaults percent.

time.symmetricalAbout([value])

If value is specified, sets the value around which the extent will be centered around and returns this extent instance. Can also be set to null to disable centering. Note this is applied before padding. If value is not specified, returns the current center value, which defaults null.

time.include([values])

If values is specified, sets the array of additional values to include within the calculated extent to the specified array and returns this extent instance. If values is not specified, returns the current array of included values, which defaults [].

Date

Deprecated - use time instead.

版本与发布记录

@d3fc/d3fc-extent 共发布 18 个版本,首次发布于 2018/08/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.2latest2020/08/306 年前
4.0.12020/07/146 年前
4.0.02020/04/166 年前
3.2.02020/03/196 年前
3.1.72019/11/286 年前
3.1.62019/09/047 年前

关于 @d3fc/d3fc-extent 的常见问题

@d3fc/d3fc-extent 是什么?

Extends the d3 extent functionality to allow multiple accessors, padding and date support

如何安装 @d3fc/d3fc-extent?

在项目目录运行 npm install @d3fc/d3fc-extent,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:d3-array(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@d3fc/d3fc-extent 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/d3fc__d3fc-extent 是否存在。

@d3fc/d3fc-extent 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@d3fc/d3fc-extent 可以商用吗?

@d3fc/d3fc-extent 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d3fc/d3fc-extent 的下载量有多少?

根据 npm 官方下载统计,@d3fc/d3fc-extent 在 2026/10/11 – 2026/11/09 这 30 天内被下载 61,855 次,日均约 2,062 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@d3fc/d3fc-extent 还在维护吗?

最新版本 4.0.2 发布于 2020/08/30(6 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。