-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
379 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
<script> | ||
export default { | ||
name: 'mermaid', | ||
name: 'Mermaid', | ||
props: { | ||
id: { | ||
type: String, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Xiaohan Zou (@Renovamen) | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# vuepress-plugin-roughviz | ||
|
||
A plugin for adding [roughViz.js](https://github.com/jwilber/roughViz) to [VuePress](https://vuepress.vuejs.org/). | ||
|
||
| ||
|
||
## Installation | ||
|
||
Install this plugin with: | ||
|
||
```bash | ||
yarn add vuepress-plugin-roughviz | ||
# or | ||
npm install vuepress-plugin-roughviz | ||
``` | ||
|
||
And add it to your `.vuepress/config.js`: | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
'vuepress-plugin-roughviz' | ||
] | ||
] | ||
} | ||
``` | ||
|
||
| ||
|
||
## Usage | ||
|
||
Then you can use [roughViz.js](https://github.com/jwilber/roughViz) in Markdown. | ||
|
||
roughViz.js supports the following chart types: | ||
|
||
- Bar (`bar`) | ||
- Horizontal Bar (`barh`) | ||
- Donut (`donut`) | ||
- Line (`line`) | ||
- Pie (`pie`) | ||
- Scatter (`scater`) | ||
- Stacked Bar (`stackedbar`) | ||
|
||
So the format of your code block's `token.info` should be `roughviz-{ chart-type }`. For example, to draw a Donut chart: | ||
|
||
~~~json | ||
```roughviz-donut | ||
{ | ||
"data": { | ||
"labels": ["North", "South", "East", "West"], | ||
"values": [10, 5, 8, 3] | ||
}, | ||
"title": "Regions", | ||
"colors": ["red", "orange", "blue", "skyblue"], | ||
"roughness": 4 | ||
} | ||
``` | ||
~~~ | ||
|
||
| ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Roughviz from './lib/Roughviz'; | ||
|
||
export default function (ctx) { | ||
const { Vue } = ctx; | ||
Vue.component('Roughviz', Roughviz); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path') | ||
const roughviz = require('./lib/markdown-it-roughviz') | ||
|
||
module.exports = (options, ctx) => { | ||
return { | ||
name:'vuepress-plugin-roughviz', | ||
enhanceAppFiles: path.resolve(__dirname, './enhanceApp.js'), | ||
chainMarkdown(config) { | ||
config | ||
.plugin('roughviz') | ||
.use(roughviz) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<div class="vuepress-roughviz-container"> | ||
<div :id="id" class="vuepress-roughviz"></div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { | ||
Bar, | ||
BarH, | ||
Donut, | ||
Line, | ||
Pie, | ||
Scatter, | ||
StackedBar | ||
} from "rough-viz/dist/roughviz.min.js"; | ||
export default { | ||
name: 'Roughviz', | ||
props: { | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
chart: { | ||
type: String, | ||
required: true | ||
}, | ||
code: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
mounted () { | ||
let data = JSON.parse(this.code); | ||
data.element = `#${this.id}`; | ||
switch(this.chart) { | ||
case 'bar': | ||
new Bar(data); | ||
break; | ||
case 'barh': | ||
new BarH(data); | ||
break; | ||
case 'donut': | ||
new Donut(data); | ||
break; | ||
case 'line': | ||
new Line(data); | ||
break; | ||
case 'pie': | ||
new Pie(data); | ||
break; | ||
case 'scatter': | ||
new Scatter(data); | ||
break; | ||
case 'stackedbar': | ||
new StackedBar(data); | ||
break; | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus"> | ||
.vuepress-roughviz-container | ||
margin 30px 0 | ||
text-align center | ||
.vuepress-roughviz | ||
overflow scroll | ||
display inline-block | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { hash } = require('@vuepress/shared-utils') | ||
|
||
const validType = ['bar', 'barh', 'donut', 'line', 'pie', 'scatter', 'stackedbar'] | ||
|
||
const mermaid = (md) => { | ||
const temp = md.renderer.rules.fence.bind(md.renderer.rules); | ||
md.renderer.rules.fence = (tokens, idx, options, env, slf) => { | ||
const token = tokens[idx]; | ||
const name = token.info.split('-')[0] | ||
const type = token.info.split('-')[1] | ||
|
||
if (name === 'roughviz' && validType.includes(type)) { | ||
try { | ||
const key = `roughviz_${type}_${hash(idx)}`; | ||
const code = token.content.trim(); | ||
|
||
md.$dataBlock[key] = code; | ||
return `<Roughviz id="${key}" chart="${type}" :code="$dataBlock.${key}"></Roughviz>`; | ||
} | ||
catch (err) { | ||
return `<pre>${err}</pre>` | ||
} | ||
} | ||
return temp(tokens, idx, options, env, slf); | ||
} | ||
} | ||
|
||
module.exports = mermaid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "vuepress-plugin-roughviz", | ||
"version": "0.1.0", | ||
"description": "A plugin for adding roughViz.js to VuePress.", | ||
"author": "Renovamen <renovamenzxh@gmail.com>", | ||
"main": "index.js", | ||
"keywords": [ | ||
"vue", | ||
"vuepress", | ||
"vuepress-plugin", | ||
"rough-viz", | ||
"roughviz", | ||
"roughviz.js" | ||
], | ||
"homepage": "https://github.com/Renovamen/vuepress-theme-gungnir/tree/main/packages/plugins/roughviz", | ||
"bugs": { | ||
"url": "https://github.com/Renovamen/vuepress-theme-gungnir/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Renovamen/vuepress-theme-gungnir.git", | ||
"directory": "packages/plugins/roughviz" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"rough-viz": "^1.0.6" | ||
} | ||
} |
Oops, something went wrong.
1a7da3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: