# @javinor/canvas-grid

> Visual representation of a positive integer matrix (board).

Latest version **0.0.1** (published 2016-02-07) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @javinor/canvas-grid
pnpm add @javinor/canvas-grid
yarn add @javinor/canvas-grid
bun add @javinor/canvas-grid
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-02-07 |
| First published | 2016-02-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | javinor |

## Links

- npm: https://www.npmjs.com/package/@javinor/canvas-grid
- npm.io page: https://npm.io/package/@javinor/canvas-grid

## Recent versions

- 0.0.1 (latest) — 2016-02-07

## README

# CanvasGrid

Visual representation of a positive integer matrix (board).

### Examples
See [examples page][examples]. 
[examples]: https://javinor.github.io/CanvasGrid/

## Usage

#### Initialize

initialize with an `args` object containing the canvas element and optional initial board or options
```
var grid = new CanvasGrid({ canvas: document.getElementById('myCanvas') })
```

default options or grid styles and cell colors:
```
var defaultOptions =  {
  cellSize: 30,
  lineWidth: 0.5,
  gridColor: 'black',
  valueToColor: ['white', 'black']
}
```

#### Render

Render the board (only needed for initial render)
```
grid.render()
```

#### Set a new value / board
set the cell at row 2, column 3 to value of 1:
```
grid.setValue(2, 3, 1)
```
or shove in a new board
```
grid.setBoard([
  [0,1,0],
  [0,1,0],
  [0,1,0]
])
```

#### Handle Clicks
Default handling of clicks will be toggle through the `valueToColor` array given in `args.options`. 
```
canvas.addEventListener('click', (e) => grid.handleClick(e), false)
```

You can also supply your own `newValueFn` that will get the `row`, `col` and old `value` of a cell and return a new value:
```
grid.options.newValueFn = (row, col, val) => val ? 0 : 1
```

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