@oliasoft-open-source/charts-library 2.17.0-beta-1 → 2.17.0-beta-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.
package/index.js CHANGED
@@ -6,6 +6,7 @@ import ScatterChart from './src/components/scatter-chart/scatter-chart';
6
6
 
7
7
  export { LineChart } from './src/components/line-chart/line-chart';
8
8
  export { initializeLineChart } from './src/components/line-chart/utils/initialize/initialize-line-chart';
9
+ export { updateTranslations } from './src/components/line-chart/utils/translations/translations';
9
10
 
10
11
  export { PieChart } from './src/components/pie-chart/pie-chart';
11
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "2.17.0-beta-1",
3
+ "version": "2.17.0-beta-2",
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": {
@@ -29,8 +29,8 @@ 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 { getConfig } from './utils/initialize/initialize-line-chart';
33
32
  import { INIT_KEYS } from './constants/line-chart-consts';
33
+ import { getConfig } from './utils/initialize/config';
34
34
 
35
35
  ChartJS.register(
36
36
  LinearScale,
@@ -55,7 +55,7 @@ ChartJS.register(
55
55
  const LineChart = (props) => {
56
56
  setDefaultTheme();
57
57
  const chartRef = useRef(null);
58
- const { table, translations: translationsRaw } = props;
58
+ const { table } = props;
59
59
  const translations = getConfig(INIT_KEYS.TRANSLATIONS);
60
60
  const chart = getDefaultProps(props);
61
61
  const {
@@ -0,0 +1,22 @@
1
+ import { INIT_KEYS } from '../../constants/line-chart-consts';
2
+ import { defaultTranslations } from '../../constants/default-translations';
3
+
4
+ const config = {
5
+ [INIT_KEYS.TRANSLATIONS]: defaultTranslations,
6
+ };
7
+
8
+ /**
9
+ * Retrieve the value for the given key from the config object.
10
+ * @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
+ */
13
+ export const getConfig = (key) => config[key];
14
+
15
+ /**
16
+ * Set a new value for the given key in the config object.
17
+ * @param {string} key - The key to access the corresponding value in the config object.
18
+ * @param {*} newValue - The new value to be set for the given key.
19
+ */
20
+ export const setConfig = (key, newValue) => {
21
+ config[key] = newValue;
22
+ };
@@ -1,16 +1,6 @@
1
- import { getTranslations } from '../get-translations/get-translations';
1
+ import { translations } from '../translations/translations';
2
2
  import { INIT_KEYS } from '../../constants/line-chart-consts';
3
-
4
- const config = {
5
- [INIT_KEYS.TRANSLATIONS]: getTranslations(),
6
- };
7
-
8
- /**
9
- * Retrieve the value for the given key from the config object.
10
- * @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
- */
13
- export const getConfig = (key) => config[key];
3
+ import { setConfig } from './config';
14
4
 
15
5
  /**
16
6
  * Initialize the charts library with the provided configurations.
@@ -20,9 +10,9 @@ export const getConfig = (key) => config[key];
20
10
  export const initializeLineChart = (options = {}) => {
21
11
  Object.entries(options).forEach(([key, value]) => {
22
12
  if (key === INIT_KEYS.TRANSLATIONS) {
23
- config[key] = getTranslations(value);
13
+ setConfig(INIT_KEYS.TRANSLATIONS, translations(value));
24
14
  } else {
25
- config[key] = { ...value };
15
+ setConfig(INIT_KEYS.TRANSLATIONS, { ...value });
26
16
  }
27
17
  });
28
18
  };
@@ -1,4 +1,6 @@
1
1
  import { defaultTranslations } from '../../constants/default-translations';
2
+ import { INIT_KEYS } from '../../constants/line-chart-consts';
3
+ import { setConfig } from '../initialize/config';
2
4
 
3
5
  /**
4
6
  * Merges custom translations with the default translations.
@@ -6,7 +8,7 @@ import { defaultTranslations } from '../../constants/default-translations';
6
8
  * @param {object} translations - Custom translations.
7
9
  * @returns {object} - The resulting translations object, containing both default and custom translations.
8
10
  */
9
- export const getTranslations = (translations = {}) => {
11
+ export const translations = (translations = {}) => {
10
12
  return Object.keys(defaultTranslations).reduce(
11
13
  (acc, key) => ({
12
14
  ...acc,
@@ -15,3 +17,14 @@ export const getTranslations = (translations = {}) => {
15
17
  {},
16
18
  );
17
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
+ }