@flourish/colors

中文文档
9.0.0发布于 2026/07/08LicenseRef-LICENSEES Module近 30 天下载 2087

Adds color settings

原始使用文档
文档目录4 节
  1. Install
  2. Unit tests
  3. Basic usage
  4. Methods

Flourish colors

Add settings and logic to easily add custom colors to your template

Install

npm install @flourish/colors

Unit tests

Test using:

npm run test

Test a specific test file using:

npm run test test/name-of-test.test.mjs

Basic usage

The settings.yml file should be imported into your template’s template.yml file, like this:

  - Colours
  - property: color
    import: "@flourish/colors"

You can use overrides to control whether to show categorical or numerical color settings. See below for an example. Replace [dataset] and [binding] with the relevant dataset and binding name (learn more about conditional settings).

  - Colours
  - property: color
    import: "@flourish/colors"
    overrides:
      - tag: discrete
        method: extend
        show_if:
          data.[dataset].[binding].type: string
      - tag: numeric
        method: extend
        show_if:
          data.[dataset].[binding].type: number

Add a color object to your template state:

export var state = {
    color: {},
    ...
}

Import the package like import createColors from "@flourish/colors"

var colors = createColors(state.color) creates a new object colors.

You only need to pass in a state to get the color function working.

Methods

colors.getColor(value) finds the correct color for value. Will just return the fallback value unless the updateColorScale method has been called at some point.

colors.fallback([value]) returns the current fallback value if value is undefined or (usually) sets it to value if it is defined and returns the colors object. The value "default" (re)sets the fallback to be the default value of null. The fallback value is returned whenever the getColor method cannot interpret the value passed into it (for example if that value is non-numeric when in sequential or diverging mode).

colors.updateColorScale(domain) updates the color scale based on the domain array. In general the domain array is an array of data values that the scale should be based on. For a categorical scale, this'll be an array of strings. For numeric (sequential or diverging) scales, this'll be an array of numbers (e.g. [10, 50, 30, 20, 50, 10, 30, 60, 100, 90]).

版本与发布记录

@flourish/colors 共发布 18 个版本,首次发布于 2020/06/01;过去 12 个月发布了 1 个版本。

版本发布日期距今
9.0.0latest2026/07/084 个月前
8.0.02025/03/281.6 年前
7.0.12025/01/101.8 年前
7.0.02024/07/312 年前
6.2.22024/02/082 年前
6.2.12023/11/143 年前

关于 @flourish/colors 的常见问题

@flourish/colors 是什么?

Adds color settings

如何安装 @flourish/colors?

在项目目录运行 npm install @flourish/colors,或使用 pnpm add / yarn add / bun add。

@flourish/colors 支持 TypeScript 吗?

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

@flourish/colors 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@flourish/colors 可以商用吗?

@flourish/colors 使用 LicenseRef-LICENSE 许可。声明的许可为 LicenseRef-LICENSE,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@flourish/colors 的下载量有多少?

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

@flourish/colors 还在维护吗?

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