forked from alshedivat/al-folio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Echarts support (alshedivat#2129)
Since I added support for chart.js and while doing so found some other wonderful charting libraries, I thought, why not give support to some more? So adding support to [Apache Echarts](https://echarts.apache.org/en/index.html). ![image](https://github.com/alshedivat/al-folio/assets/31376482/088f0932-524f-4fcd-a34b-b132f569a675) ![image](https://github.com/alshedivat/al-folio/assets/31376482/36bfe4f8-a9d1-4b6d-a912-fb40ba3b5337) --------- Signed-off-by: George Araújo <[email protected]>
- Loading branch information
1 parent
3ec0ff4
commit 4f6fe1a
Showing
8 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
_includes/scripts/chart.liquid → _includes/scripts/chartjs.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{% if page.chart %} | ||
{% if page.chart and page.chart.chartjs %} | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script> | ||
<script> | ||
$(document).ready(function () { | ||
var $canvas = null, | ||
$this = null, | ||
_ctx = null, | ||
_text = ''; | ||
$('.language-chart').each(function () { | ||
$('.language-chartjs').each(function () { | ||
$this = $(this); | ||
$canvas = $('<canvas></canvas>'); | ||
_text = $this.text(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% if page.chart and page.chart.echarts %} | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js" | ||
integrity="sha256-EVZCmhajjLhgTcxlGMGUBtQiYULZCPjt0uNTFEPFTRk=" | ||
crossorigin="anonymous" | ||
></script> | ||
{% if site.enable_darkmode %} | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/theme/dark-fresh-cut.js" | ||
integrity="sha256-UmFIP/4VvOqBDIl2QWl1HBuAJ1XWs/iFZxT5yJRZOKo=" | ||
crossorigin="anonymous" | ||
></script> | ||
{% endif %} | ||
<script> | ||
let theme = localStorage.getItem('theme'); | ||
/* Create echarts chart as another node and hide the code block, appending the echarts node after it | ||
this is done to enable retrieving the code again when changing theme between light/dark */ | ||
document.querySelectorAll('pre>code.language-echarts').forEach((elem) => { | ||
const jsonData = elem.textContent; | ||
const backup = elem.parentElement; | ||
backup.classList.add('unloaded'); | ||
/* create echarts node */ | ||
let chartElement = document.createElement('div'); | ||
chartElement.classList.add('echarts'); | ||
backup.after(chartElement); | ||
/* create echarts */ | ||
if (theme === 'dark') { | ||
var chart = echarts.init(chartElement, 'dark-fresh-cut'); | ||
} else { | ||
var chart = echarts.init(chartElement); | ||
} | ||
chart.setOption(JSON.parse(jsonData)); | ||
window.addEventListener('resize', function () { | ||
chart.resize(); | ||
}); | ||
}); | ||
</script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
layout: post | ||
title: a post with echarts | ||
date: 2024-01-26 16:03:00 | ||
description: this is what included echarts code could look like | ||
tags: formatting charts | ||
categories: sample-posts | ||
chart: | ||
echarts: true | ||
--- | ||
|
||
This is an example post with some [echarts](https://echarts.apache.org/) code. | ||
|
||
````markdown | ||
```echarts | ||
{ | ||
"title": { | ||
"text": "ECharts Getting Started Example" | ||
}, | ||
"responsive": true, | ||
"tooltip": {}, | ||
"legend": { | ||
"top": "30px", | ||
"data": ["sales"] | ||
}, | ||
"xAxis": { | ||
"data": ["Shirts", "Cardigans", "Chiffons", "Pants", "Heels", "Socks"] | ||
}, | ||
"yAxis": {}, | ||
"series": [ | ||
{ | ||
"name": "sales", | ||
"type": "bar", | ||
"data": [5, 20, 36, 10, 10, 20] | ||
} | ||
] | ||
} | ||
``` | ||
```` | ||
|
||
Which generates: | ||
|
||
```echarts | ||
{ | ||
"title": { | ||
"text": "ECharts Getting Started Example" | ||
}, | ||
"responsive": true, | ||
"tooltip": {}, | ||
"legend": { | ||
"top": "30px", | ||
"data": ["sales"] | ||
}, | ||
"xAxis": { | ||
"data": ["Shirts", "Cardigans", "Chiffons", "Pants", "Heels", "Socks"] | ||
}, | ||
"yAxis": {}, | ||
"series": [ | ||
{ | ||
"name": "sales", | ||
"type": "bar", | ||
"data": [5, 20, 36, 10, 10, 20] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
Note that this library offer support for both light and dark themes. You can switch between them using the theme switcher in the top right corner of the page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1081,3 +1081,8 @@ nav[data-toggle="toc"] { | |
#toc-sidebar { | ||
z-index: 1; | ||
} | ||
|
||
.echarts { | ||
width: 100%; | ||
height: 400px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters