-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
330202a
commit a89e6a6
Showing
7 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: Value Decimals | ||
hide_table_of_contents: true | ||
--- | ||
|
||
import RacingBars from '../../src/components/RacingBars'; | ||
import { valueDecimals } from './\_gallery-demos.ts'; | ||
|
||
A demo for using [`valueDecimals`](../documentation/options.md#valuedecimals) to control the number of decimal places to display for values. | ||
|
||
<!--truncate--> | ||
|
||
### Chart | ||
|
||
<div className="gallery"> | ||
<RacingBars | ||
{...valueDecimals} | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Colors | ||
--- | ||
|
||
TODO... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Data Transformation | ||
--- | ||
|
||
By, default, the [loaded data](../documentation/data.md) is used as is. | ||
|
||
However, it is possible to transform the data before it is used in the chart, by one of these ways: | ||
|
||
## `dataTransform` function | ||
|
||
The [chart options](../documentation/options.md) can have a [`dataTransform`](../documentation/options.md#datatransform) function which can be used to transform the data before it is used in the chart. It receives the loaded data and returns the transformed data. | ||
|
||
Example: | ||
|
||
```js | ||
import { race } from 'racing-bars'; | ||
|
||
const options = { | ||
dataTransform: (data) => | ||
data.map((d) => ({ | ||
...d, | ||
icon: `https://flagsapi.com/${d.code}/flat/64.png`, | ||
})), | ||
title: 'World Population', | ||
// ... | ||
}; | ||
|
||
race('/data/population.csv', '#race', options); | ||
``` | ||
|
||
## Manually loading and transforming data | ||
|
||
The [`loadData`](../documentation/api.md#loaddata) function can be used to load data. It can then be transformed before it is used in the chart. | ||
|
||
```js | ||
import { loadData, race } from 'racing-bars'; | ||
|
||
const data = await loadData('/data/population.csv', 'csv'); | ||
const transformedData = data.map((d) => ({ | ||
...d, | ||
icon: `https://flagsapi.com/${d.code}/flat/64.png`, | ||
})); | ||
|
||
const options = { | ||
title: 'World Population', | ||
// ... | ||
}; | ||
|
||
race(transformedData, '#race', options); | ||
``` | ||
|
||
## `valueDecimals` option | ||
|
||
In case you just need to control the number of decimal places to display for values, you do not need to transform the data. You may just use the [`valueDecimals`](../documentation/options.md#valuedecimals) option. | ||
|
||
```js | ||
import { race } from 'racing-bars'; | ||
|
||
const options = { | ||
title: 'World Population', | ||
valueDecimals: 0, | ||
// ... | ||
}; | ||
|
||
race('/data/population.csv', '#race', options); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters