-
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.
Merge pull request #48 from geo2france/dev
1.3
- Loading branch information
Showing
25 changed files
with
717 additions
and
54 deletions.
There are no files selected for viewing
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 @@ | ||
module.exports = {}; |
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,70 @@ | ||
import alasql from "alasql"; | ||
import { EChartsOption } from "echarts"; | ||
import ReactECharts from 'echarts-for-react'; | ||
import { useRef } from "react"; | ||
import { useChartData, useDashboardElement } from "../DashboardElement/hooks"; | ||
import deepMerge from "../../utils/deepmerge"; | ||
|
||
|
||
type EChartsSeriesTypes = ('line' | 'bar' | 'pie' | 'scatter'); | ||
|
||
interface IDashboardChartProps { | ||
data?: any[]; | ||
chart_type?: EChartsSeriesTypes; // Utiliser directement le type de SeriesOption | ||
sql? : string; | ||
echarts_option?: EChartsOption; | ||
reverse_axies?:boolean | ||
} | ||
|
||
|
||
// Les données doivent être de la forme {axeA : axeB : } ? | ||
|
||
const DashboardChart: React.FC<IDashboardChartProps> = ({data, chart_type='line', reverse_axies=false, echarts_option = {}, sql}) => { | ||
const chartRef = useRef<any>(); | ||
useDashboardElement({chartRef}) | ||
|
||
const data_xy = sql ? alasql(sql, [data]) : data; | ||
|
||
useChartData({data:data_xy}) | ||
|
||
const keys = Object.keys(data_xy[0]); | ||
|
||
const axis0 = { | ||
type: typeof data_xy[0][keys[0]] === 'number' ? 'value' : 'category', | ||
name: keys[0] | ||
} | ||
|
||
const axis1 = { | ||
type: typeof data_xy[0][keys[1]] === 'number' ? 'value' : 'category', | ||
name: keys[1] | ||
} | ||
|
||
const options:EChartsOption = { | ||
series:[ | ||
{ | ||
type:chart_type, | ||
data:data_xy.map((e:any) => | ||
reverse_axies ? | ||
[e[keys[1]], e[keys[0]]] | ||
: [e[keys[0]], e[keys[1]]] | ||
) | ||
} | ||
], | ||
//@ts-ignore | ||
xAxis:{ | ||
...reverse_axies ? axis1 : axis0 | ||
}, | ||
//@ts-ignore | ||
yAxis:{ | ||
...reverse_axies ? axis0 : axis1 | ||
} | ||
} | ||
return ( | ||
<ReactECharts | ||
option={deepMerge(options,echarts_option)} ref={chartRef} /> | ||
) | ||
} | ||
|
||
|
||
export default DashboardChart; | ||
|
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,38 @@ | ||
# DashboardChart | ||
|
||
Le composant DashboardChart facilite la création de graphique à deux dimensions. | ||
Le type de graphique `chart_type` est à choisir parmis les suivants : `'bar' | 'pie' | 'line' | 'scatter' `. | ||
|
||
## Les données et les axes | ||
|
||
Les données `data` doivent être une liste d'objets ayant chacun _exactement_ deux propriétés. Le nom des propriétés est libre, et consitituerons les noms des axes. | ||
Par défaut, la première clé correspond aux abscisses (X) et la seconde aux ordonnées (Y). Il est possible d'inverser ceci avec `reverse_axies=true`. | ||
Le type d'axe (`value` ou `category`) est déterminé automatiquement à partir du contenu des données (numérique ou texte). | ||
|
||
DashboardChart permet également d'appliquer une requête `sql` pour traiter les données à la volée (par exemple pour réaliser une aggrégation). Le nom de la table à utilisé est `?` (exemple : `SELECT x as commune, y as population FROM ?`). Pour plus d'information, voir la [documentation AlaSQL](https://github.com/AlaSQL/alasql/wiki/Select). | ||
Si aucune requête n'est fournie, les données `data` sont directement utilisées. | ||
|
||
## Intégration dans la page | ||
|
||
Il est intéressant de placer _DashboardChart_ en tant qu'enfant de [_DashboardElement_](../DashboardElement/) : En plus de l'habillage du graphique (titre, crédits, etc.), ceci permettra de proposer automatiquement à l'utilisateur d'exporter les données en format tabulaire (CSV, ODS, etc.). | ||
|
||
|
||
## Personnalisation avancée | ||
|
||
La propriété `echarts_option` permet de personnaliser le graphique en éditant directement la configuration du graphique. Voir les paramètres disponibles dans la [documentation de Apache ECharts](https://echarts.apache.org/en/option.html). | ||
|
||
## Exemple | ||
|
||
```tsx | ||
<DashboardElement title="Mon graphique de test"> | ||
<DashboardChart | ||
data={[{mavar:'a', autrevar:2},{mavar:'b', autrevar:5},{mavar:'c', autrevar:4}]} | ||
chart_type="bar" | ||
echarts_option={{ | ||
xAxis:{show:false}, | ||
yAxis:{axisLabel:{color:'red'}}, | ||
tooltip:{show:true} | ||
}} | ||
/> | ||
</DashboardElement> | ||
``` |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.