|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class Views::Docs::Chart < Views::Base |
| 4 | + def view_template |
| 5 | + div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do |
| 6 | + render Docs::Header.new(title: "Chart", description: "Displays information in a visual way.") |
| 7 | + |
| 8 | + Heading(level: 2) { "Introduction" } |
| 9 | + |
| 10 | + Text do |
| 11 | + plain "RubyUI uses " |
| 12 | + InlineLink(href: "https://www.chartjs.org/") { "Chart.js" } |
| 13 | + plain " to render charts. Chart.js is a free open-source JavaScript library for data visualization, which supports 8 chart types: bar, line, area, pie, bubble, radar, polar, and scatter. If you're unfamiliar with Chart.js. We recommend the " |
| 14 | + InlineLink(href: "https://www.chartjs.org/docs/latest/getting-started/") { "Getting Started guide" } |
| 15 | + plain ". " |
| 16 | + end |
| 17 | + |
| 18 | + Heading(level: 2) { "Usage" } |
| 19 | + |
| 20 | + render Docs::VisualCodeExample.new(title: "Bar Chart", context: self) do |
| 21 | + <<~RUBY |
| 22 | + options = { |
| 23 | + type: 'bar', |
| 24 | + data: { |
| 25 | + labels: ['Phlex', 'VC', 'ERB'], |
| 26 | + datasets: [{ |
| 27 | + label: 'render time (ms)', |
| 28 | + data: [100, 520, 1200], |
| 29 | + }] |
| 30 | + }, |
| 31 | + options: { |
| 32 | + indexAxis: 'y', |
| 33 | + scales: { |
| 34 | + y: { |
| 35 | + beginAtZero: true |
| 36 | + } |
| 37 | + }, |
| 38 | + }, |
| 39 | + } |
| 40 | +
|
| 41 | + Chart(options: options) |
| 42 | + RUBY |
| 43 | + end |
| 44 | + |
| 45 | + render Docs::VisualCodeExample.new(title: "Line Graph", context: self) do |
| 46 | + <<~RUBY |
| 47 | + options = { |
| 48 | + type: 'line', |
| 49 | + data: { |
| 50 | + labels: ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'], |
| 51 | + datasets: [{ |
| 52 | + label: 'Github Stars', |
| 53 | + data: [40, 30, 79, 140, 290, 550], |
| 54 | + }] |
| 55 | + }, |
| 56 | + options: { |
| 57 | + scales: { |
| 58 | + y: { |
| 59 | + beginAtZero: true |
| 60 | + } |
| 61 | + }, |
| 62 | + plugins: { |
| 63 | + legend: { |
| 64 | + display: false |
| 65 | + } |
| 66 | + } |
| 67 | + }, |
| 68 | + } |
| 69 | +
|
| 70 | + Chart(options: options) |
| 71 | + RUBY |
| 72 | + end |
| 73 | + |
| 74 | + render Docs::VisualCodeExample.new(title: "Pie Chart", description: "Setting custom background color", context: self) do |
| 75 | + <<~RUBY |
| 76 | + options = { |
| 77 | + type: 'pie', |
| 78 | + data: { |
| 79 | + labels: [ |
| 80 | + 'Red', |
| 81 | + 'Blue', |
| 82 | + 'Yellow' |
| 83 | + ], |
| 84 | + datasets: [{ |
| 85 | + label: 'My First Dataset', |
| 86 | + data: [300, 50, 100], |
| 87 | + backgroundColor: [ |
| 88 | + 'rgb(255, 99, 132)', |
| 89 | + 'rgb(54, 162, 235)', |
| 90 | + 'rgb(255, 205, 86)' |
| 91 | + ], |
| 92 | + hoverOffset: 4 |
| 93 | + }] |
| 94 | + }, |
| 95 | + } |
| 96 | +
|
| 97 | + Chart(options: options) |
| 98 | + RUBY |
| 99 | + end |
| 100 | + |
| 101 | + render Components::ComponentSetup::Tabs.new(component_name: "Chart") |
| 102 | + |
| 103 | + render Docs::ComponentsTable.new(components) |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + private |
| 108 | + |
| 109 | + def components |
| 110 | + [ |
| 111 | + ::Docs::ComponentStruct.new(name: "ChartController", source: "https://github.com/PhlexUI/phlex_ui_stimulus/blob/main/controllers/chart_controller.js", built_using: :stimulus), |
| 112 | + ::Docs::ComponentStruct.new(name: "Chart", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/chart.rb", built_using: :phlex) |
| 113 | + ] |
| 114 | + end |
| 115 | +end |
0 commit comments