{"id":16927793,"url":"https://github.com/pearmini/g2-ssr-node","last_synced_at":"2026-01-10T19:30:15.005Z","repository":{"id":208792127,"uuid":"722484695","full_name":"pearmini/g2-ssr-node","owner":"pearmini","description":"The tool for G2 spec's SSR(Server-Side Rendering) in Node.js.","archived":false,"fork":false,"pushed_at":"2024-07-11T12:53:11.000Z","size":423,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-04T02:12:19.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pearmini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-23T08:51:59.000Z","updated_at":"2024-07-11T12:52:15.000Z","dependencies_parsed_at":"2023-11-28T04:44:01.395Z","dependency_job_id":null,"html_url":"https://github.com/pearmini/g2-ssr-node","commit_stats":null,"previous_names":["pearmini/g2-ssr-node"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pearmini%2Fg2-ssr-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pearmini%2Fg2-ssr-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pearmini%2Fg2-ssr-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pearmini%2Fg2-ssr-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pearmini","download_url":"https://codeload.github.com/pearmini/g2-ssr-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239745953,"owners_count":19689954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T20:35:08.056Z","updated_at":"2026-01-10T19:30:14.920Z","avatar_url":"https://github.com/pearmini.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @berryv/g2-ssr-node\n\nThe tool for G2 spec's SSR(Server-Side Rendering) in Node.js.\n\n## Installing\n\nInstall via a package manager such as Yarn or NPM.\n\n```bash\n$ npm install @berryv/g2-ssr-node\n```\n\nUse CLI to convert a G2 specification file named in `bar.json` into a png file named `bar.png`.\n\n```bash\n$ g2-ssr-node g2png -i ./bar.json -o bar.png\n```\n\nIn Node, use `render` to convert a G2 specification into a png file named `bar.png`.\n\n```js\nconst fs = require(\"fs\");\nconst { render } = require(\"@berry/g2-ssr-node\");\n\nconst spec = {\n  type: \"interval\",\n  data: [\n    { genre: \"Sports\", sold: 275 },\n    { genre: \"Strategy\", sold: 115 },\n    { genre: \"Action\", sold: 120 },\n    { genre: \"Shooter\", sold: 350 },\n    { genre: \"Other\", sold: 150 },\n  ],\n  encode: { x: \"genre\", y: \"sold\", color: \"genre\" },\n};\n\nrender(spec).then((canvas) =\u003e {\n  const out = fs.createWriteStream(\"./bar.png\");\n  const stream = canvas.createJPEGStream();\n  stream.pipe(out);\n  stream.on(\"finish\", () =\u003e console.log(\"Convert successfully!\"));\n});\n```\n\n## Development\n\n```bash\n$ npm i\n$ npm link\n$ npm run build\n$ npm run test:png\n```\n\n## API Reference\n\n- [CLI](#cli) - Convert spec in command line.\n- [Node](#node) - Convert spec in Node.js.\n\n### CLI\n\n\u003ca name=\"cli-g2png\" href=\"#cli-g2png\"\u003e#\u003c/a\u003e subcommand.**g2png**\n\n```txt\nUsage: g2-ssr-node g2png [options]\n\nConvert a G2 spec to an PNG image\n\nOptions:\n  -i, --input \u003cfilename\u003e   filename for the input spec\n  -o, --output \u003cfilename\u003e  filename for the output image\n  -h, --help               display help for command\n```\n\nFor example, convert a G2 specification file named in `bar.json` into a png file named `bar.png`:\n\n```bash\n$ g2-ssr-node g2png -i ./bar.json -o bar.png\n```\n\n\u003ca name=\"cli-g2jpeg\" href=\"#cli-g2jpeg\"\u003e#\u003c/a\u003e subcommand.**g2jpeg**\n\n```txt\nUsage: g2-ssr-node g2pdf [options]\n\nConvert a G2 spec to a PDF\n\nOptions:\n  -i, --input \u003cfilename\u003e   filename for the input spec\n  -o, --output \u003cfilename\u003e  filename for the output pdf\n  -h, --help               display help for command\n```\n\nFor example, convert a G2 specification file named in `bar.json` into a png file named `bar.jpeg`:\n\n```bash\n$ g2-ssr-node g2jpeg -i ./bar.json -o bar.jpeg\n```\n\n\u003ca name=\"cli-g2pdf\" href=\"#cli-g2pdf\"\u003e#\u003c/a\u003e subcommand.**g2pdf**\n\n```txt\nUsage: g2-ssr-node g2jpeg [options]\n\nConvert a G2 spec to an JPEG image\n\nOptions:\n  -i, --input \u003cfilename\u003e   filename for the input spec\n  -o, --output \u003cfilename\u003e  filename for the output image\n  -h, --help               display help for command\n```\n\nFor example, convert a G2 specification file named in `bar.json` into a png file named `bar.pdf`:\n\n```bash\n$ g2-ssr-node g2pdf -i ./bar.json -o bar.pdf\n```\n\n### Node\n\n\u003ca name=\"node-renderImage\" href=\"#node-renderImage\"\u003e#\u003c/a\u003e node.**renderImage(_options_)**\n\nRenders a G2 specification into a image canvas in [node-canvas](https://github.com/Automattic/node-canvas) resolved by a promise. Then creates a stream from the returned canvas and write into a file, supporting the following stream types:\n\n- [canvas.createPNGStream](https://github.com/Automattic/node-canvas#canvascreatepngstream)\n- [canvas.createJPEGStream](https://github.com/Automattic/node-canvas#canvascreatejpegstream)\n\nFor example, convert a G2 specification into a png file named `bar.png`.\n\n```js\nconst fs = require(\"fs\");\nconst { render } = require(\"@berry/g2-ssr-node\");\n\nconst spec = {\n  type: \"interval\",\n  data: [\n    { genre: \"Sports\", sold: 275 },\n    { genre: \"Strategy\", sold: 115 },\n    { genre: \"Action\", sold: 120 },\n    { genre: \"Shooter\", sold: 350 },\n    { genre: \"Other\", sold: 150 },\n  ],\n  encode: { x: \"genre\", y: \"sold\", color: \"genre\" },\n};\n\nrenderImage(spec).then((canvas) =\u003e {\n  const out = fs.createWriteStream(\"./bar.png\");\n  const stream = canvas.createJPEGStream();\n  stream.pipe(out);\n  stream.on(\"finish\", () =\u003e console.log(\"Convert successfully!\"));\n});\n```\n\n\u003ca name=\"node-renderPDF\" href=\"#node-renderPDF\"\u003e#\u003c/a\u003e node.**renderPDF(_options_)**\n\nRenders a G2 specification into a pdf canvas in [node-canvas](https://github.com/Automattic/node-canvas) resolved by a promise. Then creates a pdf stream from the returned canvas and write into a file:\n\n- [canvas.createPDFStream](https://github.com/Automattic/node-canvas#canvascreatepdfstream)\n\nFor example, convert a G2 specification into a png file named `bar.png`.\n\n```js\nconst fs = require(\"fs\");\nconst { render } = require(\"@berry/g2-ssr-node\");\n\nconst spec = {\n  type: \"interval\",\n  data: [\n    { genre: \"Sports\", sold: 275 },\n    { genre: \"Strategy\", sold: 115 },\n    { genre: \"Action\", sold: 120 },\n    { genre: \"Shooter\", sold: 350 },\n    { genre: \"Other\", sold: 150 },\n  ],\n  encode: { x: \"genre\", y: \"sold\", color: \"genre\" },\n};\n\nrenderPDF(spec).then((canvas) =\u003e {\n  const out = fs.createWriteStream(\"./bar.png\");\n  const stream = canvas.createPDFStream();\n  stream.pipe(out);\n  stream.on(\"finish\", () =\u003e console.log(\"Convert successfully!\"));\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpearmini%2Fg2-ssr-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpearmini%2Fg2-ssr-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpearmini%2Fg2-ssr-node/lists"}