jens-ox/metrics-graphics

View on GitHub
packages/lib/docs/Utility.md

Summary

Maintainability
Test Coverage
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [makeAccessorFunction][1]
    -   [Parameters][2]
-   [isArrayOfArrays][3]
    -   [Parameters][4]
-   [isArrayOfObjects][5]
    -   [Parameters][6]
-   [isArrayOfObjectsOrEmpty][7]
    -   [Parameters][8]
-   [randomId][9]
-   [getPixelDimension][10]
    -   [Parameters][11]
-   [getWidth][12]
    -   [Parameters][13]
-   [getHeight][14]
    -   [Parameters][15]

## makeAccessorFunction

Handle cases where the user specifies an accessor string instead of an accessor function.

### Parameters

-   `functionOrString` **([Function][16] \| [String][17])** accessor string/function to be made an accessor function

Returns **[Function][16]** accessor function

## isArrayOfArrays

Check if an array is an array of arrays.

### Parameters

-   `arr` **[Array][18]** array to be checked.

Returns **[Boolean][19]** whether or not the given array is an array of arrays.

## isArrayOfObjects

Check if an array is an array of objects.

### Parameters

-   `arr` **[Array][18]** array to be checked.

Returns **[Boolean][19]** whether or not the given array is an array of arrays.

## isArrayOfObjectsOrEmpty

Check if an array is an array of objects or empty.

### Parameters

-   `arr` **[Array][18]** array to be checked.

Returns **[Boolean][19]** whether or not the array is an array of objects or empty.

## randomId

Generate a random id.
Used to create ids for clip paths, which need to be referenced by id.

Returns **[String][17]** random id string.

## getPixelDimension

Get height or width in pixels.

### Parameters

-   `target` **[String][17]** d3 select specifier.
-   `dimension` **[String][17]** height or width.

Returns **[Number][20]** width or height in pixels.

## getWidth

Get width of element.

### Parameters

-   `isFullWidth` **[Boolean][19]** whether or not to stretch the element to full width.
-   `width` **[Number][20]** custom width if applicable.
-   `target` **[String][17]** d3 select specifier.

Returns **[Number][20]** width of element.

## getHeight

Get height of element.

### Parameters

-   `isFullHeight` **[Boolean][19]** whether or not to stretch the element to full height.
-   `height` **[Number][20]** custom height if applicable.
-   `target` **[String][17]** d3 select specifier.

Returns **[Number][20]** height of element.

[1]: #makeaccessorfunction

[2]: #parameters

[3]: #isarrayofarrays

[4]: #parameters-1

[5]: #isarrayofobjects

[6]: #parameters-2

[7]: #isarrayofobjectsorempty

[8]: #parameters-3

[9]: #randomid

[10]: #getpixeldimension

[11]: #parameters-4

[12]: #getwidth

[13]: #parameters-5

[14]: #getheight

[15]: #parameters-6

[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number