Skip to content

Commit b11cd56

Browse files
authored
Migrate from 0.x to v1.x (ChartsCSS#45)
1 parent fd2e59c commit b11cd56

File tree

4 files changed

+335
-7
lines changed

4 files changed

+335
-7
lines changed

src/components/stacked.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Stack items atop one another using a `.column` chart.
330330

331331
## Simple vs. Percentage
332332

333-
To change the display from a simple stacked view to a percentage stacked view, change the `--size` property.
333+
To change the display from a simple stacked view to a percentage stacked view, change the `--size` variable.
334334

335335
For a **simple view**, we divide by the total number we want to compare the group to:
336336

src/development/roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ The framework will implement new features and components, not necessarily in tha
3737

3838
* **Build Tools** - Add more build tools.
3939

40-
* **Name Spacing** - Use namespaces for classes ~~& properties~~ to prevent conflicts with other CSS frameworks.
40+
* **Name Spacing** - Use namespaces for classes ~~& variable~~ to prevent conflicts with other CSS frameworks.
4141

4242
* **Component Prefixes** - Consider supporting component prefixes: `chart-axes:primary`, `chart-axes:*-secondary`, `chart-axes:data`, `chart-labels:show`, `chart-labels:align-end` etc.

src/docs/migrate-to-v1.md

Lines changed: 331 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,334 @@ next: ../../components/
55

66
# Migrate to v1.0
77

8-
::: warning WIP
9-
This guide is currently being written and will be published in the coming days.
10-
:::
8+
This guide covers notable changes and breaking changes introduced in **Charts.css** version 1.0. It will help you migrate from version 0.x to 1.x.
9+
10+
## Notable Changes
11+
12+
**New:**
13+
14+
* New chart type - Pie chart.
15+
* New aspect-ratio for charts.
16+
* New orientation utility classes to reverse labels.
17+
* New utility classes to align labels.
18+
* New utility classes to position data.
19+
* New CSS variables to style legends.
20+
* New `--end` CSS variable.
21+
* New `@property` types added to all CSS variables.
22+
* New SCSS prefix added to all CSS variables.
23+
* Fix legend colors to make them repeat after the basic 10 colors.
24+
* Fix axes by replace hardcoded SASS division with CSS `calc()`.
25+
26+
**Removals:**
27+
28+
* `--heading-size` variable was removed.
29+
* `labels-align-start` class was replaced with `labels-align-{block|inline}-start`.
30+
* `labels-align-center` class was replaced with `labels-align-{block|inline}-center`.
31+
* `labels-align-end` class was replaced with `labels-align-{block|inline}-end`.
32+
33+
**Best Practices:**
34+
35+
* Prefer styling with a wrapper element.
36+
* Custom chart `height` is no longer required.
37+
38+
### Wrapper
39+
40+
Previously, you could either apply custom `id` attributes on a `<table>` element:
41+
42+
```html{1}
43+
<table class="charts-css bar ..." id="my-chart">
44+
  ...
45+
</table>
46+
```
47+
48+
Or, on a wrapping `<div>`:
49+
50+
```html{1}
51+
<div id="my-chart">
52+
53+
  <table class="charts-css bar ...">
54+
    ...
55+
  </table>
56+
57+
</div>
58+
```
59+
60+
You can still do that, but as of this release it's no longer recommended.
61+
62+
All the docs have been updated to recommend using a wrapper `<div>` with custom `id` attribute. This change makes it easier to add new inner elements like the [legend](../components/legend/), [axes titles](../components/axes/#axis-title), [multiple mixed charts](./../charts/mixed/) etc.
63+
64+
We strongly recommend adding [wrapper elements](./../components/wrapper/) when migrating from version 0.x to 1.x.
65+
66+
### Chart Height
67+
68+
**Breaking change!** Previously, when serving an empty `<td>` or utilizing the `hide-data` / `show-data-on-hover` utility classes, the chart had no height. To overcome this issue, you had to set a custom style containing a minimum `height` value. It's no longer required.
69+
70+
```diff
71+
- #my-chart .column {
72+
-   height: 200px;
73+
- }
74+
```
75+
76+
### Aspect Ratio
77+
78+
**Breaking change!** Version 1.0.0 uses `aspect-ratio` on `<tbody>` element, making sure the chart always has a height even when you don't set a `height`. This change sets a proportional height based on the chart width.
79+
80+
The change has the potential to change the height of existing charts. When migrating to 1.0, if the chart height is changed when you remove the `height` property, use `aspect-ratio` instead:
81+
82+
```css
83+
#my-chart .column tbody {
84+
  aspect-ratio: 21 / 9;
85+
}
86+
```
87+
88+
Note that [each chart type has a different aspect ratio](./../customization/basic-styling/#aspect-ratio).
89+
90+
### Heading Size
91+
92+
Previously, when you had a long text inside the `<caption>`, the text and the chart were overlapping. To fix this visual issue, you could increase the size of the heading with the `--heading-size` variable, and tweak the size for each media query. It's no longer required.
93+
94+
As of this release, the size of the heading text fits to the content, without any external workarounds. When migrating to version 1.x, remove all the `--heading-size` variables from your chart customizations. This variable has been removed from **Charts.css**.
95+
96+
```diff
97+
- #my-chart .column {
98+
-   --heading-size: 3rem;
99+
- }
100+
```
101+
102+
### Reverse Labels
103+
104+
Previously, there were three [orientation](../components/orientation/) utility classes for reversing the order of different elements inside the chart - `reverse`, `reverse-data` and `reverse-dataset`.
105+
106+
As of this release, a fourth orientation class was added, the `reverse-labels` class. This class allows you to [position the labels on the other side](./../components/orientation/#reverse-labels). Charts with reversed labels position the label where the data ends, rather where the data starts.
107+
108+
```html{3}
109+
<div id="my-chart">
110+
111+
  <table class="charts-css column reverse-labels ...">
112+
    ...
113+
  </table>
114+
115+
</div>
116+
```
117+
118+
With this feature you can create **[Population Pyramid](./../components/orientation/#population-pyramid-chart)** charts. It can be achieved by positioning side-by-side two bar charts with reversed labels.
119+
120+
<code-example code-example-id="new-population-chart">
121+
<template v-slot:css-code>
122+
#new-population-chart {
123+
width: 100%;
124+
max-width: 600px;
125+
margin: 0 auto;
126+
display: flex;
127+
}
128+
#new-population-chart .bar tbody {
129+
aspect-ratio: 1 / 1;
130+
}
131+
#new-population-chart .bar.male {
132+
--color: rgba(100, 210, 80, .75);
133+
}
134+
#new-population-chart .bar.female {
135+
--color: rgba(240, 50, 50, .75);
136+
}
137+
</template>
138+
<template v-slot:html-code>
139+
<div id="new-population-chart">
140+
<table class="charts-css bar show-heading show-labels show-data-on-hover data-outside data-spacing-1 reverse-labels reverse male">
141+
<caption> Male population </caption>
142+
<thead>
143+
<tr>
144+
<th scope="col"> Age </th>
145+
<th scope="col"> Population </th>
146+
</tr>
147+
</thead>
148+
<tbody>
149+
<tr>
150+
<th scope="row"> 85+ </th>
151+
<td style="--size: calc( 0.010 / 0.10 )"> <span class="data outside">1.0%</span> </td>
152+
</tr>
153+
<tr>
154+
<th scope="row"> 75-84 </th>
155+
<td style="--size: calc( 0.020 / 0.10 )"> <span class="data">2.0%</span> </td>
156+
</tr>
157+
<tr>
158+
<th scope="row"> 65-74 </th>
159+
<td style="--size: calc( 0.037 / 0.10 )"> <span class="data">3.7%</span> </td>
160+
</tr>
161+
<tr>
162+
<th scope="row"> 55-64 </th>
163+
<td style="--size: calc( 0.042 / 0.10 )"> <span class="data">4.2%</span> </td>
164+
</tr>
165+
<tr>
166+
<th scope="row"> 45-54 </th>
167+
<td style="--size: calc( 0.054 / 0.10 )"> <span class="data">5.4%</span> </td>
168+
</tr>
169+
<tr>
170+
<th scope="row"> 35-44 </th>
171+
<td style="--size: calc( 0.062 / 0.10 )"> <span class="data">6.2%</span> </td>
172+
</tr>
173+
<tr>
174+
<th scope="row"> 25-34 </th>
175+
<td style="--size: calc( 0.065 / 0.10 )"> <span class="data">6.5%</span> </td>
176+
</tr>
177+
<tr>
178+
<th scope="row"> 15-24 </th>
179+
<td style="--size: calc( 0.074 / 0.10 )"> <span class="data">7.4%</span> </td>
180+
</tr>
181+
<tr>
182+
<th scope="row"> 5-14 </th>
183+
<td style="--size: calc( 0.089 / 0.10 )"> <span class="data">8.9%</span> </td>
184+
</tr>
185+
<tr>
186+
<th scope="row"> 0-4 </th>
187+
<td style="--size: calc( 0.048 / 0.10 )"> <span class="data">4.8%</span> </td>
188+
</tr>
189+
</tbody>
190+
</table>
191+
<table class="charts-css bar show-heading show-labels show-data-on-hover data-outside data-spacing-1 reverse-labels female">
192+
<caption> Female population </caption>
193+
<thead>
194+
<tr>
195+
<th scope="col"> Age </th>
196+
<th scope="col"> Population </th>
197+
</tr>
198+
</thead>
199+
<tbody>
200+
<tr>
201+
<th scope="row"> 85+ </th>
202+
<td style="--size: calc( 0.007 / 0.10 )"> <span class="data outside">0.7%</span> </td>
203+
</tr>
204+
<tr>
205+
<th scope="row"> 75-84 </th>
206+
<td style="--size: calc( 0.016 / 0.10 )"> <span class="data">1.6%</span> </td>
207+
</tr>
208+
<tr>
209+
<th scope="row"> 65-74 </th>
210+
<td style="--size: calc( 0.032 / 0.10 )"> <span class="data">3.2%</span> </td>
211+
</tr>
212+
<tr>
213+
<th scope="row"> 55-64 </th>
214+
<td style="--size: calc( 0.040 / 0.10 )"> <span class="data">4.0%</span> </td>
215+
</tr>
216+
<tr>
217+
<th scope="row"> 45-54 </th>
218+
<td style="--size: calc( 0.053 / 0.10 )"> <span class="data">5.3%</span> </td>
219+
</tr>
220+
<tr>
221+
<th scope="row"> 35-44 </th>
222+
<td style="--size: calc( 0.064 / 0.10 )"> <span class="data">6.4%</span> </td>
223+
</tr>
224+
<tr>
225+
<th scope="row"> 25-34 </th>
226+
<td style="--size: calc( 0.067 / 0.10 )"> <span class="data">6.7%</span> </td>
227+
</tr>
228+
<tr>
229+
<th scope="row"> 15-24 </th>
230+
<td style="--size: calc( 0.077 / 0.10 )"> <span class="data">7.7%</span> </td>
231+
</tr>
232+
<tr>
233+
<th scope="row"> 5-14 </th>
234+
<td style="--size: calc( 0.094 / 0.10 )"> <span class="data">9.4%</span> </td>
235+
</tr>
236+
<tr>
237+
<th scope="row"> 0-4 </th>
238+
<td style="--size: calc( 0.050 / 0.10 )"> <span class="data">5.0%</span> </td>
239+
</tr>
240+
</tbody>
241+
</table>
242+
</div>
243+
</template>
244+
</code-example>
245+
246+
### Pie Chart
247+
248+
Version 1.0.0 also introduced [Pie charts](../charts/pie/), streamline the process of converting data tables to an additional [chart type](../charts/) using a simple CSS utility class. This is the first circular chart introduced by **Charts.css**.
249+
250+
<code-example code-example-id="new-pie-chart">
251+
<template v-slot:css-code>
252+
#new-pie-chart {
253+
width: 100%;
254+
max-width: 300px;
255+
margin: 0 auto;
256+
}
257+
</template>
258+
<template v-slot:html-code>
259+
<div id="new-pie-chart">
260+
<table class="charts-css pie hide-data">
261+
<caption> Pie Chart </caption>
262+
<tbody>
263+
<tr>
264+
<td style="--start: 0.0; --end: 0.1"> <span class="data"> 10 </span> </td>
265+
</tr>
266+
<tr>
267+
<td style="--start: 0.1; --end: 0.2"> <span class="data"> 10 </span> </td>
268+
</tr>
269+
<tr>
270+
<td style="--start: 0.2; --end: 0.3"> <span class="data"> 10 </span> </td>
271+
</tr>
272+
<tr>
273+
<td style="--start: 0.3; --end: 0.4"> <span class="data"> 10 </span> </td>
274+
</tr>
275+
<tr>
276+
<td style="--start: 0.4; --end: 0.5"> <span class="data"> 10 </span> </td>
277+
</tr>
278+
<tr>
279+
<td style="--start: 0.5; --end: 0.6"> <span class="data"> 10 </span> </td>
280+
</tr>
281+
<tr>
282+
<td style="--start: 0.6; --end: 0.7"> <span class="data"> 10 </span> </td>
283+
</tr>
284+
<tr>
285+
<td style="--start: 0.7; --end: 0.8"> <span class="data"> 10 </span> </td>
286+
</tr>
287+
<tr>
288+
<td style="--start: 0.8; --end: 0.9"> <span class="data"> 10 </span> </td>
289+
</tr>
290+
<tr>
291+
<td style="--start: 0.9; --end: 1.0"> <span class="data"> 10 </span> </td>
292+
</tr>
293+
</tbody>
294+
</table>
295+
</div>
296+
</template>
297+
</code-example>
298+
299+
### Labels Position
300+
301+
Previously, all labels were aligned to the center of the `<th>` element. As of this release, the labels are aligned to the beginning of the row in [bar charts](../charts/bar/) and to the bottom of the column on [column](../charts/column/), [area](../charts/area/) and [line](../charts/line/) charts.
302+
303+
To control the [position alignment of the label](./../components/labels/#align-labels), you get more possibilities.
304+
305+
**Deprecated classes:**
306+
307+
* `labels-align-start`
308+
* `labels-align-center`
309+
* `labels-align-end`
310+
311+
**New classes:**
312+
313+
* `labels-align-inline-start`
314+
* `labels-align-inline-center`
315+
* `labels-align-inline-end`
316+
* `labels-align-block-start`
317+
* `labels-align-block-center`
318+
* `labels-align-block-end`
319+
320+
### Data Position
321+
322+
Previously you couldn't control where the data will be displayed. It was fixed at the end of the row. Version 1.0.0 introduces additional CSS utility classes snd variables that help you customize the position of your data.
323+
324+
**New classes:**
325+
326+
* `data-start`
327+
* `data-center`
328+
* `data-end`
329+
* `data-outside`
330+
331+
**New variables:**
332+
333+
* `--data-position`
334+
335+
Furthermore, when you have a very low or a very heigh value on your bar and column charts, the data seems out of position. Version 1.0.0 introduces new utility classes added either to the `<td>` element or to the `<span>` element wrapping the data. The new classes are:
336+
337+
* `inside`
338+
* `outside`

src/docs/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ Result:
9090

9191
## Add Data
9292

93-
To make the data available for use by **Charts.css**, it should be converted to CSS properties.
93+
To make the data available for use by **Charts.css**, it should be converted to CSS variables.
9494

95-
The same table with CSS `--size` properties:
95+
The same table with CSS `--size` variables:
9696

9797
```html{17-19,23-25,29-31}
9898
<table>

0 commit comments

Comments
 (0)