@geo2france/api-dashboard 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Charts/Pie.d.ts +1 -0
- package/dist/components/Charts/Pie.js +13 -5
- package/dist/components/Charts/YearSerie.d.ts +0 -1
- package/dist/components/Charts/YearSerie.js +20 -16
- package/dist/components/DashboardPage/Page.d.ts +1 -0
- package/dist/components/DashboardPage/Page.js +4 -1
- package/dist/data_providers/datafair/utils/generateFilter.js +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/merge_others.d.ts +8 -0
- package/dist/utils/merge_others.js +14 -0
- package/package.json +1 -1
|
@@ -5,7 +5,8 @@ import { ChartBlockContext } from "../DashboardPage/Block";
|
|
|
5
5
|
import { usePalette } from "../Palette/Palette";
|
|
6
6
|
import { from, op } from "arquero";
|
|
7
7
|
import { ChartEcharts } from "./ChartEcharts";
|
|
8
|
-
|
|
8
|
+
import { merge_others } from "../..";
|
|
9
|
+
export const ChartPie = ({ dataset: dataset_id, nameKey, dataKey, unit, title, donut = false, other = 5 }) => {
|
|
9
10
|
const dataset = useDataset(dataset_id);
|
|
10
11
|
const blockConfig = useContext(ChartBlockContext);
|
|
11
12
|
const data = dataset?.data;
|
|
@@ -14,10 +15,17 @@ export const ChartPie = ({ dataset: dataset_id, nameKey, dataKey, unit, title, d
|
|
|
14
15
|
dataExport: data
|
|
15
16
|
};
|
|
16
17
|
useEffect(() => blockConfig?.setConfig(block_config), [data]);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const chart_data1 = data && data.length > 0
|
|
19
|
+
? from(data)
|
|
20
|
+
.groupby(nameKey)
|
|
21
|
+
.rollup({ value: op.sum(dataKey) })
|
|
22
|
+
.objects()
|
|
23
|
+
.map((d) => ({
|
|
24
|
+
name: d[nameKey],
|
|
25
|
+
value: d.value,
|
|
26
|
+
}))
|
|
27
|
+
: [];
|
|
28
|
+
const chart_data = merge_others({ dataset: chart_data1 || [], min: other || -1 });
|
|
21
29
|
const option = {
|
|
22
30
|
color: usePalette({ nColors: chart_data?.length }),
|
|
23
31
|
xAxis: { show: false }, yAxis: { show: false },
|
|
@@ -6,27 +6,31 @@ import { from, op } from "arquero";
|
|
|
6
6
|
import { useDataset } from "../Dataset/hooks";
|
|
7
7
|
import { usePalette } from "../Palette/Palette";
|
|
8
8
|
import { ChartEcharts } from "./ChartEcharts";
|
|
9
|
-
export const ChartYearSerie = ({ dataset: dataset_id, categoryKey, valueKey, yearKey, yearMark, stack: stack_input, type: chart_type = 'bar'
|
|
9
|
+
export const ChartYearSerie = ({ dataset: dataset_id, categoryKey, valueKey, yearKey, yearMark, stack: stack_input, type: chart_type = 'bar' }) => {
|
|
10
10
|
const stack = stack_input || chart_type == 'line' ? false : true; // Pas de stack par défaut pour le type line
|
|
11
11
|
const dataset = useDataset(dataset_id);
|
|
12
12
|
const data = dataset?.data;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
:
|
|
23
|
-
|
|
13
|
+
let chart_data = [];
|
|
14
|
+
let distinct_cat = [];
|
|
15
|
+
if (data && data.length > 0) {
|
|
16
|
+
const grouped_data = categoryKey ? from(data).groupby(yearKey, categoryKey) //Somme par année et categorykey
|
|
17
|
+
.rollup({ [valueKey]: op.sum(valueKey) })
|
|
18
|
+
.groupby(yearKey).orderby(yearKey)
|
|
19
|
+
:
|
|
20
|
+
from(data).groupby(yearKey) //Somme par année seulement
|
|
21
|
+
.rollup({ [valueKey]: op.sum(valueKey) }).orderby(yearKey);
|
|
22
|
+
const all_years = from(data).groupby(yearKey).rollup({ [yearKey]: op.any(yearKey) });
|
|
23
|
+
const all_cats = categoryKey ? (from(data).groupby(categoryKey).rollup({ [categoryKey]: op.any(categoryKey) })) : from([{ 'cat': valueKey }]);
|
|
24
|
+
const full = all_years.cross(all_cats); // Contient chaque annee x catégorie (pour éviter les trous)
|
|
25
|
+
distinct_cat = all_cats.array(categoryKey || 'cat'); // Pour générer chaque serie
|
|
26
|
+
chart_data = full.join_left(grouped_data).objects();
|
|
27
|
+
}
|
|
24
28
|
const COLORS = usePalette({ nColors: distinct_cat?.length }) || [];
|
|
25
|
-
const series = distinct_cat
|
|
29
|
+
const series = distinct_cat.map((cat, idx) => ({
|
|
26
30
|
name: cat,
|
|
27
31
|
type: chart_type === 'area' ? 'line' : chart_type,
|
|
28
|
-
data: categoryKey ? chart_data?.filter((row) => row[categoryKey] === cat).map((row) => ([String(row[yearKey]), row[valueKey]]))
|
|
29
|
-
: chart_data?.map((row) => ([String(row[yearKey]), row[valueKey]])),
|
|
32
|
+
data: categoryKey ? chart_data?.filter((row) => row[categoryKey] === cat).map((row) => ([String(row[yearKey]), row[valueKey] || 0]))
|
|
33
|
+
: chart_data?.map((row) => ([String(row[yearKey]), row[valueKey] || 0])),
|
|
30
34
|
itemStyle: {
|
|
31
35
|
color: COLORS && COLORS[idx % COLORS.length],
|
|
32
36
|
},
|
|
@@ -38,7 +42,7 @@ export const ChartYearSerie = ({ dataset: dataset_id, categoryKey, valueKey, yea
|
|
|
38
42
|
{ xAxis: String(yearMark) }
|
|
39
43
|
]
|
|
40
44
|
} : undefined
|
|
41
|
-
}))
|
|
45
|
+
}));
|
|
42
46
|
function tooltipFormatter(params) {
|
|
43
47
|
if (!params || params.length === 0)
|
|
44
48
|
return '';
|
|
@@ -40,7 +40,7 @@ export default DashboardPage;
|
|
|
40
40
|
export const DatasetContext = createContext({});
|
|
41
41
|
export const DatasetRegistryContext = createContext(() => { }); // A modifier, utiliser un seul context
|
|
42
42
|
export const ControlContext = createContext(undefined);
|
|
43
|
-
export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, children }) => {
|
|
43
|
+
export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, children, debug = false }) => {
|
|
44
44
|
const [datasets, setdatasets] = useState({});
|
|
45
45
|
const [palette, setPalette] = useState(DEFAULT_PALETTE);
|
|
46
46
|
//const allDatasetLoaded = Object.values(datasets).every(d => !d.isFetching);
|
|
@@ -68,6 +68,9 @@ export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, child
|
|
|
68
68
|
const visible_components = childrenArray.filter((c) => c && getComponentKind(c) == 'other');
|
|
69
69
|
const logic_components = childrenArray.filter((c) => getComponentKind(c) == 'logical');
|
|
70
70
|
const control_components = childrenArray.filter((c) => getComponentKind(c) == 'control');
|
|
71
|
+
if (debug && !logic_components.some((c) => typeof c.type !== "string" && c.type.name === Debug.name)) {
|
|
72
|
+
logic_components.push(_jsx(Debug, {}, "debug_property"));
|
|
73
|
+
}
|
|
71
74
|
return (_jsxs(_Fragment, { children: [_jsx(Helmet, { children: _jsx("title", { children: name }) }), _jsx(DatasetRegistryContext.Provider, { value: pushDataset, children: _jsx(DatasetContext.Provider, { value: datasets, children: _jsxs(PaletteContext.Provider, { value: { palette, setPalette }, children: [control_components.length > 0 && _jsx(Header, { style: {
|
|
72
75
|
padding: 12,
|
|
73
76
|
position: "sticky",
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { useChartData, useDashboardElement, useNoData } from "./components/Dashb
|
|
|
6
6
|
export { useMapControl } from "./utils/useMapControl";
|
|
7
7
|
export { BaseRecordToGeojsonPoint } from "./utils/baserecordtogeojsonpoint";
|
|
8
8
|
export { cardStyles } from "./utils/cardStyles";
|
|
9
|
+
export { merge_others } from "./utils/merge_others";
|
|
9
10
|
import KeyFigure from "./components/KeyFigure/KeyFigure";
|
|
10
11
|
import LoadingContainer from "./components/LoadingContainer/LoadingContainer";
|
|
11
12
|
import FlipCard from "./components/FlipCard/FlipCard";
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { useMapControl } from "./utils/useMapControl";
|
|
|
8
8
|
// Helpers
|
|
9
9
|
export { BaseRecordToGeojsonPoint } from "./utils/baserecordtogeojsonpoint";
|
|
10
10
|
export { cardStyles } from "./utils/cardStyles";
|
|
11
|
+
export { merge_others } from "./utils/merge_others";
|
|
11
12
|
// Components
|
|
12
13
|
import KeyFigure from "./components/KeyFigure/KeyFigure";
|
|
13
14
|
import LoadingContainer from "./components/LoadingContainer/LoadingContainer";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { from, op } from "arquero";
|
|
2
|
+
export const merge_others = ({ dataset, min, other_cat_name = 'Autres' }) => {
|
|
3
|
+
const total = dataset.reduce((acc, d) => acc + d.value, 0);
|
|
4
|
+
const small = dataset.filter(d => (d.value / total) * 100 < min);
|
|
5
|
+
const large = dataset.filter(d => (d.value / total) * 100 >= min);
|
|
6
|
+
if (small.length > 1) {
|
|
7
|
+
const others_row = from(small).rollup({ value: op.sum('value') }).objects().map((d) => ({
|
|
8
|
+
name: other_cat_name,
|
|
9
|
+
value: d.value
|
|
10
|
+
}));
|
|
11
|
+
return [...large, ...others_row];
|
|
12
|
+
}
|
|
13
|
+
return dataset;
|
|
14
|
+
};
|