{"id":13517789,"url":"https://github.com/fnando/sparkline","last_synced_at":"2025-04-08T13:07:28.085Z","repository":{"id":39617991,"uuid":"111340868","full_name":"fnando/sparkline","owner":"fnando","description":"Generate SVG sparklines with JavaScript without any external dependency.","archived":false,"fork":false,"pushed_at":"2023-10-17T16:23:47.000Z","size":570,"stargazers_count":537,"open_issues_count":14,"forks_count":60,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-01T11:05:59.033Z","etag":null,"topics":["javascript","lightweight","sparkline","sparklines"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["fnando"],"custom":["https://www.buymeacoffee.com/fnando"]}},"created_at":"2017-11-19T23:32:07.000Z","updated_at":"2025-03-22T11:09:09.000Z","dependencies_parsed_at":"2024-01-13T19:27:14.759Z","dependency_job_id":"0a9887f8-3122-455c-a10b-c1f389e8aba3","html_url":"https://github.com/fnando/sparkline","commit_stats":{"total_commits":49,"total_committers":4,"mean_commits":12.25,"dds":"0.12244897959183676","last_synced_commit":"3008997512faff401da2c6a953fa600cd87de90b"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsparkline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsparkline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsparkline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fsparkline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/sparkline/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847610,"owners_count":21006100,"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":["javascript","lightweight","sparkline","sparklines"],"created_at":"2024-08-01T05:01:37.383Z","updated_at":"2025-04-08T13:07:28.059Z","avatar_url":"https://github.com/fnando.png","language":"JavaScript","readme":"# sparkline\n\n[![NPM package version](https://img.shields.io/npm/v/@fnando/sparkline.svg)](https://www.npmjs.com/package/@fnando/sparkline)\n![License: MIT](https://img.shields.io/npm/l/@fnando/sparkline.svg)\n![Minified size](http://img.badgesize.io/fnando/sparkline/main/dist/sparkline.min.js.svg?label=min+size)\n![Minified+Gzip size](http://img.badgesize.io/fnando/sparkline/main/dist/sparkline.min.js.svg?compression=gzip\u0026label=min%2Bgzip+size)\n\nGenerate SVG sparklines with JavaScript without any external dependency.\n\n## Instalation\n\nThis lib is available as a NPM package. To install it, use the following command:\n\n```\nnpm install @fnando/sparkline --save\n```\n\nIf you're using Yarn (and you should):\n\n```\nyarn add @fnando/sparkline\n```\n\nYou'll have to call `sparkline.sparkline(svg, values, options)` directly if you're loading the script without compiling your script (e.g. [webpack](https://webpack.js.org/)). Otherwise you can simply `import sparkline from \"@fnando/sparkline\";`.\n\n## API\n\n### `sparkline(svg, values, options = {})`\n\n- `svg`: This is a `\u003csvg\u003e` reference that must contain three required attributes (`width`, `height`, and `stroke-width`). These attributes are used to calculate the drawing area.\n- `values`: You can either provide an array of numbers or an array of objects that respond to `.value`. If you have a different data structure, see `options.fetch`.\n- `options`: This optional argument allows you to further customize the sparkline. The available options are:\n    - `fetch`: Use this function to return the value if you have a different data structure that's not natively supported by sparkline.\n    - `onmousemove`: By setting this callback function, you'll enable the interactive mode (unless you set `options.interactive` to `false`). The callback signature is `callback(event, datapoint)`, where `datapoint` is an object containing the value, x/y coordinates, and the item index.\n    - `onmouseout`: This callback function is called every time the mouse leaves the SVG area. You can use it to hide things like tooltips.\n    - `spotRadius`: Set the spot radius. The default is `2`.\n    - `cursorWidth`: Set the cursor width. The default is `2`.\n    - `interactive`: When `true`, this enables the interactive mode. You don't have to set this option if you're providing a `onmousemove` callback.\n\n## Usage\n\nThis is the minimum working example:\n\n```html\n\u003c!-- width, height and stroke-width attributes must be defined on the target SVG --\u003e\n\u003csvg class=\"sparkline\" width=\"100\" height=\"30\" stroke-width=\"3\"\u003e\u003c/svg\u003e\n\n\u003cscript\u003e\n  sparkline(document.querySelector(\".sparkline\"), [1, 5, 2, 4, 8, 3, 7]);\n\u003c/script\u003e\n```\n\nYou can change the colors by either setting the attributes directly to the SVG element or using CSS, like the following:\n\n```css\n/* just the line */\n.sparkline {\n  stroke: red;\n  fill: none;\n}\n\n/* line with highlight area */\n.sparkline {\n  stroke: red;\n  fill: rgba(255, 0, 0, .3);\n}\n\n/* change the spot color */\n.sparkline--spot {\n  stroke: blue;\n  fill: blue;\n}\n\n/* change the cursor color */\n.sparkline--cursor {\n  stroke: orange;\n}\n\n/* style fill area and line colors using specific class name */\n.sparkline--fill {\n  fill: rgba(255, 0, 0, .3);\n}\n\n.sparkline--line {\n  stroke: red;\n}\n```\n\n## Examples\n\n### Static\n\nAvailable at https://codepen.io/fnando/full/KyZLLV/\n\n[![](https://github.com/fnando/sparkline/blob/main/sparkline.gif?raw=true)](https://codepen.io/fnando/full/KyZLLV/)\n\n### Interactive\n\nAvailable at https://codepen.io/fnando/full/GOQLVE/\n\n[![](https://github.com/fnando/sparkline/blob/main/sparkline-interactive.gif?raw=true)](https://codepen.io/fnando/full/GOQLVE)\n\n## License\n\n(The MIT License)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":["https://github.com/sponsors/fnando","https://www.buymeacoffee.com/fnando"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fsparkline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fsparkline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fsparkline/lists"}