Skip to content

Commit ff710f7

Browse files
committed
Initial commit of viewbox library
0 parents  commit ff710f7

10 files changed

+406
-0
lines changed

Diff for: .eslintrc

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"rules": {
3+
"indent": [2, 2, {"SwitchCase": 1}],
4+
"quotes": [2, "single", "avoid-escape"],
5+
"linebreak-style": [2, "unix"],
6+
"semi": [2, "never"],
7+
"eqeqeq": [2, "allow-null"],
8+
"no-extend-native": 2,
9+
"curly": [2, "all"],
10+
"strict": [2, "global"],
11+
"space-before-function-paren": [2, "never"],
12+
"space-unary-ops": [2, {"words": true, "nonwords": false}],
13+
"space-infix-ops": [2, {"int32Hint": false}],
14+
"keyword-spacing": 2,
15+
"spaced-comment": [2, "always", { "exceptions": ["-", "+"] }],
16+
"no-inline-comments": 2,
17+
"func-style": [2, "expression"],
18+
"callback-return": [2, ["done", "next"]],
19+
"no-path-concat": 2,
20+
"no-use-before-define": 2,
21+
"array-bracket-spacing": [2, "never"],
22+
"object-curly-spacing": [2, "never"],
23+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
24+
"comma-spacing": [2, {"before": false, "after": true}],
25+
"brace-style": [2, "stroustrup", {"allowSingleLine": true}],
26+
"handle-callback-err": [2, "^(e|err|error)$" ],
27+
"one-var": [2, "never"],
28+
"one-var-declaration-per-line": [2, "always"],
29+
"newline-after-var": 2,
30+
"newline-before-return": 2,
31+
"no-else-return": 2,
32+
"no-unexpected-multiline": 2,
33+
"eol-last": 2
34+
},
35+
"env": {
36+
"node": true,
37+
"browser": true,
38+
"mocha": true
39+
},
40+
"extends": "eslint:recommended"
41+
}

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
coverage
3+
integration/public/bundle.js
4+
example/*.svg

Diff for: .travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '0.10'
5+
- '4'
6+
- node
7+
matrix:
8+
include:
9+
- node_js: node
10+
env: TEST_BROWSERS=true
11+
script: npm run-script ci
12+
deploy:
13+
provider: npm
14+
15+
api_key:
16+
secure: vBZRpIaY4dy2nV6evcERLPMycsQ4u2ZfTQZhed8zWWbKXlLDYufYzdklzBhWbozj8jCyqnwm1uLriVXTafYS84zIliRssjMj6UC5irG9EUsTZFTBDDoPtywYpbSWQMj2YjBGiDu5b+iuTgcuD2VdyFxP7fMST0PjXscuD/jWQgRtcLaN+NmJh1oQyd1Mr7F7WcP8xqq1f68UmpKgdrAsdITWfbXGKsI8bDZ4aAHbrjnbhnxIZuXJmgr/QUg97MDl156B8ptpqi3ivykoFZs6Rlhpgxaf6p6knvuy8CwOoAirNe+c/uWl6W+OmtZyX43uHPlNvZrWG/F6/nNFNBYdiLJlw3wy/d8p18kw00ALeYfshOhdqjXoq+HdpeA2Do6cJpJtlnCuJHOd6nQyGbkMtygdfBfBnj4UgFA3zP9dqNcLEoF3Ny+1emo1PgrOa1fzkX9U0/SMUIZt3QKcH6io5duStMAt5kQuhjlylJ52/9tjqafY+Xghoo+f3hbFhs5D9T8+KXviqY4wHEJPVZ6k1yMa45SLjNX+xzBHj5KVwVkZGPrjtAa2Z4PYCMQ21T5f8ugo2CZYVrirgTV5MszQXJPvePEIxCxs2Rk3SUhaCiacKpzM8MzRsqAfc3YwIOp07iE0cLmTYQYTMrITrnkwJw5kTS6UXFMWm0xDdjrGUo0=
17+
on:
18+
node: node
19+
condition: "$TEST_BROWSERS = true"
20+
tags: true
21+
all_branches: true
22+
repo: tracespace/viewbox
23+
env:
24+
global:
25+
- secure: ZDLrgNyY0+8JbQy/4J+8644/cSrKd1xpkIVCV7btXCF1A5/1qatHNr0HZlo7HLRu5CUAaySnhhrrtO1QNWEh9E4aKKul/CVV1mODrz3qC+dLCYBXFKdnUkKyTJmYMos33IlZEIsKcJn6CUS5zVS77jN4Ey3ywwDZHaa0RhGAOK8aYHrzBPTuuB8S6s0oNVrKNwROa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7Y64TbCqK8vajnufca2zS4da+Vtf+tXJwAKRrdZnc9eCUKB2uriaJglY6uBl1gHZQ2TTu1RM19C8VvL8mjY8NqHlVJ1xhuFHNnYA16Lz0qZEM=

Diff for: .zuul.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ui: mocha-bdd
2+
browsers:
3+
- name: chrome
4+
version: -1..latest
5+
- name: safari
6+
version: -1..latest
7+
- name: firefox
8+
version: -1..latest
9+
- name: ie
10+
version: -1..latest
11+
browserify:
12+
- plugin: proxyquire-universal

Diff for: API.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# TOC
2+
- [viewbox](#viewbox)
3+
<a name=""></a>
4+
5+
<a name="viewbox"></a>
6+
# viewbox
7+
should be able to create a new empty viewbox.
8+
9+
```js
10+
var result = viewbox.create()
11+
expect(result).to.eql([])
12+
```
13+
14+
should be able to add two viewboxes.
15+
16+
```js
17+
var box1 = [0, -1, 4, 5]
18+
var box2 = [-3, 1, 2, 6]
19+
var result = viewbox.add(box1, box2)
20+
expect(result).to.eql([-3, -1, 7, 8])
21+
```
22+
23+
should be able to add a viewbox to a new viewbox.
24+
25+
```js
26+
var box1 = viewbox.create()
27+
var box2 = [-3, 1, 2, 6]
28+
var result = viewbox.add(box1, box2)
29+
expect(result).to.eql([-3, 1, 2, 6])
30+
```
31+
32+
should be able to add a new viewbox to a viewbox.
33+
34+
```js
35+
var box1 = [0, -1, 4, 5]
36+
var box2 = viewbox.create()
37+
var result = viewbox.add(box1, box2)
38+
expect(result).to.eql([0, -1, 4, 5])
39+
```
40+
41+
should be able to scale a viewbox.
42+
43+
```js
44+
var box = [-1.5, 0.5, 1, 3]
45+
var result = viewbox.scale(box, 2)
46+
expect(result).to.eql([-3, 1, 2, 6])
47+
```
48+
49+
should be able to generate attributes for an SVG rectangle.
50+
51+
```js
52+
var box = [0, -1, 4, 5]
53+
var result = viewbox.rect(box)
54+
expect(result).to.eql({
55+
x: 0,
56+
y: -1,
57+
width: 4,
58+
height: 5
59+
})
60+
```
61+
62+
should output a 0 size rectangle for a new viewbox.
63+
64+
```js
65+
var box = viewbox.create()
66+
var result = viewbox.rect(box)
67+
expect(result).to.eql({
68+
x: 0,
69+
y: 0,
70+
width: 0,
71+
height: 0
72+
})
73+
```
74+

Diff for: LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2016 by Mike Cousins, shared under the terms of the MIT License.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# viewbox
2+
3+
[![npm](https://img.shields.io/npm/v/viewbox.svg?style=flat-square)](https://www.npmjs.com/package/viewbox)
4+
[![Travis](https://img.shields.io/travis/tracespace/viewbox.svg?style=flat-square)](https://travis-ci.org/tracespace/viewbox)
5+
[![Coveralls](https://img.shields.io/coveralls/tracespace/viewbox.svg?style=flat-square)](https://coveralls.io/github/tracespace/viewbox)
6+
[![David](https://img.shields.io/david/tracespace/viewbox.svg?style=flat-square)](https://david-dm.org/tracespace/viewbox)
7+
[![David](https://img.shields.io/david/dev/tracespace/viewbox.svg?style=flat-square)](https://david-dm.org/tracespace/viewbox#info=devDependencies)
8+
9+
Utility library for dealing with SVG viewboxes as plain arrays.
10+
11+
Install with:
12+
13+
```
14+
$ npm install --save viewbox
15+
```
16+
17+
## usage
18+
19+
``` javascript
20+
var viewbox = require('viewbox')
21+
```
22+
23+
See [API.md](API.md) for usage.
24+
25+
## developing and contributing
26+
27+
Clone and then `$ npm install`. Please accompany all PRs with applicable tests. Please test your code in browsers, as Travis CI cannot run browser tests for PRs.
28+
29+
### unit testing
30+
31+
This module uses [Mocha](http://mochajs.org/) and [Chai](http://chaijs.com/) for unit testing, [Istanbul](https://github.com/gotwarlost/istanbul) for coverage, and [ESLint](http://eslint.org/) for linting.
32+
33+
* `$ npm test` - run the tests, calculate coverage, and lint
34+
* `$ npm run test:watch` - run the tests on code changes (does not lint nor cover)
35+
* `$ npm run lint` - lint the code (will be run as a pre-commit script)
36+
37+
### browser testing
38+
39+
Browser tests are run with [Zuul](https://github.com/defunctzombie/zuul) and [Sauce Labs](https://saucelabs.com/opensauce/) on the latest two versions of Chrome, Firefox, Safari, and Internet Explorer, as well as the latest version of Edge.
40+
41+
* `$ npm run test:browser` - run the unit tests in a local browser
42+
* `$ npm run test:sauce` - run the units tests in several browsers using Open Sauce (Sauce Labs account and local [.zuulrc](https://github.com/defunctzombie/zuul/wiki/Zuulrc) required)

Diff for: index.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// viewbox helper library
2+
'use strict'
3+
4+
module.exports = {
5+
create: function createViewbox() {
6+
return []
7+
},
8+
9+
add: function addViewboxes(box, addend) {
10+
if (!box.length) {
11+
return addend
12+
}
13+
14+
if (!addend.length) {
15+
return box
16+
}
17+
18+
var xMin = Math.min(box[0], addend[0])
19+
var yMin = Math.min(box[1], addend[1])
20+
var xMax = Math.max((box[0] + box[2]), (addend[0] + addend[2]))
21+
var yMax = Math.max((box[1] + box[3]), (addend[1] + addend[3]))
22+
23+
return [xMin, yMin, (xMax - xMin), (yMax - yMin)]
24+
},
25+
26+
scale: function scaleViewboxes(box, scale) {
27+
return box.map(function(component) {
28+
return component * scale
29+
})
30+
},
31+
32+
rect: function viewboxRect(box) {
33+
box = box && box.length
34+
? box
35+
: [0, 0, 0, 0]
36+
37+
return {
38+
x: box[0],
39+
y: box[1],
40+
width: box[2],
41+
height: box[3]
42+
}
43+
},
44+
45+
asString: function(box) {
46+
box = box && box.length
47+
? box
48+
: [0, 0, 0, 0]
49+
50+
return box.join(' ')
51+
}
52+
}

Diff for: package.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "viewbox",
3+
"version": "0.0.0",
4+
"description": "Library for dealing with SVG viewboxes as plain arrays",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"lint": "eslint *.js",
11+
"test": "istanbul cover _mocha",
12+
"posttest": "npm run lint",
13+
"doc": "mocha --reporter markdown > API.md",
14+
"preversion": "npm run doc && git add API.md",
15+
"test:watch": "mocha --reporter dot --watch",
16+
"test:browser": "zuul --local -- test.js",
17+
"test:sauce": "zuul -- test.js",
18+
"ci": "npm test && if [ \"${TEST_BROWSERS}\" = \"true\" ]; then npm run ci:browser; fi",
19+
"ci:browser": "if [ \"${TRAVIS_PULL_REQUEST}\" = \"false\" ]; then npm run test:sauce; fi",
20+
"postci": "coveralls < ./coverage/lcov.info"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "git://github.com/tracespace/viewbox.git"
25+
},
26+
"keywords": [
27+
"svg",
28+
"viewbox",
29+
"geometry"
30+
],
31+
"contributors": [
32+
"Mike Cousins <[email protected]> (http://cousins.io/)"
33+
],
34+
"license": "MIT",
35+
"bugs": {
36+
"url": "https://github.com/tracespace/viewbox/issues"
37+
},
38+
"homepage": "https://github.com/tracespace/viewbox",
39+
"devDependencies": {
40+
"chai": "^3.5.0",
41+
"coveralls": "^2.11.9",
42+
"eslint": "^2.13.1",
43+
"istanbul": "^0.4.4",
44+
"mocha": "^2.5.3",
45+
"zuul": "^3.10.1"
46+
},
47+
"dependencies": {}
48+
}

0 commit comments

Comments
 (0)