├── .gitignore
├── CHANGELOG.md
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── Makefile.toml
├── README.md
├── examples
├── Cargo.toml
├── Makefile.toml
├── demo
│ ├── Cargo.toml
│ ├── Makefile.toml
│ └── src
│ │ ├── input.scss
│ │ └── lib.rs
├── desktop
│ ├── Cargo.toml
│ ├── Makefile.toml
│ ├── index.html
│ ├── src
│ │ ├── input.css
│ │ └── main.rs
│ └── tailwind.config.js
└── web
│ ├── Cargo.toml
│ ├── Makefile.toml
│ ├── index.html
│ ├── src
│ ├── input.css
│ └── main.rs
│ └── tailwind.config.js
├── release.toml
└── src
├── charts
├── bar.rs
├── line.rs
└── pie.rs
├── grid.rs
├── lib.rs
├── types.rs
└── utils.rs
/.gitignore:
--------------------------------------------------------------------------------
1 | debug/
2 | target/
3 | **/dist/
4 |
5 | **/Cargo.lock
6 | **/*.css
7 | **/*.log
8 |
9 | # These are backup files generated by rustfmt
10 | **/*.rs.bk
11 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](http://keepachangelog.com/)
5 | and this project adheres to [Semantic Versioning](http://semver.org/).
6 |
7 |
8 |
9 | ## [Unreleased] - ReleaseDate
10 |
11 | ## [0.1.3] - 2023-11-06
12 |
13 | ### Fixed
14 |
15 | - Updated to Dioxus 0.4.0
16 |
17 | ## [0.1.2] - 2023-06-03
18 |
19 | ### Fixed
20 |
21 | - Updated to Dioxus 0.3.2
22 |
23 | ## [0.1.1] - 2023-02-17
24 |
25 | ### Added
26 |
27 | - This changelog
28 | - Cargo release config
29 | - README instructions
30 |
31 | ### Fixed
32 |
33 | - Updated to Dioxus 0.3.1
34 |
35 | ## 0.1.0 - 2022-12-18
36 |
37 | ### Added
38 |
39 | - Initial commit
40 |
41 |
42 | [Unreleased]: https://github.com/hiltonm/dioxus-charts/compare/v0.1.3...HEAD
43 | [0.1.3]: https://github.com/hiltonm/dioxus-charts/compare/v0.1.2...v0.1.3
44 | [0.1.2]: https://github.com/hiltonm/dioxus-charts/compare/v0.1.1...v0.1.2
45 | [0.1.1]: https://github.com/hiltonm/dioxus-charts/compare/v0.1.0...v0.1.1
46 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "dioxus-charts"
3 | version = "0.3.1"
4 | authors = ["Hilton Medeiros"]
5 | edition = "2021"
6 | description = "Chart components library for Dioxus"
7 | repository = "https://github.com/dioxus-community/dioxus-charts"
8 | license = "MIT OR Apache-2.0"
9 | keywords = ["ui", "gui", "react", "wasm", "dioxus"]
10 | categories = ["wasm", "gui", "web-programming"]
11 |
12 | [dependencies]
13 | log = "0.4"
14 | dioxus = { version = "0.6", default-features = false, features = ["launch", "macro", "html", "signals"] }
15 |
16 | [profile.release]
17 | lto = true
18 |
--------------------------------------------------------------------------------
/LICENSE-APACHE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Hilton Medeiros
4 |
5 | Permission is hereby granted, free of charge, to any
6 | person obtaining a copy of this software and associated
7 | documentation files (the "Software"), to deal in the
8 | Software without restriction, including without
9 | limitation the rights to use, copy, modify, merge,
10 | publish, distribute, sublicense, and/or sell copies of
11 | the Software, and to permit persons to whom the Software
12 | is furnished to do so, subject to the following
13 | conditions:
14 |
15 | The above copyright notice and this permission notice
16 | shall be included in all copies or substantial portions
17 | of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
20 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
23 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
26 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 | DEALINGS IN THE SOFTWARE.
28 |
--------------------------------------------------------------------------------
/Makefile.toml:
--------------------------------------------------------------------------------
1 |
2 | [tasks.format]
3 | install_crate = "rustfmt"
4 | command = "cargo"
5 | args = ["fmt", "--", "--emit=files"]
6 |
7 | [tasks.build]
8 | command = "cargo"
9 | args = ["build"]
10 |
11 | [tasks.lint]
12 | command = "cargo"
13 | args = ["clippy"]
14 |
15 | [tasks.dev]
16 | dependencies = [
17 | "format",
18 | "lint",
19 | "build",
20 | ]
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://discord.gg/sKJSVNSCDJ)
2 |
3 | # dioxus-charts 📊
4 |
5 | A simple chart components library for [Dioxus](https://dioxuslabs.com/).
6 |
7 | This crate provides some basic SVG-based chart components, customizable with
8 | CSS, to be used with the Dioxus GUI library. The
9 | components configuration was designed to be similar to what one would find
10 | in JavaScript chart libraries.
11 |
12 | The components available currently are:
13 |
14 | - `PieChart`: for Pie, Donut and Gauge charts
15 | - `BarChart`: for Bar and Stacked Bar charts, vertical or horizontal
16 | - `LineChart`
17 |
18 | You can check them out at the very simple [demo site](https://hiltonm.github.io/dioxus-charts-demo/)
19 | for now.
20 |
21 | ## Usage
22 |
23 | This crate is [on crates.io](https://crates.io/crates/dioxus-charts) and can be
24 | used by adding `dioxus-charts` to your dependencies in your project's `Cargo.toml`.
25 |
26 | ```toml
27 | [dependencies]
28 | dioxus-charts = "0.3"
29 | ```
30 |
31 | ## Example
32 |
33 | ```rust
34 | use dioxus::prelude::*;
35 | use dioxus_charts::BarChart;
36 |
37 | fn app() -> Element {
38 | rsx!(
39 | BarChart {
40 | padding_top: 30,
41 | padding_left: 70,
42 | padding_right: 50,
43 | padding_bottom: 30,
44 | bar_width: "10%",
45 | horizontal_bars: true,
46 | label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
47 | series: vec![
48 | vec![63.0, 14.4, 8.0, 5.1, 1.8],
49 | ],
50 | labels: vec!["Chrome".into(), "Safari".into(), "IE/Edge".into(), "Firefox".into(), "Opera".into()]
51 | }
52 | )
53 | }
54 | ```
55 |
56 | There is also a couple of examples in the `examples` folder with a `Makefile.toml` that makes it easier
57 | to build them. You need to install cargo-make first to make use of them:
58 |
59 | ```sh
60 | cargo install cargo-make
61 | ```
62 |
63 | You will also need to have [`sass`](https://sass-lang.com/) and [`tailwindcss`](https://tailwindcss.com/)
64 | installed in your system for the make commands to generate the css files.
65 |
66 | Then for the desktop demo, inside the examples folder:
67 |
68 | ```sh
69 | cd examples
70 | cargo make desktop
71 | ```
72 |
73 | The web example was used to generate the [demo site](https://hiltonm.github.io/dioxus-charts-demo/).
74 | To test it out yourself you need to have `trunk` for the dev-server and the rust wasm target installed:
75 |
76 | ```sh
77 | cargo install trunk
78 | rustup target add wasm32-unknown-unknown
79 | ```
80 |
81 | Then build and launch the dev-server inside the examples folder:
82 |
83 | ```sh
84 | cargo make web
85 | ```
86 |
87 | Note: if you get hit by an error when the web example launches, its possible you were blessed by a version
88 | mismatch issue caused by the rustwasm tooling getting out of sync. The simplest fix for that seems to be
89 | to just remove the Cargo.lock file from the `examples/web` folder. Check
90 | [this issue](https://github.com/rustwasm/wasm-bindgen/issues/2776) for more info if that doesn't do it.
91 |
92 | Please check out the [Dioxus reference guide](https://dioxuslabs.com/learn/0.6/reference) for more
93 | information.
94 |
95 | ## License
96 |
97 | Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
98 | [MIT License](LICENSE-MIT) at your option.
99 |
100 | Unless you explicitly state otherwise, any contribution intentionally submitted
101 | for inclusion in Dioxus-Charts by you, as defined in the Apache-2.0 license, shall be
102 | dual licensed as above, without any additional terms or conditions.
103 |
--------------------------------------------------------------------------------
/examples/Cargo.toml:
--------------------------------------------------------------------------------
1 | [workspace]
2 | members = [
3 | "demo",
4 | "web",
5 | "desktop",
6 | ]
7 |
--------------------------------------------------------------------------------
/examples/Makefile.toml:
--------------------------------------------------------------------------------
1 |
2 | [tasks.desktop]
3 | workspace = false
4 | env = { "CARGO_MAKE_WORKSPACE_SKIP_MEMBERS" = ["web"] }
5 | run_task = { name = "dev", fork = true }
6 |
7 | [tasks.web]
8 | workspace = false
9 | env = { "CARGO_MAKE_WORKSPACE_SKIP_MEMBERS" = ["desktop"] }
10 | run_task = { name = "dev", fork = true }
11 |
12 |
--------------------------------------------------------------------------------
/examples/demo/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "charts-demo"
3 | version = "0.1.0"
4 | authors = ["Hilton Medeiros"]
5 | edition = "2021"
6 | description = "A dioxus-charts element demo"
7 | license = "MIT OR Apache-2.0"
8 | publish = false
9 |
10 | [dependencies]
11 | dioxus = { version = "0.6", default-features = false, features = ["launch", "macro", "html"] }
12 | dioxus-charts = { path = "../.." }
13 |
14 |
--------------------------------------------------------------------------------
/examples/demo/Makefile.toml:
--------------------------------------------------------------------------------
1 |
2 | [tasks.format]
3 | install_crate = "rustfmt"
4 | command = "cargo"
5 | args = ["fmt", "--", "--emit=files"]
6 |
7 | [tasks.css]
8 | command = "sass"
9 | args = ["--no-source-map", "src/input.scss", "src/custom.css"]
10 |
11 | [tasks.build]
12 | command = "cargo"
13 | args = ["build"]
14 | dependencies = [
15 | "format",
16 | "css",
17 | ]
18 |
19 | [tasks.dev]
20 | dependencies = [
21 | "format",
22 | "css",
23 | ]
24 |
25 |
--------------------------------------------------------------------------------
/examples/demo/src/input.scss:
--------------------------------------------------------------------------------
1 |
2 | $col1: #8f327b;
3 | $col2: #b33473;
4 | $col3: #d03e65;
5 | $col4: #e55253;
6 | $col5: #f06d3e;
7 | $col6: #f18c27;
8 | $col7: #e8ab0c;
9 | $col8: #d6ca0b;
10 |
11 |
12 | g.dx-series-0 > path { fill: $col1; }
13 | g.dx-series-1 > path { fill: $col2; }
14 | g.dx-series-2 > path { fill: $col3; }
15 | g.dx-series-3 > path { fill: $col4; }
16 | g.dx-series-4 > path { fill: $col5; }
17 | g.dx-series-5 > path { fill: $col6; }
18 | g.dx-series-6 > path { fill: $col7; }
19 | g.dx-series-7 > path { fill: $col8; }
20 |
21 | g.dx-bar-group-0 > line { stroke: $col1; }
22 | g.dx-bar-group-1 > line { stroke: $col2; }
23 | g.dx-bar-group-2 > line { stroke: $col3; }
24 | g.dx-bar-group-3 > line { stroke: $col4; }
25 | g.dx-bar-group-4 > line { stroke: $col5; }
26 | g.dx-bar-group-5 > line { stroke: $col6; }
27 | g.dx-bar-group-6 > line { stroke: $col7; }
28 | g.dx-bar-group-7 > line { stroke: $col8; }
29 |
30 | g.dx-line-0 > line, g.dx-line-0 > path { stroke: $col1; }
31 | g.dx-line-1 > line, g.dx-line-1 > path { stroke: $col2; }
32 | g.dx-line-2 > line, g.dx-line-2 > path { stroke: $col3; }
33 | g.dx-line-3 > line, g.dx-line-3 > path { stroke: $col4; }
34 | g.dx-line-4 > line, g.dx-line-4 > path { stroke: $col5; }
35 | g.dx-line-5 > line, g.dx-line-5 > path { stroke: $col6; }
36 | g.dx-line-6 > line, g.dx-line-6 > path { stroke: $col7; }
37 | g.dx-line-7 > line, g.dx-line-7 > path { stroke: $col8; }
38 |
39 |
--------------------------------------------------------------------------------
/examples/demo/src/lib.rs:
--------------------------------------------------------------------------------
1 | use dioxus::prelude::*;
2 |
3 | use dioxus_charts::charts::pie::LabelPosition;
4 | use dioxus_charts::{BarChart, LineChart, PieChart};
5 |
6 | pub fn demo_element() -> Element {
7 | rsx! {
8 | style {
9 | {include_str!("./custom.css")},
10 | },
11 | div {
12 | class: "bg-gray-600",
13 | div {
14 | class: "mx-auto max-w-2xl py-8 px-4 sm:py-10 sm:px-6 lg:max-w-7xl lg:px-8 space-y-4",
15 | h2 {
16 | class: "text-2xl font-bold tracking-tight text-gray-200",
17 | "Examples"
18 | }
19 |
20 | div {
21 | class: "grid grid-cols-1 gap-y-12 gap-x-6 sm:grid-cols-2 lg:grid-cols-3 xl:gap-x-8",
22 |
23 | div {
24 | class: "inline-grid grid-cols-1 gap-y-2",
25 | div {
26 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
27 | BarChart {
28 | padding_top: 30,
29 | padding_left: 70,
30 | padding_right: 50,
31 | padding_bottom: 30,
32 | bar_width: "10%",
33 | horizontal_bars: true,
34 | label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
35 | series: vec![
36 | vec![63.0, 14.4, 8.0, 5.1, 1.8],
37 | ],
38 | labels: vec!["Chrome".into(), "Safari".into(), "IE/Edge".into(), "Firefox".into(), "Opera".into()]
39 | }
40 | }
41 | h3 {
42 | class: "truncate tracking-tight text-sm text-gray-200",
43 | "Global desktop browser market share for 2022"
44 | }
45 | }
46 |
47 | div {
48 | class: "inline-grid grid-cols-1 gap-y-2",
49 | div {
50 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
51 | BarChart {
52 | padding_top: 30,
53 | padding_left: 80,
54 | padding_right: 60,
55 | padding_bottom: 30,
56 | bar_distance: 25.0,
57 | horizontal_bars: true,
58 | label_size: 70,
59 | label_interpolation: (|v| format!("${v:.0}B")) as fn(f32) -> String,
60 | series: vec![
61 | vec![2901.0, 2522.0, 1917.0, 1691.0, 1061.0],
62 | vec![2307.0, 1640.0, 1125.0, 939.8, 668.8],
63 | ],
64 | labels: vec!["Apple".into(), "Microsoft".into(), "Alphabet".into(), "Amazon".into(), "Tesla".into()],
65 | }
66 | }
67 | h3 {
68 | class: "truncate tracking-tight text-sm text-gray-200",
69 | "Market value of top tech companies [Jan-Nov 2022]"
70 | }
71 | }
72 |
73 | div {
74 | class: "inline-grid grid-cols-1 gap-y-2",
75 | div {
76 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
77 | BarChart {
78 | padding_top: 30,
79 | padding_left: 50,
80 | padding_right: 30,
81 | padding_bottom: 40,
82 | bar_width: "3.5%",
83 | bar_distance: 20.0,
84 | show_series_labels: false,
85 | label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
86 | label_size: 70,
87 | series: vec![
88 | vec![11.3, 4.3, 2.6, 1.7, 0.3],
89 | vec![13.7, 6.1, 4.1, 2.3, 0.7],
90 | vec![15.3, 6.9, 4.8, 3.2, 0.9],
91 | ],
92 | labels: vec!["Asia".into(), "Western Europe".into(), "USA".into(), "Eastern Europe".into(), "Latin America".into()],
93 | }
94 | }
95 | h3 {
96 | class: "truncate tracking-tight text-sm text-gray-200",
97 | "Ecommerce share of FMCG value, 2019-2021"
98 | }
99 | }
100 |
101 | div {
102 | class: "inline-grid grid-cols-1 gap-y-2",
103 | div {
104 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
105 | BarChart {
106 | padding_top: 30,
107 | padding_left: 40,
108 | padding_right: 30,
109 | padding_bottom: 30,
110 | label_interpolation: (|v| format!("${v}")) as fn(f32) -> String,
111 | show_series_labels: false,
112 | stacked_bars: true,
113 | series: vec![
114 | vec![32.0, 24.0, 19.0, 18.5, 11.5],
115 | vec![9.5, 11.0, 17.0, 5.5, 2.5],
116 | vec![4.0, 3.5, 2.5, 5.0, 1.9],
117 | vec![38.5, 24.0, 19.0, 15.0, 2.3],
118 | ],
119 | labels: vec!["Miami".into(), "Barcelona".into(), "Tokyo".into(), "Rio de Janeiro".into(), "Mexico City".into()],
120 | }
121 | }
122 | h3 {
123 | class: "truncate tracking-tight text-sm text-gray-200",
124 | "Date night cost (2 long drinks, taxi, big mac and club entry)"
125 | }
126 | }
127 |
128 | div {
129 | class: "inline-grid grid-cols-1 gap-y-2",
130 | div {
131 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
132 | LineChart {
133 | padding_top: 30,
134 | padding_left: 65,
135 | padding_right: 80,
136 | padding_bottom: 30,
137 | label_interpolation: (|v| format!("${v}B")) as fn(f32) -> String,
138 | series: vec![
139 | vec![29.0, 30.5, 32.6, 35.0, 37.5],
140 | vec![20.0, 25.1, 26.0, 25.2, 26.6],
141 | vec![18.0, 21.0, 22.5, 24.0, 25.1],
142 | vec![12.5, 17.0, 19.3, 20.1, 21.0],
143 | ],
144 | labels: vec!["2020A".into(), "2021E".into(), "2022E".into(), "2023E".into(), "2024E".into()],
145 | series_labels: vec!["Disney".into(), "Comcast".into(), "Warner".into(), "Netflix".into()],
146 | }
147 | }
148 | h3 {
149 | class: "truncate tracking-tight text-sm text-gray-200",
150 | "Content spending at major media and tech companies"
151 | }
152 | }
153 |
154 | div {
155 | class: "inline-grid grid-cols-1 gap-y-2",
156 | div {
157 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
158 | LineChart {
159 | width: "100%",
160 | height: "100%",
161 | padding_top: 30,
162 | padding_left: 50,
163 | padding_right: 90,
164 | padding_bottom: 30,
165 | show_grid_ticks: true,
166 | show_dotted_grid: false,
167 | label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
168 | series: vec![
169 | vec![75.77, 73.95, 74.56, 78.25, 77.15, 62.64, 67.51],
170 | vec![57.17, 57.78, 54.69, 52.95, 51.78, 41.0, 47.25],
171 | vec![23.12, 26.5, 26.1, 29.84, 25.05, 20.41, 20.1],
172 | vec![26.02, 21.48, 21.05, 22.64, 20.64, 17.19, 16.31],
173 | vec![0.0, 13.65, 12.3, 13.35, 11.17, 9.87, 10.15],
174 | ],
175 | labels: vec!["2016".into(), "2017".into(), "2018".into(), "2019".into(), "2020".into(), "2021".into(), "2022".into()],
176 | series_labels: vec!["Firefox".into(), "Chromium".into(), "Chrome".into(), "Epiphany".into(), "Konqueror".into()],
177 | }
178 | }
179 | h3 {
180 | class: "truncate tracking-tight text-sm text-gray-200",
181 | "Arch Linux browser package relative usage"
182 | }
183 | }
184 |
185 | div {
186 | class: "inline-grid grid-cols-1 gap-y-2",
187 | div {
188 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
189 | PieChart {
190 | width: "100%",
191 | height: "100%",
192 | start_angle: -60.0,
193 | label_position: LabelPosition::Outside,
194 | label_offset: 35.0,
195 | padding: 20.0,
196 | series: vec![59.54, 17.2, 9.59, 7.6, 5.53, 0.55],
197 | labels: vec!["Asia".into(), "Africa".into(), "Europe".into(), "N. America".into(), "S. America".into(), "Oceania".into()],
198 | }
199 | }
200 | h3 {
201 | class: "truncate tracking-tight text-sm text-gray-200",
202 | "World population share by continents 2022"
203 | }
204 | }
205 |
206 | div {
207 | class: "inline-grid grid-cols-1 gap-y-2",
208 | div {
209 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
210 | PieChart {
211 | width: "100%",
212 | height: "100%",
213 | start_angle: 50.0,
214 | label_position: LabelPosition::Outside,
215 | label_offset: 27.0,
216 | donut: true,
217 | padding: 20.0,
218 | series: vec![5.0, 4.0, 4.0, 2.0, 2.0, 2.0, 1.0, 1.0],
219 | labels: vec!["Brazil".into(), "Germany".into(), "Italy".into(), "France".into(), "Uruguay".into(), "Argentina".into(), "England".into(), "Spain".into()],
220 | }
221 | }
222 | h3 {
223 | class: "truncate tracking-tight text-sm text-gray-200",
224 | "World Cup titles at 2022"
225 | }
226 | }
227 |
228 | div {
229 | class: "inline-grid grid-cols-1 gap-y-2",
230 | div {
231 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
232 | PieChart {
233 | width: "100%",
234 | height: "100%",
235 | viewbox_width: 500,
236 | viewbox_height: 300,
237 | start_angle: 270.0,
238 | show_ratio: 0.5,
239 | donut: true,
240 | label_position: LabelPosition::Center,
241 | label_offset: 60.0,
242 | label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
243 | series: vec![50.0, 25.0, 25.0],
244 | }
245 | }
246 | h3 {
247 | class: "truncate tracking-tight text-sm text-gray-200",
248 | "Gauge Chart"
249 | }
250 | }
251 |
252 | div {
253 | class: "inline-grid grid-cols-1 gap-y-2",
254 | div {
255 | class: "aspect-w-1 aspect-h-1 w-full overflow-hidden rounded-lg bg-gray-300 xl:aspect-w-7 xl:aspect-h-8",
256 | BarChart {
257 | padding_top: 30,
258 | padding_left: 100,
259 | padding_right: 70,
260 | padding_bottom: 30,
261 | bar_width: "6%",
262 | horizontal_bars: true,
263 | viewbox_width: 600,
264 | viewbox_height: 500,
265 | show_grid_ticks: true,
266 | show_dotted_grid: false,
267 | label_size: 90,
268 | label_interpolation: (|v| format!("{v}km²")) as fn(f32) -> String,
269 | series: vec![
270 | vec![150.0, 22.3, 13.5, 12.7, 3.7, 2.78, 2.5, 1.47],
271 | ],
272 | labels: vec![
273 | "Walt Disney Orlando, USA".into(),
274 | "Disneyland Paris, France".into(),
275 | "Beto Carrero, Brazil".into(),
276 | "Disneyland Anaheim, USA".into(),
277 | "Alton Towers, UK".into(),
278 | "Universal Orlando, USA".into(),
279 | "Tokyo Disney, Japan".into(),
280 | "Cedar Point, USA".into(),
281 | ]
282 | }
283 | }
284 | h3 {
285 | class: "truncate tracking-tight text-sm text-gray-200",
286 | "8 biggest amusement parks in the world"
287 | }
288 | }
289 | }
290 | }
291 | }
292 | }
293 | }
294 |
--------------------------------------------------------------------------------
/examples/desktop/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "charts-desktop-demo"
3 | version = "0.1.0"
4 | authors = ["Hilton Medeiros"]
5 | edition = "2021"
6 | description = "A dioxus-charts desktop demo"
7 | license = "MIT OR Apache-2.0"
8 | publish = false
9 |
10 | [dependencies]
11 | log = "0.4"
12 | env_logger = "0.10"
13 | charts-demo = { path = "../demo" }
14 | dioxus = { version = "0.6", features = ["desktop"] }
15 |
--------------------------------------------------------------------------------
/examples/desktop/Makefile.toml:
--------------------------------------------------------------------------------
1 |
2 | [tasks.format]
3 | install_crate = "rustfmt"
4 | command = "cargo"
5 | args = ["fmt", "--", "--emit=files"]
6 |
7 | [tasks.run]
8 | command = "cargo"
9 | args = ["run"]
10 |
11 | [tasks.css]
12 | command = "npx"
13 | args = ["tailwindcss", "-i", "src/input.css", "-o", "src/tailwind.css"]
14 |
15 | [tasks.dev]
16 | dependencies = [
17 | "format",
18 | "css",
19 | "run",
20 | ]
21 |
--------------------------------------------------------------------------------
/examples/desktop/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |