@oliasoft-open-source/charts-library 2.17.0-beta-2 → 2.17.0-beta-3

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/index.js CHANGED
@@ -5,8 +5,7 @@
5
5
  import ScatterChart from './src/components/scatter-chart/scatter-chart';
6
6
 
7
7
  export { LineChart } from './src/components/line-chart/line-chart';
8
- export { initializeLineChart } from './src/components/line-chart/utils/initialize/initialize-line-chart';
9
- export { updateTranslations } from './src/components/line-chart/utils/translations/translations';
8
+ export { initializeLineChart } from './src/components/line-chart/initialize/initialize-line-chart';
10
9
 
11
10
  export { PieChart } from './src/components/pie-chart/pie-chart';
12
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "2.17.0-beta-2",
3
+ "version": "2.17.0-beta-3",
4
4
  "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
5
  "homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
6
6
  "bugs": {
package/release-notes.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Charts Library Release Notes
2
2
 
3
3
  ## 2.17.0
4
- - Added initialize logic, for improve translations
4
+ - Added initialize logic, for improve getTranslations
5
5
 
6
6
  ## 2.15.0
7
7
  - Added translation, by provider handled([OW-11237](https://oliasoft.atlassian.net/browse/OW-11237))
@@ -8,4 +8,5 @@ export const ZOOM_BOX_BACKGROUND_COLOR = 'rgba(0, 0, 0, 0.1)';
8
8
  export const DOUBLE_CLICK = 'dblclick';
9
9
  export const INIT_KEYS = {
10
10
  TRANSLATIONS: 'translations',
11
+ LANGUAGE_KEY: 'languageKey',
11
12
  };
@@ -1,16 +1,17 @@
1
- import { INIT_KEYS } from '../../constants/line-chart-consts';
2
- import { defaultTranslations } from '../../constants/default-translations';
1
+ import { INIT_KEYS } from '../constants/line-chart-consts';
2
+ import { getTranslations } from '../utils/translations/get-translations';
3
3
 
4
4
  const config = {
5
- [INIT_KEYS.TRANSLATIONS]: defaultTranslations,
5
+ [INIT_KEYS.TRANSLATIONS]: getTranslations(),
6
+ [INIT_KEYS.LANGUAGE_KEY]: 'en',
6
7
  };
7
8
 
8
9
  /**
9
10
  * Retrieve the value for the given key from the config object.
10
11
  * @param {string} key - The key to access the corresponding value in the config object.
11
- * @returns {*} - The value associated with the given key in the config object.
12
+ * @returns {*} - The value associated with the given key in the config object or config.
12
13
  */
13
- export const getConfig = (key) => config[key];
14
+ export const getConfig = (key) => (key ? config[key] : config);
14
15
 
15
16
  /**
16
17
  * Set a new value for the given key in the config object.
@@ -0,0 +1,25 @@
1
+ import { INIT_KEYS } from '../constants/line-chart-consts';
2
+ import { setConfig } from './config';
3
+ import { isPrimitiveValue } from '../utils/line-chart-utils';
4
+ import { getTranslations } from '../utils/translations/get-translations';
5
+
6
+ /**
7
+ * Initialize the charts library with the provided configurations.
8
+ * This function will store the configuration options in a config object.
9
+ * @param {object} options - An object containing the configuration options for the library.
10
+ * @param {object} options.getTranslations - The getTranslations to be used in the library.
11
+ * @param {string} options.languageKey - The language key to be stored in the config object, used for getTranslations.
12
+ * @param {...object} options - Any additional options to be stored in the config object.
13
+ */
14
+ export const initializeLineChart = ({ languageKey = 'en', ...options }) => {
15
+ setConfig(INIT_KEYS.LANGUAGE_KEY, languageKey);
16
+
17
+ Object.entries(options).forEach(([key, value]) => {
18
+ if (key === INIT_KEYS.TRANSLATIONS) {
19
+ setConfig(key, getTranslations(value));
20
+ } else {
21
+ const newValue = isPrimitiveValue(value) ? value : { ...value };
22
+ setConfig(key, newValue);
23
+ }
24
+ });
25
+ };
@@ -29,8 +29,7 @@ import { useChartOptions } from './hooks/use-chart-options';
29
29
  import { useChartPlugins } from './hooks/use-chart-plugins';
30
30
  import { generateKey } from './utils/line-chart-utils';
31
31
  import { useChartState } from './state/use-chart-state';
32
- import { INIT_KEYS } from './constants/line-chart-consts';
33
- import { getConfig } from './utils/initialize/config';
32
+ import { getConfig } from './initialize/config';
34
33
 
35
34
  ChartJS.register(
36
35
  LinearScale,
@@ -56,7 +55,8 @@ const LineChart = (props) => {
56
55
  setDefaultTheme();
57
56
  const chartRef = useRef(null);
58
57
  const { table } = props;
59
- const translations = getConfig(INIT_KEYS.TRANSLATIONS);
58
+ const { translations, languageKey } = getConfig();
59
+
60
60
  const chart = getDefaultProps(props);
61
61
  const {
62
62
  data: { datasets },
@@ -116,6 +116,7 @@ const LineChart = (props) => {
116
116
  state.enableDragPoints,
117
117
  state.zoomEnabled,
118
118
  state.panEnabled,
119
+ languageKey,
119
120
  ])}
120
121
  className={getClassName(chartStyling, styles)}
121
122
  style={{
@@ -15,7 +15,7 @@ import { generateRandomColor } from '../../../helpers/chart-utils';
15
15
  * @param {Array} datasets - The initial datasets for the line chart.
16
16
  * @param {Object} state - The state object containing chart settings (e.g., lineEnabled, pointsEnabled, axes).
17
17
  * @param {Object} options - The options object containing additional settings (e.g., annotations, graph).
18
- * @param {Object} translations - The translations object with the label property
18
+ * @param {Object} translations - The getTranslations object with the label property
19
19
  * @returns {Array} - The generated line chart datasets with applied settings and configurations.
20
20
  */
21
21
  export const generateLineChartDatasets = (
@@ -68,3 +68,14 @@ export const generateKey = (values) => {
68
68
  const key = values.join('');
69
69
  return key;
70
70
  };
71
+
72
+ /**
73
+ * Checks if a value is a primitive value (which includes strings, numbers, booleans, and null).
74
+ * @param {*} value - The value to check.
75
+ * @returns {boolean} - Returns true if the value is a primitive value, otherwise false.
76
+ */
77
+ export const isPrimitiveValue = (value) =>
78
+ typeof value === 'string' ||
79
+ typeof value === 'number' ||
80
+ typeof value === 'boolean' ||
81
+ value === null;
@@ -0,0 +1,17 @@
1
+ import { defaultTranslations } from '../../constants/default-translations';
2
+
3
+ /**
4
+ * Merges custom getTranslations with the default getTranslations.
5
+ * If a custom translation is provided for a key, it will override the default one.
6
+ * @param {object} translations - Custom getTranslations.
7
+ * @returns {object} - The resulting getTranslations object, containing both default and custom getTranslations.
8
+ */
9
+ export const getTranslations = (translations = {}) => {
10
+ return Object.keys(defaultTranslations).reduce(
11
+ (acc, key) => ({
12
+ ...acc,
13
+ [key]: translations[key] || defaultTranslations[key],
14
+ }),
15
+ {},
16
+ );
17
+ };
@@ -1,18 +0,0 @@
1
- import { translations } from '../translations/translations';
2
- import { INIT_KEYS } from '../../constants/line-chart-consts';
3
- import { setConfig } from './config';
4
-
5
- /**
6
- * Initialize the charts library with the provided configurations.
7
- * This function will store the configuration options in a config object.
8
- * @param {object} options - An object containing the configuration options for the library.
9
- */
10
- export const initializeLineChart = (options = {}) => {
11
- Object.entries(options).forEach(([key, value]) => {
12
- if (key === INIT_KEYS.TRANSLATIONS) {
13
- setConfig(INIT_KEYS.TRANSLATIONS, translations(value));
14
- } else {
15
- setConfig(INIT_KEYS.TRANSLATIONS, { ...value });
16
- }
17
- });
18
- };
@@ -1,30 +0,0 @@
1
- import { defaultTranslations } from '../../constants/default-translations';
2
- import { INIT_KEYS } from '../../constants/line-chart-consts';
3
- import { setConfig } from '../initialize/config';
4
-
5
- /**
6
- * Merges custom translations with the default translations.
7
- * If a custom translation is provided for a key, it will override the default one.
8
- * @param {object} translations - Custom translations.
9
- * @returns {object} - The resulting translations object, containing both default and custom translations.
10
- */
11
- export const translations = (translations = {}) => {
12
- return Object.keys(defaultTranslations).reduce(
13
- (acc, key) => ({
14
- ...acc,
15
- [key]: translations[key] || defaultTranslations[key],
16
- }),
17
- {},
18
- );
19
- };
20
-
21
- /**
22
- * Updates the translations configuration with new translations.
23
- *
24
- * @param {object} newTranslations - The new translations to be added.
25
- * @returns {void}
26
- */
27
- export function updateTranslations(newTranslations) {
28
- const updatedTranslations = translations(newTranslations);
29
- setConfig(INIT_KEYS.TRANSLATIONS, updatedTranslations);
30
- }