@icgcat/chart 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +104 -89
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,128 +1,143 @@
1
- # Accordion Component for Svelte
1
+ <div style="text-align:center">
2
+ <p>
3
+ <img src="https://eines.icgc.cat/recursos/logos/icgc_logo_color.png" alt="ICGC Logo" width="250px">
4
+ </p>
5
+ </div>
2
6
 
3
- ## Introduction
4
- This Svelte package provides two components for creating collapsible sections: `Accordion` and `SubAccordion`. These components are accessible, customizable, and lightweight, with built-in animations and rich styling options. Perfect for displaying nested or standalone collapsible content sections in a clean and interactive manner.
7
+ <div style="text-align:center">
8
+
9
+ [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg?style=flat)](LICENSE.txt)
10
+ [![Version](https://img.shields.io/npm/v/@icgcat/chart?style=flat)](https://www.npmjs.com/package/@icgcat/chart)
11
+ [![X](https://img.shields.io/twitter/follow/icgcat?style=social)](https://twitter.com/icgcat)
12
+ <img src="https://eines.icgc.cat/recursos//images/JS-logo.svg" width="20px"/>
13
+ </div>
14
+
15
+ # Svelte Chart Component
16
+
17
+ This npm package provides a reusable chart component using the `Chart.js` library. It is designed to work seamlessly with Svelte applications and supports various chart types.
5
18
 
6
19
  ---
7
20
 
8
21
  ## Installation
9
22
 
10
- To clone the package:
23
+ Install the package using npm:
11
24
 
12
25
  ```bash
13
- git clone git@autogitlab.icgc.local:geostarters/components/accordion.git
26
+ npm install @icgcat/chart
14
27
  ```
15
28
 
16
- To install the package, use npm or yarn:
17
-
18
- ```bash
19
- npm install @icgcat/accordion
20
- ```
29
+ The package automatically includes the required Chart.js dependency, so there is no need for additional installations.
21
30
 
22
31
  ---
23
32
 
24
- ## Usage
25
-
26
- ### Import and Basic Example
27
- Here's how to use the `Accordion` and `SubAccordion` components in your Svelte application:
33
+ ## Features
28
34
 
29
- ```svelte
30
- <script>
31
- import { Accordion, SubAccordion } from "@icgcat/accordion";
35
+ - **Chart Types**: Supports bar, line, pie, and other chart types supported by Chart.js.
36
+ - **Customizable**: Easily configure labels, datasets, and chart options.
37
+ - **Responsive Design**: Charts adapt to different screen sizes.
38
+ - **Legend Management**: Position and display customization for chart legends.
32
39
 
33
- let openedAccordion = 0; // Track the currently opened accordion
40
+ ---
34
41
 
35
- const toggleAccordion = (id) => {
36
- openedAccordion = openedAccordion === id ? 0 : id;
37
- };
38
- </script>
42
+ ## Props
39
43
 
40
- <Accordion
41
- id={1}
42
- openedAccordion={openedAccordion}
43
- title="First Section"
44
- iconTheme = "share"
45
- onToggle={toggleAccordion}
46
- component={() => <p>Content for the first section</p>}
47
- />
48
-
49
- <Accordion
50
- id={2}
51
- openedAccordion={openedAccordion}
52
- title="Second Section"
53
- iconTheme = "map"
54
- onToggle={toggleAccordion}
55
- >
56
- <SubAccordion
57
- id={3}
58
- openedAccordion={openedAccordion}
59
- title="Nested Section"
60
- onToggle={toggleAccordion}
61
- >
62
- <p>Content for the nested section</p>
63
- </SubAccordion>
64
- </Accordion>
44
+ ### Configurable Properties
45
+
46
+ - **`chartData`**: (Required) Configuration object for the chart. This includes:
47
+ - `type`: Type of the chart (e.g., `bar`, `line`, `pie`).
48
+ - `data`: Chart data, including `labels` and `datasets`.
49
+ - `options`: Additional Chart.js options for customization.
50
+
51
+ #### Example `chartData` Object
52
+
53
+ ```javascript
54
+ {
55
+ type: "bar",
56
+ data: {
57
+ labels: ["January", "February", "March"],
58
+ datasets: [
59
+ {
60
+ label: "Sample Data",
61
+ data: [10, 20, 30],
62
+ backgroundColor: "rgba(255, 99, 132, 0.2)",
63
+ borderColor: "rgba(255, 99, 132, 1)",
64
+ borderWidth: 1,
65
+ },
66
+ ],
67
+ },
68
+ options: {
69
+ responsive: true,
70
+ plugins: {
71
+ legend: {
72
+ display: true,
73
+ position: "top",
74
+ },
75
+ },
76
+ },
77
+ }
65
78
  ```
66
79
 
67
80
  ---
68
81
 
69
- ## Props
70
- ### Accordion
71
- The `Accordion` component accepts the following props:
72
-
73
- | Prop | Type | Default | Description |
74
- |-------------------|----------|------------------------|-----------------------------------------------|
75
- | `id` | `number` | `0` | Unique identifier for each accordion. |
76
- | `openedAccordion` | `number` | `0` | Tracks the currently opened accordion. |
77
- | `title` | `string` | `""` | The title displayed in the accordion header. |
78
- | `className` | `string` | `"acc"` | Custom CSS class for styling. |
79
- | `iconTheme` | `string` | `"keyboard_arrow_down"` | Icon displayed in the accordion header. |
80
- | `component` | `any` | `null` | Content rendered inside the accordion body. |
81
- | `onToggle` | `function` | `null` | Callback triggered when the accordion is toggled. |
82
- | `openColor` | `string` | `"#FFE448"` | Background color when the accordion is open. |
83
- | `backgroundColor` | `string` | `"#F5F5F5"` | Default background color. |
84
- | `hoverColor` | `string` | `"rgb(173, 173, 173)"`| Background color on hover. |
85
- | `activeColorStyle`| `string` | `"rgb(173, 173, 173)"`| Background color on active state. |
86
- | `fontColor` | `string` | `"black"` | Font color for the accordion header. |
87
- | `children` | `function` | `null` | Content passed dynamically to the accordion body. |
88
-
89
- ### SubAccordion
90
- The `SubAccordion` component accepts the same props as `Accordion`, with the exception of `component`. Instead, it expects content to be passed as `children`.
82
+ ## Usage Example
83
+
84
+ ```svelte
85
+ <script>
86
+ import Chart from '@icgcat/chart';
87
+
88
+ const chartData = {
89
+ type: "line",
90
+ data: {
91
+ labels: ["January", "February", "March"],
92
+ datasets: [
93
+ {
94
+ label: "Monthly Sales",
95
+ data: [50, 75, 100],
96
+ backgroundColor: "rgba(54, 162, 235, 0.2)",
97
+ borderColor: "rgba(54, 162, 235, 1)",
98
+ borderWidth: 2,
99
+ },
100
+ ],
101
+ },
102
+ options: {
103
+ responsive: true,
104
+ plugins: {
105
+ legend: {
106
+ display: true,
107
+ position: "bottom",
108
+ },
109
+ },
110
+ },
111
+ };
112
+ </script>
113
+
114
+ <ChartComponent {chartData} />
115
+ ```
91
116
 
92
117
  ---
93
118
 
94
119
  ## Styling
95
- The components come with default styles, but you can override them using custom CSS. For example:
96
120
 
97
- ```css
98
- .acc {
99
- border-radius: 8px;
100
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
101
- }
121
+ The component comes with minimal styling for the canvas element. Customize it as needed:
102
122
 
103
- .collapsible-header {
104
- transition: background-color 0.3s ease;
123
+ ```css
124
+ canvas {
125
+ max-width: 100%;
126
+ margin: 20px 0;
105
127
  }
106
128
  ```
107
129
 
108
130
  ---
109
131
 
110
- ## Transitions
111
- These components use Svelte's `slide` transition for smooth opening and closing animations. You can modify or replace the transition if desired.
132
+ ## Dependencies
112
133
 
113
- ---
134
+ - `chart.js`
114
135
 
115
- ## Accessibility
116
- - Fully keyboard-navigable.
117
- - Supports dynamic aria-expanded attributes for screen readers.
118
-
119
- ---
120
-
121
- ## Contributions
122
- Feel free to fork this repository and open pull requests to improve the components or add new features.
136
+ This dependency is included automatically when you install the package.
123
137
 
124
138
  ---
125
139
 
126
140
  ## License
127
- This project is licensed under the MIT License.
141
+
142
+ This project is licensed under the [MIT License](LICENSE).
128
143
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgcat/chart",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -23,4 +23,4 @@
23
23
  "dependencies": {
24
24
  "chart.js": "^4.4.7"
25
25
  }
26
- }
26
+ }