{"id":26963987,"url":"https://github.com/spyna/react-svg-radar-chart","last_synced_at":"2025-04-03T06:19:03.295Z","repository":{"id":56511379,"uuid":"141715241","full_name":"Spyna/react-svg-radar-chart","owner":"Spyna","description":"A reusable radar chart in SVG.","archived":false,"fork":false,"pushed_at":"2024-08-28T00:51:42.000Z","size":1053,"stargazers_count":47,"open_issues_count":11,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T06:18:55.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://spyna.github.io/react-svg-radar-chart/","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/Spyna.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-20T13:26:37.000Z","updated_at":"2024-08-12T05:54:36.000Z","dependencies_parsed_at":"2022-08-15T20:10:17.084Z","dependency_job_id":null,"html_url":"https://github.com/Spyna/react-svg-radar-chart","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spyna%2Freact-svg-radar-chart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spyna%2Freact-svg-radar-chart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spyna%2Freact-svg-radar-chart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Spyna%2Freact-svg-radar-chart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Spyna","download_url":"https://codeload.github.com/Spyna/react-svg-radar-chart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246944386,"owners_count":20858772,"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":"2025-04-03T06:19:02.478Z","updated_at":"2025-04-03T06:19:03.282Z","avatar_url":"https://github.com/Spyna.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react-svg-radar-chart\n\n\nGenerate SVG radar charts with React.\n\n[![Build Status](https://travis-ci.org/Spyna/react-svg-radar-chart.svg?branch=master)](https://travis-ci.org/Spyna/react-svg-radar-chart)\n[![Coverage Status](https://coveralls.io/repos/github/Spyna/react-svg-radar-chart/badge.svg?branch=master)](https://coveralls.io/github/Spyna/react-svg-radar-chart?branch=master)\n\n![an example](./demo.gif)\n\nBased on \u003ca href=\"https://github.com/derhuerst/svg-radar-chart\" target=\"_blank\"\u003esvg-radar-chart\u003c/a\u003e.\n\n## Installing\n\n```shell\nnpm install react-svg-radar-chart\n```\n\n## Demo and Examples\n\n### Running demo\n\n could be found here: https://spyna.github.io/react-svg-radar-chart/\n\n### Source code\n\n could be found here: https://github.com/Spyna/react-svg-radar-chart/tree/master/src/demo.\n\n### Run locally\n\n\n\n```shell\ngit clone https://github.com/Spyna/react-svg-radar-chart.git\ncd react-svg-radar-chart \u0026\u0026 npm install;\nnpm start;\n\n```\n\n## Usage\n\n\nImport the `RadarChart` component and the default css file.\n\n```js\nimport RadarChart from 'react-svg-radar-chart';\nimport 'react-svg-radar-chart/build/css/index.css'\n```\n\nCreate the dataset you want to draw\n\n```js\nconst data = [\n      {\n        data: {\n          battery: 0.7,\n          design: .8,\n          useful: 0.9,\n          speed: 0.67,\n          weight: 0.8\n        },\n        meta: { color: 'blue' }\n      },\n      {\n        data: {\n          battery: 0.6,\n          design: .85,\n          useful: 0.5,\n          speed: 0.6,\n          weight: 0.7\n        },\n        meta: { color: 'red' }\n      }\n    ];\n\nconst captions = {\n      // columns\n      battery: 'Battery Capacity',\n      design: 'Design',\n      useful: 'Usefulness',\n      speed: 'Speed',\n      weight: 'Weight'\n    };\n\n```\n\nUse the component:\n\n```js\n\u003cRadarChart\n    captions={captions}\n    data={data}\n    size={450}\n  /\u003e\n\n```\n\nWhere:\n\n * `captions` are the names that will be drawn on the svg.\n * `data` are the data that will be displayed.\n * `size` is the size of the svg in *pixels*\n\nPutting all togheter\n\n```js\nimport React from 'react';\n\nimport RadarChart from 'react-svg-radar-chart';\nimport 'react-svg-radar-chart/build/css/index.css'\n\nclass App extends React.Component {\n  render() {\n \t const data = [\n      {\n        data: {\n          battery: 0.7,\n          design: .8,\n          useful: 0.9,\n          speed: 0.67,\n          weight: 0.8\n        },\n        meta: { color: 'blue' }\n      },\n      {\n        data: {\n          battery: 0.6,\n          design: .85,\n          useful: 0.5,\n          speed: 0.6,\n          weight: 0.7\n        },\n        meta: { color: 'red' }\n      }\n    ];\n\n\tconst captions = {\n      // columns\n      battery: 'Battery Capacity',\n      design: 'Design',\n      useful: 'Usefulness',\n      speed: 'Speed',\n      weight: 'Weight'\n    };\n\n    return (\n      \u003cdiv\u003e\n        \u003cRadarChart\n            captions={{\n              // columns\n              battery: 'Battery Capacity',\n              design: 'Design',\n              useful: 'Usefulness',\n              speed: 'Speed',\n              weight: 'Weight'\n            }}\n            data={[\n              // data\n              {\n                data: {\n                  battery: 0.7,\n                  design: .8,\n                  useful: 0.9,\n                  speed: 0.67,\n                  weight: 0.8\n                },\n                meta: { color: '#58FCEC' }\n              },\n            ]}\n            size={400}\n          /\u003e\n        \u003c/div\u003e\n    );\n  }\n}\n\nexport default App;\n\n```\n\n## Props\n\n\n| Property | meaning | mandatory |\n| --- | --- | --- |\n| captions | *object* the label on the chart | **yes** |\n| data | *array* the data to display | **yes** |\n| options | *object* custom options for the chart, see below | no |\n| size | *number* custom size, the default is 300 | no |\n\n\n## Data format\n\nthe `data` property must be an array of object composed as following:\n\n```js\nconst dataset1 = {\n data : {property1 : value1 , property2: value2, ..., propertyN: valueN},\n meta : { color: 'green'}\n}\nconst data = [dataset1, dataset2, ..., datasetN]\n\n```\nThe `dataset` object must have:\n * a property named `data`: an object with the data to display: `battery: 0.7`. The name of each property must be found in the `captions` object.\n * a property named `meta`: an object with a `color` or `class` property to set the color or the class in the chart.\n\n\n## Options, styles and defaults.\n\nYou can:\n\n* Customize the color of the chart.\n* Use your own *stylesheet* to customize the style of the radar chart.\n* Pass some *options* to the `RadarChart` component.\n\n\n ### Customize the color of the chart\n\n When generating the `data` object you can use a `meta` property to set the *color* and the *class* of the shape.\n\n ```js\nconst dataset1 = {\n data : {...},\n meta : { color: 'green'}\n};\nconst dataset2 = {\n data : {...},\n meta : { class: 'my-custom-class'}\n};\n```\n### Use your own *stylesheet* to customize the style of the radar chart.\n\nIn the demo the `'react-svg-radar-chart/build/css/index.css'` is imported, but you can define you own if needed.\n\nIf you want to use a custom stylesheet you have to implement these classes:\n\n * `.shape`: the shape on the radar chart. The deafult is: `fill-opacity: .3;`.\n\n* `.shape:hover` : if you want some *hover* effects. The default is:  `fill-opacity: .65;z-index: 100;`.\n\n* `.scale`: the *circles* in the radar chart. The default is: `fill: #FAFAFA; stroke: #999;stroke-width: .2`.\n\n* `.axis`: the axis of the chart. The default is: `stroke: #555;\tstroke-width: .2`.\n\n* `.caption`: the text on the chart. The default is: `fill: #444;\tfont-weight: 400;\ttext-shadow: 1px 1px 0 #fff`.\n\n### Pass some *options* to the `RadarChart` component\n\nThe `RadarChart` component accepts a property named **options**. The default options are:\n\n```js\nconst noSmoothing = points =\u003e {\n  let d = 'M' + points[0][0].toFixed(4) + ',' + points[0][1].toFixed(4);\n  for (let i = 1; i \u003c points.length; i++) {\n    d += 'L' + points[i][0].toFixed(4) + ',' + points[i][1].toFixed(4);\n  }\n  return d + 'z';\n};\n\nconst defaultOptions = {\n  size: 200,\n  axes: true, // show axes?\n  scales: 3, // show scale circles?\n  captions: true, // show captions?\n  captionMargin: 10,\n  dots: false, // show dots?\n  zoomDistance: 1.2, // where on the axes are the captions?\n  setViewBox: (options) =\u003e `-${options.captionMargin} 0 ${options.size + options.captionMargin * 2} ${options.size}`, // custom viewBox ?\n  smoothing: noSmoothing, // shape smoothing function\n  axisProps: () =\u003e ({ className: 'axis' }),\n  scaleProps: () =\u003e ({ className: 'scale', fill: 'none' }),\n  shapeProps: () =\u003e ({ className: 'shape' }),\n  captionProps: () =\u003e ({\n    className: 'caption',\n    textAnchor: 'middle',\n    fontSize: 10,\n    fontFamily: 'sans-serif'\n  }),\n  dotProps: () =\u003e ({\n    className: 'dot',\n    mouseEnter: (dot) =\u003e { console.log(dot) },\n    mouseLeave: (dot) =\u003e { console.log(dot) }\n  }),\n  rotation: 0,\n  wrapCaptionAt: 15,\n  captionLineHeight: 20,\n};\n```\n\n| Property | meaning |\n| --- | --- |\n| size | the size in pixels of the svg chart, default is 300, can use only if `size` props is not used |\n| axes | *true*/*false* show axes |\n| scales | *number* how many scale circles |\n| captions | *true*/*false* show captions |\n| captionMargin | *number* The margin of the svg, to fit captions |\n| dots | *true*/*false* show dots |\n| zoomDistance | the distance of the zoom: 0.2 = closest |\n| smoothing | the smoothing function |\n| setViewBox | a function that take *options*' object as argument and returns viewBox as a string. ViewBox will be added to the *svg*|\n| axisProps | a function that take the *current caption name* as arguments and returns an object. All the property will be added to the *axis svg component*|\n| scaleProps | a function that take the *value of the scales* as arguments and returns an object. All the property will be added to the *scale svg component*|\n| shapeProps | a function that take the *meta of the data* as arguments and returns an object. All the property will be added to the *shape svg component*|\n| captionProps |  a function that take the *current caption name* as arguments and returns an object. All the property will be added to the *text svg component*|\n| dotProps |  a function that takes the *dot svg component* as arguments and returns an object. All properties will be added to the *dot svg component*. The `mouseEnter` function returns useful information like `key`, `value` and the index of the shape the dot is associated with. See the demo as example for using the information as a tooltip|\n| rotation | default `0`: The rotation (clockwise) in degrees. A number that indicates the rotation of the shape and captions. It must be beetween 0 and 360. Eg: `180` makes the chart upside down. `90` rotates the chart of 90 degrees. |\n| wrapCaptionAt | default `15`: The max length of the caption before it is wrapped in a new line |\n| captionLineHeight | default `20`: The height of the line of a caption when it is wrapped in a new line |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyna%2Freact-svg-radar-chart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspyna%2Freact-svg-radar-chart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyna%2Freact-svg-radar-chart/lists"}