bento-charts 2.4.1 → 2.4.2

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.
Files changed (39) hide show
  1. package/dist/ChartConfigProvider.js +1 -12
  2. package/dist/ChartConfigProvider.js.map +1 -1
  3. package/dist/Components/Charts/BentoBarChart.d.ts +1 -1
  4. package/dist/Components/Charts/BentoBarChart.js +21 -35
  5. package/dist/Components/Charts/BentoBarChart.js.map +1 -1
  6. package/dist/Components/Charts/BentoPie.d.ts +1 -1
  7. package/dist/Components/Charts/BentoPie.js +55 -46
  8. package/dist/Components/Charts/BentoPie.js.map +1 -1
  9. package/dist/Components/Maps/BentoChoroplethMap.d.ts +1 -1
  10. package/dist/Components/Maps/BentoChoroplethMap.js +15 -32
  11. package/dist/Components/Maps/BentoChoroplethMap.js.map +1 -1
  12. package/dist/Components/Maps/BentoMapContainer.js +1 -12
  13. package/dist/Components/Maps/BentoMapContainer.js.map +1 -1
  14. package/dist/Components/Maps/BentoPointMap.js +4 -15
  15. package/dist/Components/Maps/BentoPointMap.js.map +1 -1
  16. package/dist/Components/Maps/controls/MapLegendContinuous.js +1 -12
  17. package/dist/Components/Maps/controls/MapLegendContinuous.js.map +1 -1
  18. package/dist/Components/Maps/controls/MapLegendDiscrete.js +2 -13
  19. package/dist/Components/Maps/controls/MapLegendDiscrete.js.map +1 -1
  20. package/dist/Components/NoData.js +2 -13
  21. package/dist/Components/NoData.js.map +1 -1
  22. package/dist/constants/chartConstants.d.ts +0 -1
  23. package/dist/constants/chartConstants.js +0 -1
  24. package/dist/constants/chartConstants.js.map +1 -1
  25. package/dist/types/chartTypes.d.ts +9 -6
  26. package/dist/types/mapTypes.d.ts +2 -3
  27. package/dist/util/chartUtils.d.ts +2 -0
  28. package/dist/util/chartUtils.js +30 -0
  29. package/dist/util/chartUtils.js.map +1 -1
  30. package/package.json +17 -16
  31. package/src/Components/Charts/BentoBarChart.tsx +15 -25
  32. package/src/Components/Charts/BentoPie.tsx +74 -76
  33. package/src/Components/Maps/BentoChoroplethMap.tsx +4 -12
  34. package/src/Components/Maps/BentoPointMap.tsx +13 -4
  35. package/src/constants/chartConstants.ts +0 -1
  36. package/src/types/chartTypes.ts +10 -7
  37. package/src/types/mapTypes.ts +3 -3
  38. package/src/util/chartUtils.ts +29 -0
  39. package/webpack.config.js +9 -1
@@ -37,6 +37,7 @@ export type UnitaryMapCallback<T> = (value: T, index: number, array: T[]) => T;
37
37
  // export type BinaryMapCallback<T, U> = (value: T, index: number, array: T[]) => U;
38
38
 
39
39
  export type ChartFilterCallback = FilterCallback<CategoricalChartDataItem>;
40
+ export type ChartDataMapCallback = UnitaryMapCallback<CategoricalChartDataItem>;
40
41
 
41
42
  export type SupportedLng = 'en' | 'fr';
42
43
 
@@ -50,19 +51,21 @@ export type TranslationObject = {
50
51
  [key in SupportedLng]: LngDictionary;
51
52
  };
52
53
 
53
- // ################### COMPONENT PROPS #####################
54
- export interface BaseChartComponentProps {
55
- height: number;
54
+ export interface CategoricalChartDataWithTransforms {
55
+ data: CategoricalChartDataType;
56
56
  preFilter?: ChartFilterCallback;
57
- dataMap?: UnitaryMapCallback<CategoricalChartDataItem>;
57
+ dataMap?: ChartDataMapCallback;
58
58
  postFilter?: ChartFilterCallback;
59
+ removeEmpty?: boolean;
59
60
  }
60
61
 
61
- interface BaseCategoricalChartProps extends BaseChartComponentProps {
62
- data: CategoricalChartDataType;
63
- removeEmpty?: boolean;
62
+ // ################### COMPONENT PROPS #####################
63
+ export interface BaseChartComponentProps {
64
+ height: number;
64
65
  }
65
66
 
67
+ export interface BaseCategoricalChartProps extends BaseChartComponentProps, CategoricalChartDataWithTransforms {}
68
+
66
69
  export interface PieChartProps extends BaseCategoricalChartProps {
67
70
  colorTheme?: keyof ChartTheme['pie'];
68
71
  sort?: boolean;
@@ -1,7 +1,7 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import type { Feature as GeoJSONFeatureType } from 'geojson';
3
3
 
4
- import { BaseChartComponentProps, CategoricalChartDataType } from './chartTypes';
4
+ import { BaseCategoricalChartProps, BaseChartComponentProps } from './chartTypes';
5
5
  import type { GeoJSONPolygonOnlyFeatureCollection } from './geoJSONTypes';
6
6
 
7
7
  export interface GeoPointDataItem {
@@ -42,8 +42,8 @@ export interface ChoroplethMapColorModeDiscrete {
42
42
  legendItems: MapDiscreteLegendItem[];
43
43
  }
44
44
 
45
- export interface ChoroplethMapProps extends BaseMapProps {
46
- data: CategoricalChartDataType; // heatmaps are 'categorical' + geographical
45
+ // heatmaps are 'categorical' + geographical:
46
+ export interface ChoroplethMapProps extends BaseCategoricalChartProps, BaseMapProps {
47
47
  features: GeoJSONPolygonOnlyFeatureCollection;
48
48
  colorMode: ChoroplethMapColorModeContinuous | ChoroplethMapColorModeDiscrete;
49
49
  categoryProp: string;
@@ -1,4 +1,6 @@
1
+ import { useMemo } from 'react';
1
2
  import { RADIAN } from '../constants/chartConstants';
3
+ import type { CategoricalChartDataWithTransforms } from '../types/chartTypes';
2
4
 
3
5
  export const polarToCartesian = (cx: number, cy: number, radius: number, angle: number) => {
4
6
  return {
@@ -6,3 +8,30 @@ export const polarToCartesian = (cx: number, cy: number, radius: number, angle:
6
8
  y: cy + Math.sin(-RADIAN * angle) * radius,
7
9
  };
8
10
  };
11
+
12
+ export const useTransformedChartData = (
13
+ {
14
+ data: originalData,
15
+ preFilter,
16
+ dataMap,
17
+ postFilter,
18
+ removeEmpty: origRemoveEmpty,
19
+ }: CategoricalChartDataWithTransforms,
20
+ defaultRemoveEmpty = true,
21
+ sortY = false,
22
+ ) =>
23
+ useMemo(() => {
24
+ const removeEmpty = origRemoveEmpty ?? defaultRemoveEmpty;
25
+
26
+ let data = [...originalData];
27
+
28
+ if (preFilter) data = data.filter(preFilter);
29
+ if (dataMap) data = data.map(dataMap);
30
+ if (postFilter) data = data.filter(postFilter);
31
+
32
+ if (removeEmpty) data = data.filter((e) => e.y !== 0);
33
+
34
+ if (sortY) data.sort((a, b) => a.y - b.y);
35
+
36
+ return data;
37
+ }, [originalData, preFilter, dataMap, postFilter, origRemoveEmpty]);
package/webpack.config.js CHANGED
@@ -12,7 +12,14 @@ const config = {
12
12
  },
13
13
  module: {
14
14
  rules: [
15
- { test: /\.[tj](sx|s)?$/, use: { loader: 'ts-loader' }, exclude: /node_modules/ },
15
+ {
16
+ test: /\.[tj](sx|s)?$/,
17
+ loader: 'ts-loader',
18
+ exclude: /node_modules/,
19
+ options: {
20
+ configFile: 'test/tsconfig.json'
21
+ }
22
+ },
16
23
  {
17
24
  test: /\.html$/i,
18
25
  loader: 'html-loader',
@@ -43,6 +50,7 @@ const config = {
43
50
  devtool: 'source-map',
44
51
  devServer: {
45
52
  static: './test/dist',
53
+ historyApiFallback: true,
46
54
  },
47
55
  resolve: {
48
56
  alias: {