Skip to content

Commit 116e884

Browse files
authored
Wrapper: rewrite the content (ChartsCSS#42)
1 parent 88a04d0 commit 116e884

File tree

1 file changed

+70
-54
lines changed

1 file changed

+70
-54
lines changed

src/components/wrapper.md

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,50 @@ The full structure of a chart includes a wrapper `<div>` with inner components i
1515
<div id="my-chart">
1616

1717
<table class="charts-css bar|column|area|line">
18+
...
1819
</table>
1920

2021
<ul class="charts-css legend">
22+
...
2123
</ul>
2224

2325
</div>
2426
```
2527

26-
Note that only the `<table>` is required. The wrapper elements and the legend are optional fields.
28+
Please note that only the `<table>` element is required. The wrapper elements and the legend are optional fields.
2729

2830
| Type | Field | Element |
2931
|:----------------|:-------------|:----------------|
3032
| Wrapper Element | **Optional** | Any |
3133
| Chart Legend | **Optional** | `<ul>` / `<ol>` |
3234
| Chart Data | **Required** | `<table>` |
3335

34-
As of version 1.0.0, the new best practice is to add a wrapper element to all your charts.
36+
Although a wrapper div is not required, as of version 1.0.0 the new best practice is to add a wrapper element to all charts.
3537

36-
## Data Table
38+
## Customizing the Wrapper
3739

38-
To turn the data table into a chart, you need to add the `.charts-css` class to the `<table>` element itself:
39-
40-
```html
41-
<table class="charts-css">
42-
...
43-
</table>
44-
```
45-
46-
This class will reset, contain, pad and remove all other styles. But it won't transform the data table into a chart, yet.
47-
48-
## Chart Classes
49-
50-
To visualize the data you need to decide which [chart type](/charts/) you want to use and add the chart class after the main class. For example, to display a column chart we need to add the `.column` class.
51-
52-
```html
53-
<table class="charts-css column">
54-
...
55-
</table>
56-
```
57-
58-
To create a bar chart you need to add the `.bar` class.
59-
60-
```html
61-
<table class="charts-css bar">
62-
...
63-
</table>
64-
```
65-
66-
Only then add some inner components like [axes](/components/axes), [tooltips](/components/tooltips) etc.
67-
68-
```html
69-
<table class="charts-css bar show-primary-axis show-4-secondary-axes show-data-axes">
70-
...
71-
</table>
72-
```
73-
74-
## Customizing the Chart
75-
76-
A simple customization will include the `height` and `width` of the chart.
40+
A simple customization will include custom width for the wrapper.
7741

7842
```css
79-
#my-chart .bar {
80-
height: 300px;
81-
width: 600px;
43+
#my-chart {
44+
width: 100%;
45+
max-width: 300px;
8246
margin: 0 auto;
8347
}
8448
```
8549

86-
In addition, you can add any CSS to style the chart. For example, add your brand logo in the background.
50+
To customize chart components, use descendant combinators with the component selector.
8751

8852
```css
89-
#my-chart .bar {
90-
background-image: url(path/to/your/logo.svg);
91-
background-repeat: no-repeat;
92-
background-position: center center;
93-
background-size: 100px 100px;
53+
#my-chart .legend {
54+
...
55+
}
56+
#my-chart .bar,
57+
#my-chart .column,
58+
#my-chart .area,
59+
#my-chart .line,
60+
#my-chart .pie {
61+
...
9462
}
9563
```
9664

@@ -99,19 +67,67 @@ In addition, you can add any CSS to style the chart. For example, add your brand
9967
Media queries can be used to set different dimensions for different screen sizes.
10068

10169
```css
102-
#my-chart .bar {
70+
#my-chart {
10371
max-width: 600px;
10472
}
10573

10674
@media (min-width: 600px) {
107-
#my-chart .bar {
75+
#my-chart {
10876
max-width: 800px;
10977
}
11078
}
11179

11280
@media (min-width: 1000px) {
113-
#my-chart .bar {
81+
#my-chart {
11482
max-width: 1000px;
11583
}
11684
}
11785
```
86+
87+
Alternatively, container queries can be used to style based on the size and layout of specific elements on the page. For example, you can position the legend and the chart side-by-side, and under a certain width to position them below each other.
88+
89+
```css
90+
#my-chart {
91+
container-name: chart;
92+
container-type: inline-size;
93+
}
94+
95+
#my-chart {
96+
display: flex;
97+
flex-direction: row;
98+
}
99+
100+
@container charts (max-width: 600px) {
101+
#my-chart {
102+
flex-direction: column;
103+
}
104+
}
105+
```
106+
107+
## Additional Elements
108+
109+
Add your own elements to the chart and style them accordingly.
110+
111+
```html
112+
<div id="my-chart">
113+
114+
<table class="charts-css bar|column|area|line">
115+
...
116+
</table>
117+
118+
<ul class="charts-css legend">
119+
...
120+
</ul>
121+
122+
<div class="my-chart-element">
123+
...
124+
</div>
125+
126+
<div class="another-custom-element">
127+
...
128+
</div>
129+
130+
</div>
131+
```
132+
133+
For a concrete example, see how easy it is to add [axes titles](./axes/#axis-title) with custom HTML elements and some CSS magic.

0 commit comments

Comments
 (0)