Skip to content
This repository was archived by the owner on Aug 1, 2022. It is now read-only.

Commit cb861f9

Browse files
committed
Merge branch 'release/v1.2.0'
2 parents 4306542 + 061e483 commit cb861f9

16 files changed

+30813
-10263
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
"contributions": [
3030
"ideas"
3131
]
32+
},
33+
{
34+
"login": "ern-arrowsmith",
35+
"name": "Ernie Arrowsmith",
36+
"avatar_url": "https://avatars2.githubusercontent.com/u/3596444?s=400&u=c4cc9bf80c5572d07c8f877635b785b3ab99eee7&v=4",
37+
"profile": "https://www.linkedin.com/in/ernarrowsmith/",
38+
"contributions": [
39+
"ideas"
40+
]
3241
}
3342
]
3443
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/node_modules
66
/umd
77
npm-debug.log*
8+
.vscode/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ script:
1414
- yarn test
1515
- yarn build
1616
deploy:
17+
skip_cleanup: true
1718
provider: npm
1819
email: mbeierling@gmail.com
1920
api_key:

CHANGELOG.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

78
## [Unreleased]
89

10+
## [1.2.0] - 2021-11-08
11+
12+
### Added
13+
14+
- Support for refreshing the background image
15+
- Grid customization props (grid size, line width & hide axis)
16+
- Export drawing to file/dataUrl using new `getDataURL` function
17+
- Panning & Zooming
18+
19+
### Changed
20+
21+
- z-index no longer hard-coded, allowing overlayed CanvasDraw components
22+
- big refactor, kudos to @markbiddlecom for this mammoth task
23+
- allow React 17 as peer dependency
924

1025
## [1.1.1] - 2020-04-27
26+
1127
### Added
28+
1229
- Started this CHANGELOG.md file to keep track of any changes per version
1330

1431
### Fixed
15-
- Fix touch draw issue. (https://github.com/embiem/react-canvas-draw/issues/29)
16-
- Fix "Can't draw dots" issue. (https://github.com/embiem/react-canvas-draw/issues/42)
17-
- Fix image not shown due to cache. (https://github.com/embiem/react-canvas-draw/issues/59)
18-
- Fix image issues on canvas resize. (https://github.com/embiem/react-canvas-draw/issues/66)
19-
- Fix SecurityError on save. (https://github.com/embiem/react-canvas-draw/issues/70)
32+
33+
- Fix touch draw issue. (<https://github.com/embiem/react-canvas-draw/issues/29>)
34+
- Fix "Can't draw dots" issue. (<https://github.com/embiem/react-canvas-draw/issues/42>)
35+
- Fix image not shown due to cache. (<https://github.com/embiem/react-canvas-draw/issues/59>)
36+
- Fix image issues on canvas resize. (<https://github.com/embiem/react-canvas-draw/issues/66>)
37+
- Fix SecurityError on save. (<https://github.com/embiem/react-canvas-draw/issues/70>)
2038

2139
### Changed
40+
2241
- Unified touch & mouse events to streamline core draw logic (handleDrawStart, handleDrawMove & handleDrawEnd)
2342

2443
## [1.1.0] - 2019-12-29
44+
2545
### Added
26-
- onChange prop #50 (https://github.com/embiem/react-canvas-draw/pull/50)
46+
47+
- onChange prop #50 (<https://github.com/embiem/react-canvas-draw/pull/50>)
2748

2849
### Fixed
29-
- Fix "Immediate flag should be really immediate" issue #30 (https://github.com/embiem/react-canvas-draw/issues/30)
50+
51+
- Fix "Immediate flag should be really immediate" issue #30 (<https://github.com/embiem/react-canvas-draw/issues/30>)

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Contributing
2+
3+
Thanks for considering to contribute to React Canvas Draw!
4+
5+
Please use the `develop` branch when creating PRs. Below are the necessary steps to get going.
6+
7+
If you want to be added to the contributors list in the README,
8+
please follow the [all-contributors bot instructions](https://allcontributors.org/docs/en/bot/usage).
9+
110
## Prerequisites
211

312
[Node.js](http://nodejs.org/) >= v4 must be installed.

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ These are the defaultProps of CanvasDraw. You can pass along any of these props
5858
imgSrc: "",
5959
saveData: null,
6060
immediateLoading: false,
61-
hideInterface: false
61+
hideInterface: false,
62+
gridSizeX: 25,
63+
gridSizeY: 25,
64+
gridLineWidth: 0.5,
65+
hideGridX: false,
66+
hideGridY: false
67+
enablePanAndZoom: false,
68+
mouseZoomFactor: 0.01,
69+
zoomExtents: { min: 0.33, max: 3 },
6270
};
6371
```
6472

@@ -68,7 +76,10 @@ Useful functions that you can call, e.g. when having a reference to this compone
6876

6977
- `getSaveData()` returns the drawing's save-data as a stringified object
7078
- `loadSaveData(saveData: String, immediate: Boolean)` loads a previously saved drawing using the saveData string, as well as an optional boolean flag to load it immediately, instead of live-drawing it.
71-
- `clear()` clears the canvas completely
79+
- `getDataURL(fileType, useBgImage, backgroundColour)` will export the canvas to a data URL, which can subsequently be used to share or manipulate the image file.
80+
- `clear()` clears the canvas completely, including previously erased lines, and resets the view. After a clear, `undo()` will have no effect.
81+
- `eraseAll()` clears the drawn lines but retains their data; calling `undo()` can restore the erased lines. _Note: erased lines are not included in the save data._
82+
- `resetView()` resets the canvas' view to defaults. Has no effect if the `enablePanAndZoom` property is `false`.
7283
- `undo()` removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.
7384

7485
## Local Development
@@ -79,7 +90,7 @@ You just need to clone it, yarn it & start it!
7990

8091
## Tips
8192

82-
If you want to save large strings, like the stringified JSON of a drawing, I recommend you to use [pieroxy/lz-string](https://github.com/pieroxy/lz-string) for compression. It's LZ compression will bring down your long strings to only ~10% of it's original size.
93+
If you want to save large strings, like the stringified JSON of a drawing, I recommend you use [pieroxy/lz-string](https://github.com/pieroxy/lz-string) for compression. It's LZ compression will bring down your long strings to only ~10% of its original size.
8394

8495
## Acknowledgement
8596

demo/src/index.js

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,43 @@ class Demo extends Component {
1010
width: 400,
1111
height: 400,
1212
brushRadius: 10,
13-
lazyRadius: 12
13+
lazyRadius: 12,
14+
backgroundImg: "https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg",
15+
imgs: [
16+
"https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg",
17+
"https://i.imgur.com/a0CGGVC.jpg"
18+
]
1419
};
20+
1521
componentDidMount() {
1622
// let's change the color randomly every 2 seconds. fun!
1723
window.setInterval(() => {
1824
this.setState({
1925
color: "#" + Math.floor(Math.random() * 16777215).toString(16)
2026
});
2127
}, 2000);
28+
29+
// let's change the background image every 2 seconds. fun!
30+
window.setInterval(() => {
31+
if (
32+
this.state.imgs &&
33+
this.state.imgs.length &&
34+
this.state.backgroundImg
35+
) {
36+
let img = '';
37+
let imgs = this.state.imgs;
38+
for (let i = 0; i < imgs.length; i++) {
39+
if (this.state.backgroundImg !== imgs[i]) {
40+
img = imgs[i];
41+
}
42+
}
43+
44+
this.setState({
45+
backgroundImg: img,
46+
});
47+
}
48+
}, 2000);
49+
2250
}
2351
render() {
2452
return (
@@ -69,9 +97,29 @@ class Demo extends Component {
6997
brushColor="rgba(155,12,60,0.3)"
7098
imgSrc="https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg"
7199
/>
100+
101+
<h2>Refreshable Background Image</h2>
102+
<p>This will refresh the background in every two seconds.</p>
103+
<CanvasDraw
104+
brushColor="rgba(155,12,60,0.3)"
105+
imgSrc={this.state.backgroundImg}
106+
/>
72107
<h2>Hide UI</h2>
73108
<p>To hide the UI elements, set the `hideInterface` prop. You can also hide the grid with the `hideGrid` prop.</p>
74109
<CanvasDraw hideInterface hideGrid />
110+
<h2>Zoom & Pan</h2>
111+
<p>
112+
Set the <span>enablePanAndZoom</span> prop to enable mouse scrolling
113+
and panning (using Ctrl), pinch zooming, and two-finger panning. If
114+
you want to ensure that all lines stay within the bounds of the
115+
canvas, set the <span>clampLinesToDocument</span> property.
116+
</p>
117+
<CanvasDraw
118+
enablePanAndZoom
119+
clampLinesToDocument
120+
gridColor="#ccc"
121+
imgSrc="https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg"
122+
/>
75123
<h2>Save & Load</h2>
76124
<p>
77125
This part got me most excited. Very easy to use saving and loading of
@@ -94,10 +142,10 @@ class Demo extends Component {
94142
</button>
95143
<button
96144
onClick={() => {
97-
this.saveableCanvas.clear();
145+
this.saveableCanvas.eraseAll();
98146
}}
99147
>
100-
Clear
148+
Erase
101149
</button>
102150
<button
103151
onClick={() => {
@@ -106,6 +154,14 @@ class Demo extends Component {
106154
>
107155
Undo
108156
</button>
157+
<button
158+
onClick={() => {
159+
console.log(this.saveableCanvas.getDataURL());
160+
alert("DataURL written to console")
161+
}}
162+
>
163+
GetDataURL
164+
</button>
109165
<div>
110166
<label>Width:</label>
111167
<input

nwb.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ module.exports = {
1212
webpack: {
1313
rules: {
1414
css: {
15-
modules: true,
16-
localIdentName: '[local]__[hash:base64:5]'
15+
modules: {
16+
localIdentName: '[local]__[hash:base64:5]',
17+
}
1718
}
1819
}
1920
}

0 commit comments

Comments
 (0)