Skip to content

Commit f4cd4a6

Browse files
author
Thomas Bolis
committed
Upgrading to latest packages
Adding Zoom functionality
1 parent 8496f3d commit f4cd4a6

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
* **0.2.7** New Functionality and bug fixes
4+
- Zoom In/Out functionality of drawing
5+
- Upgrading to latest package versions
6+
7+
* **0.2.6** Bug fixes and performance improvements
38
* **0.2.5** Upgrading to latest libraries and bug fixes
49
- Major
510
- React 15.1.0

examples/main.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import './main.css';
99

1010
import {
1111
Card,CardText,CardTitle,
12+
Drawer,
1213
AppBar,GridList,GridTile,
1314
Slider, Toggle, MenuItem,
1415
SelectField, IconButton,
@@ -24,6 +25,8 @@ import ClearIcon from 'material-ui/svg-icons/action/delete';
2425
import SaveIcon from 'material-ui/svg-icons/content/save';
2526
import RemoveIcon from 'material-ui/svg-icons/content/clear';
2627
import DownloadIcon from 'material-ui/svg-icons/file/file-download';
28+
import ZoomInIcon from 'material-ui/svg-icons/action/zoom-in';
29+
import ZoomOutIcon from 'material-ui/svg-icons/action/zoom-out';
2730

2831
import dataJson from './data.json'
2932
import dataUrl from './data.url'
@@ -291,6 +294,20 @@ class SketchFieldDemo extends React.Component {
291294
<Slider ref='slider' step={0.1}
292295
defaultValue={this.state.lineWidth/100}
293296
onChange={(e, v) => this.setState({lineWidth:v*100})}/>
297+
<br/>
298+
<label htmlFor='zoom'>Zoom</label>
299+
<div>
300+
<IconButton
301+
ref='zoom'
302+
onTouchTap={(e) => this._sketch.zoom(1.25)}>
303+
<ZoomInIcon />
304+
</IconButton>
305+
<IconButton
306+
ref='zoom1'
307+
onTouchTap={(e) => this._sketch.zoom(0.8)}>
308+
<ZoomOutIcon />
309+
</IconButton>
310+
</div>
294311
</CardText>
295312
</Card>
296313
<Card style={{margin:'5px 10px 5px 0'}}>

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"node": ">0.4.0 <1.0.0"
4141
},
4242
"devDependencies": {
43-
"babel-cli": "^6.9.0",
43+
"babel-cli": "^6.10.1",
4444
"babel-core": "^6.9.1",
45-
"babel-eslint": "^6.0.4",
45+
"babel-eslint": "^6.0.5",
4646
"babel-loader": "^6.2.4",
4747
"babel-plugin-transform-object-assign": "^6.8.0",
4848
"babel-plugin-transform-react-display-name": "^6.8.0",
@@ -53,27 +53,27 @@
5353
"babel-preset-react": "^6.5.0",
5454
"babel-preset-react-hmre": "^1.1.1",
5555
"babel-preset-stage-0": "^6.5.0",
56-
"canvas": "^1.3.16",
56+
"canvas": "^1.4.0",
5757
"chai": "^3.5.0",
5858
"core-js": "^2.4.0",
5959
"css-loader": "^0.23.1",
60-
"eslint": "^2.11.1",
60+
"eslint": "^2.13.1",
6161
"eslint-loader": "^1.3.0",
62-
"eslint-plugin-react": "^5.1.1",
62+
"eslint-plugin-react": "^5.2.2",
6363
"fabric": "^1.6.2",
6464
"flexboxgrid": "^6.3.0",
65-
"html-webpack-plugin": "^2.19.0",
65+
"html-webpack-plugin": "^2.21.0",
6666
"karma": "^0.13.22",
6767
"karma-babel-preprocessor": "^6.0.1",
6868
"karma-chai": "^0.1.0",
6969
"karma-coverage": "^1.0.0",
7070
"karma-mocha": "^1.0.1",
71-
"karma-mocha-reporter": "^2.0.3",
71+
"karma-mocha-reporter": "^2.0.4",
7272
"karma-phantomjs-launcher": "^1.0.0",
7373
"karma-phantomjs-shim": "^1.4.0",
7474
"karma-sourcemap-loader": "^0.3.7",
7575
"karma-webpack": "^1.7.0",
76-
"material-ui": "^0.15.0",
76+
"material-ui": "^0.15.1",
7777
"mocha": "^2.5.3",
7878
"my-local-ip": "^1.0.0",
7979
"open": "0.0.5",

src/SketchField.jsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,25 @@ class SketchField extends Component {
5858

5959
constructor(props, context) {
6060
super(props, context);
61+
// Internal functions
6162
this._resize = this._resize.bind(this);
6263
this._initTools = this._initTools.bind(this);
64+
// exposed
65+
this.zoom = this.zoom.bind(this);
6366
this.enableTouchScroll = this.enableTouchScroll.bind(this);
6467
this.disableTouchScroll = this.disableTouchScroll.bind(this);
65-
68+
//events
6669
this._onMouseUp = this._onMouseUp.bind(this);
6770
this._onMouseOut = this._onMouseOut.bind(this);
6871
this._onMouseDown = this._onMouseDown.bind(this);
6972
this._onMouseMove = this._onMouseMove.bind(this);
70-
7173
this._onObjectAdded = this._onObjectAdded.bind(this);
7274
this._onObjectMoving = this._onObjectMoving.bind(this);
7375
this._onObjectRemoved = this._onObjectRemoved.bind(this);
7476
this._onObjectScaling = this._onObjectScaling.bind(this);
7577
this._onObjectModified = this._onObjectModified.bind(this);
7678
this._onObjectRotating = this._onObjectRotating.bind(this);
77-
79+
// pure render
7880
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
7981
}
8082

@@ -154,12 +156,18 @@ class SketchField extends Component {
154156
this._selectedTool.configureCanvas(nextProps);
155157
}
156158

159+
/**
160+
* Enable touch Scrolling on Canvas
161+
*/
157162
enableTouchScroll() {
158163
let canvas = this._fc;
159164
if (canvas.allowTouchScrolling) return;
160165
canvas.allowTouchScrolling = true;
161166
}
162167

168+
/**
169+
* Disable touch Scrolling on Canvas
170+
*/
163171
disableTouchScroll() {
164172
let canvas = this._fc;
165173
if (canvas.allowTouchScrolling) {
@@ -284,6 +292,29 @@ class SketchField extends Component {
284292
canvas.calcOffset();
285293
}
286294

295+
/**
296+
* Zoom the drawing by the factor specified
297+
*
298+
* The zoom factor is a percentage with regards the original, for example if factor is set to 2
299+
* it will double the size whereas if it is set to 0.5 it will half the size
300+
*
301+
* @param factor the zoom factor
302+
*/
303+
zoom(factor) {
304+
let canvas = this._fc;
305+
let objects = canvas.getObjects();
306+
for (let i in objects) {
307+
objects[i].scaleX = objects[i].scaleX * factor;
308+
objects[i].scaleY = objects[i].scaleY * factor;
309+
objects[i].left = objects[i].left * factor;
310+
objects[i].top = objects[i].top * factor;
311+
objects[i].setCoords();
312+
}
313+
canvas.renderAll();
314+
canvas.calcOffset();
315+
}
316+
317+
287318
/**
288319
* Perform an undo operation on canvas, if it cannot undo it will leave the canvas intact
289320
*/

0 commit comments

Comments
 (0)