Skip to content

Commit

Permalink
Merge pull request #24 from NHS-digital-website/DW-2981-added-chart-i…
Browse files Browse the repository at this point in the history
…cons2

[DW-2981] Added chart icons
  • Loading branch information
LEJA3 authored Jan 11, 2023
2 parents 9e36b33 + a7d3bfd commit fff4310
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 23 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/distribution-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:

- run: npm --no-git-tag-version version ${{ github.event.release.tag_name }}

# build the project
- run: npm run build

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The purpose of this library is create accessible data visualisations for web wit

### Download the latest release

To you can download the latest releases on the [release page.](https://github.com/NHS-digital-website/nhsd-dataviz/releases).
To you can download the latest releases on the [release page](https://github.com/NHS-digital-website/nhsd-dataviz/releases).

### Build from source

Expand Down Expand Up @@ -71,6 +71,7 @@ nhsdviz.chart(<i>selector</i>, <i><a href="#optionsObject">options</a></i>)
| data | <a href="#dataObject">Data object</a> | Chart data |
| source | { text: String, href: String } | Source text |
| palette | String | Chart palette |
| icon | String (<a href="#icons">icon name</a>) | Chart icon |
| desktopViewport | number (px) | Desktop viewport (default: 1024) |

### <a name="dataObject" href="#dataObject">#</a> Data object
Expand All @@ -87,7 +88,23 @@ nhsdviz.chart(<i>selector</i>, <i><a href="#optionsObject">options</a></i>)
| quantity | number | Chart quantity value (stat) |
| series | { name: string, value: [number] } | Chart series data (column) |

### Examples
### <a name="icons" href="#icons">#</a> Supported icons

If building from source icons should be placed in the `assets/icons/` directory, these icons can then be referenced by their file names.

If using the distribution library the following icons are avaliable:

- `arrow-down`
- `arrow-up`
- `calendar`
- `invite`
- `person`
- `tooth`
- `wine-glass`

--------

## Examples

#### Pie Chart
https://jsfiddle.net/LEJA3/cq8rbs12/
Expand All @@ -104,6 +121,7 @@ https://jsfiddle.net/LEJA3/rov9weby/
#### Column Chart
https://jsfiddle.net/LEJA3/fqtphz7o/

--------
## Colour palette

nhsdviz.createPalette(<i>name</i>, <i><a href="#paletteObject">palette</a></i>)
Expand Down
1 change: 1 addition & 0 deletions assets/icons/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions assets/icons/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/icons/invite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/icons/person.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/icons/tooth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/icons/wine-glass.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion rollup.config.js → build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { terser } from "rollup-plugin-terser";
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import svgImporter from "./svg-importer";

const removeCircularDependencyWarning = function ( message ) {
if (message.code === 'CIRCULAR_DEPENDENCY') {
Expand All @@ -28,9 +29,10 @@ export default [{
preventAssignment: true,
}),
terser(),
svgImporter(),
],
onwarn: removeCircularDependencyWarning,
},{
}, {
input: 'src/dataviz.ts',
output: [{
file: 'dist/nhsd-dataviz.js',
Expand All @@ -55,6 +57,7 @@ export default [{
preventAssignment: true,
}),
commonjs(),
svgImporter(),
],
onwarn: removeCircularDependencyWarning,
}];
20 changes: 20 additions & 0 deletions build/svg-importer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import glob from 'fast-glob';
import { readFile } from 'fs/promises';
import path from 'path';

export default () => ({
name: 'svg-importer',
resolveId: (id, importer) => {
if (!id.match(/\.svg$/)) return null;
return path.resolve(importer, '..', id).replace(/\\/g, '/');
},
load: async (id) => {
if (!id.match(/\.svg$/)) return null;
const icons = {};
for (const svgPath of await glob(id, { absolute: true })) {
const fname = svgPath.split("/").slice(-1)[0].replace(/\.svg$/, "");
icons[fname] = (await readFile(svgPath)).toString();
}
return `export default ${JSON.stringify(icons)}`;
}
});
Loading

0 comments on commit fff4310

Please sign in to comment.