Skip to content

Commit

Permalink
feat: translate scatter chart legend in skills tab
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-ammar committed Sep 13, 2024
1 parent 2d455ab commit 2d883e7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/components/AdvanceAnalyticsV2/charts/ChartWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ ChartWrapper.propTypes = {
isFetching: PropTypes.bool.isRequired,
isError: PropTypes.bool.isRequired,
chartType: PropTypes.oneOf(['ScatterChart', 'LineChart', 'BarChart']).isRequired,
chartProps: PropTypes.object.isRequired,
chartProps: PropTypes.shape({
data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
xKey: PropTypes.string.isRequired,
yKey: PropTypes.string.isRequired,
colorKey: PropTypes.string.isRequired,
colorMap: PropTypes.objectOf(PropTypes.string).isRequired,
hovertemplate: PropTypes.string.isRequired,
xAxisTitle: PropTypes.string,
yAxisTitle: PropTypes.string,
markerSizeKey: PropTypes.string,
customDataKeys: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
loadingMessage: PropTypes.string.isRequired,
};

Expand Down
7 changes: 5 additions & 2 deletions src/components/AdvanceAnalyticsV2/charts/ScatterChart.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useMemo } from 'react';
import Plot from 'react-plotly.js';
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import messages from '../messages';

/**
* ScatterChart component renders a scatter chart using Plotly.js.
Expand All @@ -21,6 +23,7 @@ import PropTypes from 'prop-types';
const ScatterChart = ({
data, xKey, yKey, colorKey, colorMap, hovertemplate, xAxisTitle, yAxisTitle, markerSizeKey, customDataKeys,
}) => {
const intl = useIntl();
const categories = Object.keys(colorMap);

const traces = useMemo(() => categories.map(category => {
Expand All @@ -30,15 +33,15 @@ const ScatterChart = ({
y: filteredData.map(item => item[yKey]),
type: 'scatter',
mode: 'markers',
name: category,
name: messages[category] ? intl.formatMessage(messages[category]) : category,
marker: {
color: colorMap[category],
size: filteredData.map(item => item[markerSizeKey] * 0.015).map(size => (size < 5 ? size + 6 : size)),
},
customdata: customDataKeys.length ? filteredData.map(item => customDataKeys.map(key => item[key])) : [],
hovertemplate,
};
}), [data, xKey, yKey, colorKey, colorMap, hovertemplate, categories, markerSizeKey, customDataKeys]);
}), [data, xKey, yKey, colorKey, colorMap, hovertemplate, categories, markerSizeKey, customDataKeys, intl]);

const layout = {
margin: { t: 0 },
Expand Down
20 changes: 20 additions & 0 deletions src/components/AdvanceAnalyticsV2/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ const messages = defineMessages({
id: 'advance.analytics.learning.hours.label',
defaultMessage: 'Learning Hours',
},
'Common Skill': {
id: 'advance.analytics.common.skill.label',
defaultMessage: 'Common Skill',
},
'Specialized Skill': {
id: 'advance.analytics.specialized.skill.label',
defaultMessage: 'Specialized Skill',
},
'Hard Skill': {
id: 'advance.analytics.hard.skill.label',
defaultMessage: 'Hard Skill',
},
'Soft Skill': {
id: 'advance.analytics.soft.skill.label',
defaultMessage: 'Soft Skill',
},
Certification: {
id: 'advance.analytics.certification.label',
defaultMessage: 'Certification',
},
});

export default messages;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
render, screen, waitFor, within,
} from '@testing-library/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
render, screen, waitFor, within,
} from '@testing-library/react';
Expand Down
1 change: 0 additions & 1 deletion src/components/AdvanceAnalyticsV2/tabs/Enrollments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ const Enrollments = ({
colorMap: chartColorMap,
xAxisTitle: '',
yAxisTitle: 'Number of Enrollments',
hovertemplate: 'Subject: %{x}<br>Enrolls: %{y}',
hovertemplate: constructChartHoverTemplate(intl, {
subject: '%{x}',
enrollments: '%{y}',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
render, screen, waitFor, within,
} from '@testing-library/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
render, screen, waitFor, within,
} from '@testing-library/react';
Expand Down

0 comments on commit 2d883e7

Please sign in to comment.