Skip to content

Commit

Permalink
🛠 导出svg图片功能
Browse files Browse the repository at this point in the history
  • Loading branch information
longfangsong committed Oct 8, 2018
1 parent b1bd707 commit 807125a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# Poplar

[![license](https://img.shields.io/github/license/synyi/poplar.svg)](https://github.com/synyi/poplar/blob/master/LICENSE)
[![version](https://img.shields.io/badge/npm%20version-1.3.0-brightgreen.svg)](https://www.npmjs.com/package/poplar-annotation)
[![version](https://img.shields.io/npm/v/poplar-annotation.svg)](https://www.npmjs.com/package/poplar-annotation)


A web-based annotation tool for natural language processing (NLP) needs, inspired by [brat rapid annotation tool](http://brat.nlplab.org/).
Expand Down
6 changes: 5 additions & 1 deletion doc/en.md
Expand Up @@ -240,4 +240,8 @@ All `Repository` and `annotator.store` has an attribute `json`, we can get a jso

All `Entity` can be serialized by using `JSON.stringify()`

`annotator.store.json` can be used to reconstruct the `Annotator`, as the first param of `new Annotator`.
`annotator.store.json` can be used to reconstruct the `Annotator`, as the first param of `new Annotator`.

### Image exporting

Now we support exporting to .svg files, just call `annotator.export()`to get the content of the svg file, and the use sth like `FileReader` to write it into a file which user can download.
6 changes: 5 additions & 1 deletion doc/zh.md
Expand Up @@ -263,4 +263,8 @@ for(let [id, entity] of annotator.store.labelCategoryRepo) {

而所有`Entity`都可以使用`JSON.stringify()`序列化。

`annotator.store`对象序列化得到的json可以用作`new Annotator`的第一个参数,来重建Annotator对象。
`annotator.store`对象序列化得到的json可以用作`new Annotator`的第一个参数,来重建Annotator对象。

### 图片导出

目前支持导出到svg文件,只需调用`annotator.export()`来获取到svg文件的内容,然后使用`FileReader`等方式写入文件即可。
4 changes: 4 additions & 0 deletions src/Annotator/Annotator.ts
Expand Up @@ -52,4 +52,8 @@ export class Annotator extends EventEmitter {
remove() {
this.htmlElement.innerHTML = '';
}

export(): string {
return this.view.export();
}
}
4 changes: 4 additions & 0 deletions src/Annotator/View/View.ts
Expand Up @@ -80,4 +80,8 @@ export class View implements RepositoryRoot {
resize() {
this.svgDoc.size(this.svgDoc.bbox().width + 50, this.svgDoc.bbox().height + 50);
}

export(): string {
return '<?xml version="1.0" encoding="UTF-8"?>' + this.svgDoc.svg();
}
}
5 changes: 5 additions & 0 deletions webpack.prod.js
@@ -1,4 +1,6 @@
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
mode: 'production',
entry: './index.ts',
Expand All @@ -19,5 +21,8 @@ module.exports = {
filename: 'index.js',
library: 'Poplar',
libraryTarget: "umd"
},
optimization: {
minimizer: [new UglifyJsPlugin()]
}
};
103 changes: 102 additions & 1 deletion yarn.lock
Expand Up @@ -167,6 +167,10 @@ acorn@^5.0.0, acorn@^5.6.2:
version "5.7.1"
resolved "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8"

ajv-errors@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/ajv-errors/-/ajv-errors-1.0.0.tgz#ecf021fa108fd17dfb5e6b383f2dd233e31ffc59"

ajv-keywords@^3.1.0:
version "3.2.0"
resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz#e86b819c602cf8821ad637413698f1dec021847a"
Expand Down Expand Up @@ -502,6 +506,25 @@ cacache@^10.0.4:
unique-filename "^1.1.0"
y18n "^4.0.0"

cacache@^11.2.0:
version "11.2.0"
resolved "https://registry.npmjs.org/cacache/-/cacache-11.2.0.tgz#617bdc0b02844af56310e411c0878941d5739965"
dependencies:
bluebird "^3.5.1"
chownr "^1.0.1"
figgy-pudding "^3.1.0"
glob "^7.1.2"
graceful-fs "^4.1.11"
lru-cache "^4.1.3"
mississippi "^3.0.0"
mkdirp "^0.5.1"
move-concurrently "^1.0.1"
promise-inflight "^1.0.1"
rimraf "^2.6.2"
ssri "^6.0.0"
unique-filename "^1.1.0"
y18n "^4.0.0"

cache-base@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2"
Expand Down Expand Up @@ -667,6 +690,10 @@ commander@~2.13.0:
version "2.13.0"
resolved "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"

commander@~2.17.1:
version "2.17.1"
resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down Expand Up @@ -1306,6 +1333,10 @@ faye-websocket@~0.11.0:
dependencies:
websocket-driver ">=0.5.1"

figgy-pudding@^3.1.0, figgy-pudding@^3.5.1:
version "3.5.1"
resolved "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790"

figures@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
Expand Down Expand Up @@ -1341,6 +1372,14 @@ find-cache-dir@^1.0.0:
make-dir "^1.0.0"
pkg-dir "^2.0.0"

find-cache-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.0.0.tgz#4c1faed59f45184530fb9d7fa123a4d04a98472d"
dependencies:
commondir "^1.0.1"
make-dir "^1.0.0"
pkg-dir "^3.0.0"

find-up@^1.0.0:
version "1.1.2"
resolved "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
Expand Down Expand Up @@ -2106,7 +2145,7 @@ lower-case@^1.1.1:
version "1.1.4"
resolved "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac"

lru-cache@^4.0.1, lru-cache@^4.1.1:
lru-cache@^4.0.1, lru-cache@^4.1.1, lru-cache@^4.1.3:
version "4.1.3"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz#a1175cf3496dfc8436c156c334b4955992bce69c"
dependencies:
Expand Down Expand Up @@ -2281,6 +2320,21 @@ mississippi@^2.0.0:
stream-each "^1.1.0"
through2 "^2.0.0"

mississippi@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz#ea0a3291f97e0b5e8776b363d5f0a12d94c67022"
dependencies:
concat-stream "^1.5.0"
duplexify "^3.4.2"
end-of-stream "^1.1.0"
flush-write-stream "^1.0.0"
from2 "^2.1.0"
parallel-transform "^1.1.0"
pump "^3.0.0"
pumpify "^1.3.3"
stream-each "^1.1.0"
through2 "^2.0.0"

mixin-deep@^1.2.0:
version "1.3.1"
resolved "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe"
Expand Down Expand Up @@ -2766,6 +2820,12 @@ pkg-dir@^2.0.0:
dependencies:
find-up "^2.1.0"

pkg-dir@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"
dependencies:
find-up "^3.0.0"

portfinder@^1.0.9:
version "1.0.16"
resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.16.tgz#a6a68be9c352bc66c1a4c17a261f661f3facaf52"
Expand Down Expand Up @@ -2829,6 +2889,13 @@ pump@^2.0.0, pump@^2.0.1:
end-of-stream "^1.1.0"
once "^1.3.1"

pump@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
dependencies:
end-of-stream "^1.1.0"
once "^1.3.1"

pumpify@^1.3.3:
version "1.5.1"
resolved "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz#36513be246ab27570b1a374a5ce278bfd74370ce"
Expand Down Expand Up @@ -3088,6 +3155,14 @@ schema-utils@^0.4.4, schema-utils@^0.4.5:
ajv "^6.1.0"
ajv-keywords "^3.1.0"

schema-utils@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"
dependencies:
ajv "^6.1.0"
ajv-errors "^1.0.0"
ajv-keywords "^3.1.0"

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down Expand Up @@ -3332,6 +3407,12 @@ ssri@^5.2.4:
dependencies:
safe-buffer "^5.1.1"

ssri@^6.0.0:
version "6.0.1"
resolved "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8"
dependencies:
figgy-pudding "^3.5.1"

static-extend@^0.1.1:
version "0.1.2"
resolved "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
Expand Down Expand Up @@ -3570,6 +3651,13 @@ uglify-js@3.4.x:
commander "~2.16.0"
source-map "~0.6.1"

uglify-js@^3.0.0:
version "3.4.9"
resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
dependencies:
commander "~2.17.1"
source-map "~0.6.1"

uglifyjs-webpack-plugin@^1.2.4:
version "1.3.0"
resolved "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.3.0.tgz#75f548160858163a08643e086d5fefe18a5d67de"
Expand All @@ -3583,6 +3671,19 @@ uglifyjs-webpack-plugin@^1.2.4:
webpack-sources "^1.1.0"
worker-farm "^1.5.2"

uglifyjs-webpack-plugin@^2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.0.1.tgz#f346af53ed496ce72fef462517d417f62bec3010"
dependencies:
cacache "^11.2.0"
find-cache-dir "^2.0.0"
schema-utils "^1.0.0"
serialize-javascript "^1.4.0"
source-map "^0.6.1"
uglify-js "^3.0.0"
webpack-sources "^1.1.0"
worker-farm "^1.5.2"

union-value@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"
Expand Down

0 comments on commit 807125a

Please sign in to comment.