├── .github └── workflows │ └── lint-and-test.yml ├── .gitignore ├── .prettierignore ├── LICENSE ├── README.md ├── dist ├── jquery.min.js ├── load-polyfills.js ├── underscore.min.js ├── web-component.css └── web-component.js ├── docs ├── .fix.js ├── .tpl.hbs ├── chart.md ├── column.md ├── dataset.md └── parser.md ├── index.js ├── lib ├── Block.svelte ├── BlocksRegion.svelte ├── Menu.svelte ├── Visualization.svelte ├── VisualizationIframe.svelte ├── blocks │ ├── Byline.svelte │ ├── Description.svelte │ ├── EditInDatawrapper.svelte │ ├── Embed.svelte │ ├── GetTheData.svelte │ ├── Headline.svelte │ ├── HorizontalRule.svelte │ ├── Logo.svelte │ ├── LogoInner.svelte │ ├── Notes.svelte │ ├── Rectangle.svelte │ ├── Source.svelte │ ├── Watermark.svelte │ └── svgRule.svelte ├── dw │ ├── block.mjs │ ├── chart.mjs │ ├── dataset │ │ ├── addComputedColumns.mjs │ │ ├── applyChanges.mjs │ │ ├── column.mjs │ │ ├── column.test.mjs │ │ ├── columnTypes │ │ │ ├── date.mjs │ │ │ ├── date.test.mjs │ │ │ ├── index.mjs │ │ │ ├── number.mjs │ │ │ ├── number.test.mjs │ │ │ ├── text.mjs │ │ │ └── text.test.mjs │ │ ├── delimited.mjs │ │ ├── delimited.test.mjs │ │ ├── index.mjs │ │ ├── index.test.mjs │ │ ├── json.mjs │ │ └── reorderColumns.mjs │ ├── index.mjs │ ├── notify.mjs │ ├── svelteChart.mjs │ ├── theme.mjs │ ├── utils │ │ ├── events.mjs │ │ ├── filter.mjs │ │ ├── getNonChartHeight.mjs │ │ ├── htmlTemplate.mjs │ │ ├── htmlTemplate.test.mjs │ │ ├── index.mjs │ │ ├── parser.mjs │ │ └── parser.test.mjs │ ├── visualization.base.mjs │ └── visualization.mjs ├── embed.js ├── shared.mjs └── styles.less ├── load-polyfills.js ├── main.mjs ├── package-lock.json ├── package.json └── rollup.config.js /.github/workflows/lint-and-test.yml: -------------------------------------------------------------------------------- 1 | name: lint-and-test 2 | on: ['push'] 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: actions/setup-node@v2 9 | with: 10 | node-version: '14' 11 | - name: Create npmrc 12 | run: | 13 | echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc 14 | - name: Install dependencies 15 | run: npm ci --no-optional 16 | - name: Code linting 17 | run: npm run lint 18 | - name: Run tests 19 | run: npm test 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | dw.js/dw-2.0.js 64 | dist/main.js 65 | dist/embed.js 66 | dist/Visualization_SSR.js 67 | dist/dw-2.0.min.js 68 | dist/locale 69 | dist/dw-2.0.cjs.js 70 | token.json 71 | 72 | # Source maps 73 | *.js.map 74 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | vendor 2 | dist 3 | dw.js 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Datawrapper 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chart-core 2 | 3 | **`@datawrapper/chart-core`** is a collection of useful functions and components that are required to render Datawrapper charts. 4 | 5 | ## Installation 6 | 7 | ```sh 8 | > npm i @datawrapper/chart-core 9 | ``` 10 | 11 | ## Structure 12 | 13 | ``` 14 | ├── main.mjs 15 | │ - Entry point for rollup to bundle `Visualization.svelte` 16 | │ - (used by datawrapper/api) 17 | │ 18 | ├── lib 19 | │ - Directory of source files like `Visualization.svelte` 20 | │ - (used by datawrapper/frontend) 21 | │ 22 | ├── dist 23 | │ - Files with global dependencies needed for chart rendering 24 | │ - (used by datawrapper/{api,frontend}) 25 | │ 26 | └── vendor 27 | - Source vendor files that are copied into dist when package is published 28 | ``` 29 | 30 | Above are the interesting files and directories to render charts. Only `lib/` and `dist/` get packaged and published with `npm`. 31 | 32 | ## API reference 33 | 34 | * [Chart](docs/chart.md) ⇒ class 35 | * [Column](docs/column.md) ⇒ class 36 | * [Dataset](docs/dataset.md) ⇒ class 37 | 38 | ## Development 39 | 40 | When changing core functionality it is advised to link a local copy of `@datawrapper/chart-core` in the `datawrapper/api` or `datawrapper/frontend` repositories. Follow these steps to link the package: 41 | 42 | ```sh 43 | ~/code/chart-core 44 | ❯ npm link 45 | 46 | ~/code/frontend 47 | ❯ npm link @datawrapper/chart-core 48 | ``` 49 | 50 | Everytime `npm install` is called after that, the link is removed. Usually it is enough to run the second step again. 51 | 52 | ## Publishing 53 | 54 | To publish this package run `npm version {major|minor|patch}` and `npm publish`. To publish you have to be part of the Datawrapper organization on npm. 55 | -------------------------------------------------------------------------------- /dist/load-polyfills.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";function e(e){return function(t){var r=t.toLowerCase().match(e);return!!r&&parseInt(r[1],10)}}var t={chrome:e(/chrom(?:e|ium)\/([0-9]+)\./),firefox:e(/firefox\/([0-9]+\.*[0-9]*)/),safari:e(/version\/([0-9]+).[0-9]+.[0-9]+ safari/),ie:e(/(?:msie |rv:)([0-9]+).[0-9]+/),edge:e(/edge\/([0-9]+).[0-9]+.[0-9]+/)},r={firefox:[50,74],chrome:[50,80],ie:[6,11],edge:[12,80],safari:[9,13]};var i=function(){var e=navigator.userAgent,r="undefined"!=typeof InstallTrigger,i=/constructor/i.test(window.HTMLElement)||"[object SafariRemoteNotification]"===(!window.safari||window.safari.pushNotification).toString(),o=!!document.documentMode,n=!o&&!!window.StyleMedia,s=/HeadlessChrome/.test(e)||!!window.chrome&&!!window.chrome.loadTimes,a=/; wv/.test(e)&&/Chrome/.test(e),c=/SAMSUNG/.test(e)&&/Chrome/.test(e),f=s||a||c?"chrome":r?"firefox":i?"safari":o?"ie":!!n&&"edge";return{browser:f,version:!(!f||!t[f])&&t[f](e)}}(),o=i.browser,n=i.version,s=window.__DW_SVELTE_PROPS__.polyfillUri;o&&r[o]&&n>=r[o][0]?n<=r[o][1]&&document.write(' 6 | 7 | {#if block.prepend} 8 | 9 | {@html clean(block.prepend)} 10 | 11 | {/if} 12 | 13 | 14 | 15 | {#if block.append} 16 | 17 | {@html clean(block.append)} 18 | 19 | {/if} 20 | -------------------------------------------------------------------------------- /lib/BlocksRegion.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | {#if blocks.length} 10 |
11 | {#each blocks as block} 12 | {#if block.tag === 'h1'} 13 |

14 | 15 |

16 | {:else if block.tag === 'p'} 17 |

18 | 19 |

20 | {:else} 21 |
24 | 25 |
26 | {/if} 27 | {/each} 28 |
29 | {/if} 30 | -------------------------------------------------------------------------------- /lib/Menu.svelte: -------------------------------------------------------------------------------- 1 | 19 | 20 | 79 | 80 | 81 | 82 | {#if blocks.length} 83 |