# @d3-composer/utils

> Utilities for xy, series, and other common visualization tasks, part of d3-composer

Latest version **0.8.0** (published 2019-06-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @d3-composer/utils
pnpm add @d3-composer/utils
yarn add @d3-composer/utils
bun add @d3-composer/utils
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2019-06-13 |
| First published | 2018-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Tim Hall |
| Maintainers | timhall |
| Keywords | d3, d3-composer, utils, xy, series |

## Links

- npm: https://www.npmjs.com/package/@d3-composer/utils
- Repository: https://github.com/CSNW/d3-composer
- Issues: https://github.com/CSNW/d3-composer/issues
- npm.io page: https://npm.io/package/@d3-composer/utils

## Dependencies (2)

- [d3-array](https://npm.io/package/d3-array.md) ^1
- [d3-selection](https://npm.io/package/d3-selection.md) ^1

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.8.0 (latest) — 2019-06-13
- 0.7.1 — 2019-06-13
- 0.7.0 — 2019-06-13
- 0.6.6 — 2018-10-05
- 0.6.0 — 2018-09-19
- 0.5.0 — 2018-09-16
- 0.4.0 — 2018-09-14
- 0.3.3 — 2018-09-11
- 0.3.2 — 2018-09-10
- 0.3.1 — 2018-09-10
- 0.3.0 — 2018-09-10
- 0.2.0 — 2018-09-10
- 0.2.0-beta — 2018-09-10
- 0.1.0 — 2018-09-09

## README

# @d3-composer/utils

## API

<a href="#toStyle" name="toStyle">#</a> <b>toStyle</b>(<i>style</i>)

Convert string, object, or function to style string

```js
const style = toStyle({ fill: 'blue', stroke: 'red' });
// style = 'fill: blue; stroke: red;'

const fn = toStyle(d => ({ fill: d.fill }));
// fn ~= d => `fill: ${d.fill};`

const dynamic = toStyle({ fill: d => d.fill, stroke: 'none' });
// dynamic ~= d => `fill: ${d.fill}; stroke: none;`
```

<a href="#toMargin" name="toMargin">#</a> <b>toMargin</b>(<i>margin</i>)

Convert number or object to margin array `[top, right, bottom, left]`.

```js
toMargin() // [0, 0, 0, 0]
toMargin(10) // [10, 10, 10, 10]
toMargin({ top: 10 }) // [10, 0, 0, 0]
toMargin([0, 0, 10, 0]) // [0, 0, 10, 0]
```

<a href="#passthrough" name="passthrough">#</a> <b>passthrough</b>(<i>d</i>)

Helper for passing through data from selection by default (`d => d || []`)

<a href="#array" name="array">#</a> <b>array</b>(<i>value</i>)

Helper for wrapping value in an array, handling a value function if given

<a href="#fn" name="fn">#</a> <b>fn</b>(<i>value</i>)

Helper for ensuring returned value is a function by wrapping if necessary

<a href="#seriesExtent" name="seriesExtent">#</a> <b>seriesExtent</b>(<i>data</i>, <i>values</i>, <i>value</i>)

Calculate `[min, max]` for series data.

```js
const data = [
  { values: [{ x: 100 }] },
  { values: [{ x: 0 }] }
];

const [min, max] = seriesExtent(data, series => series.values, d => d.x);
// min = 0, max = 100
```

<a href="#Size-local" name="Size-local">#</a> <b>Size</b>

`d3.local` used for retrieving defined size for node (e.g. from grid area).

<a href="#Area-local" name="Area-local">#</a> <b>Area</b>

`d3.local` use for retrieving grid area for node.

<a href="#Series-local" name="Series-local">#</a> <b>Series</b>

`d3.local` used for retrieving series for node.

---
_Source: https://npm.io/package/@d3-composer/utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
