@flourish/axes-highlights

中文文档
5.0.0发布于 2026/11/02LicenseRef-LICENSEESM + CJS近 30 天下载 2278

Axis highlighting

原始使用文档
文档目录18 节
  1. Getting started
  2. 1. Installation
  3. 2. Add settings and state
  4. 3. Initialize the axes highlights
  5. 4. Update axis highlights
  6. Methods
  7. axes_highlights.animationDuration(number)
  8. axes_highlights.appendPatternsTo(selection)
  9. axes_highlights.appendTo(selection)
  10. axes_highlights.chartLayout(chart_layout)
  11. axes_highlights.facetName(string)
  12. axes_highlights.numberParser(fn)
  13. axes_highlights.offset(object)
  14. axes_highlights.update()
  15. axes_highlights.xDisabled(boolean)
  16. axes_highlights.xExtendByStep(boolean)
  17. axes_highlights.yDisabled(boolean)
  18. axes_highlights.yExtendByStep(boolean)

Flourish axes highlights

This module lets users add highlights to flourish-chart-layout (or flourish-axes) axes.

Getting started

1. Installation

npm install --save @flourish/axes-highlights

2. Add settings and state

const state = {
    axes_highlights: {} // Add any properties to this object to override the default settings
}
# template.yml
- property: axes_highlights
  import: "@flourish/axes-highlights"

3. Initialize the axes highlights

import initAxesHighlights from "@flourish/axes-highlights";
var axes_highlights = initAxesHighlights(state.axes_highlights);

4. Update axis highlights

In the template's update function (e.g. updateGraphic) you typically call the following methods:

let container = select(...);

axes_highlights
    .appendTo(container)
    .chartLayout(chart_layout)
    .update();

The minimum methods you will need to use is appendTo, chartLayout and update. See "Methods" for full configuration.

container is a D3 selection representing the element the highlights should be rendered in. You may need to import d3-transition in the module that makes the container selection, so that transitions are available. (Without this, the axis highlights might not display at all.)

This basic implementation appends the axes highlights to a container (container). If you want to append multiple axes highlights containers (for multiple facets for example) inside the same parent container, you can use the offset() method to position the axes highlights container (see example of implementation here). Axes highlights should be appended per facet, so for example in LBP and scatter it is called in the facet.js file for each facet group.

Methods

axes_highlights.animationDuration(number)

How long you want the animations to take. Expects a number.

axes_highlights.appendPatternsTo(selection)

Axis highlights can be rendered using an SVG pattern. Pass in the container you want the patterns to be appended to. It takes a d3 selection. If this is not called it will default to the appendTo container. As axes highlights are called per facet, it would be inefficient for a template with multiple facets to append the patterns to the facet container, as it would lead to patterns being defined more times than necessary. So if you are using a template that has multiple facets you should call appendPatternsTo just once in the draw function, passing it a container that wraps all of the facets (such as the svg) so that the same patterns are used for all axes highlights. If it is a template that doesnt have multiple facets you dont need to call this method as the default should work fine.

axes_highlights.appendTo(selection)

The parent element to append it to. We tend to use the fl-data-foreground group as the parent (if it exists). e.g. .appendTo(select(".fl-data-foreground")). Expects a d3 selection.

axes_highlights.chartLayout(chart_layout)

Specifies a chart layout (or axes) instance to attach the highlight to. Used for scales, margins, plot dimentions etc (should be one per facet).

Expects it to have the following properties, typically part of the @flourish/chart-layout (or @flourish/axes) module:

- xDatetimeParse
- yDatetimeParse
- margins
- plot_height
- plot_width
- xData
- yData
- xScale
- yScale

axes_highlights.facetName(string)

Name of facet, used to know if the highlight should apply to that facet or not. Expects a string.

axes_highlights.numberParser(fn)

Used to parse numbers e.g. localization.getParser(). Used to parse numbers when one of the axes is of type number. (If the axes are of type date we use the chart layout (or axes) date parsers and strings arent parsed). Expects a function.

axes_highlights.offset(object)

Adds offset to the axes highlights container. Expects an object containing an x and y property, eg. {x: 25, y: 10}.

axes_highlights.update()

Update highlights!

axes_highlights.xDisabled(boolean)

If you want x highlights to be disabled (e.g. in LBP when a chart doesnt have an x axis). Expects a boolean.

axes_highlights.xExtendByStep(boolean)

If you want x area highlights to be extended (e.g. in LBP the area goes beyond the exact x value because it is covering a grid of columns). Expects a boolean.

axes_highlights.yDisabled(boolean)

If you want y highlights to be disabled (e.g. in LBP when a chart doesnt have an y axis). Expects a boolean.

axes_highlights.yExtendByStep(boolean)

If you want y area highlights to be extended (e.g. in LBP the area goes beyond the exact y value because it is covering a grid of columns). Expects a boolean.

版本与发布记录

@flourish/axes-highlights 共发布 23 个版本,首次发布于 2021/02/16;过去 12 个月发布了 1 个版本。

版本发布日期距今
5.0.0latest2026/11/0213 天前
4.0.12025/01/101.8 年前
4.0.02024/07/312 年前
3.1.82024/06/172 年前
3.1.72024/02/082 年前
3.1.62023/07/273 年前

关于 @flourish/axes-highlights 的常见问题

@flourish/axes-highlights 是什么?

Axis highlighting

如何安装 @flourish/axes-highlights?

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

@flourish/axes-highlights 支持 TypeScript 吗?

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

@flourish/axes-highlights 支持 ESM 还是 CommonJS?

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

@flourish/axes-highlights 可以商用吗?

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

@flourish/axes-highlights 的下载量有多少?

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

@flourish/axes-highlights 还在维护吗?

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