Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i18n): new locale interface, and translation configs #1710

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fbbfde3
feat(localeInterface):addition of locale interface in options and and…
RiyaJethwa Dec 27, 2023
b54bc7a
formatting rectified
RiyaJethwa Dec 28, 2023
4894219
Merge branch 'master' into enhancement-localeInterface
RiyaJethwa Jan 12, 2024
1701c4e
Merge branch 'master' into enhancement-localeInterface
RiyaJethwa Jan 15, 2024
568da6a
feat(localeOptions):updated translations prop and addition of numberF…
RiyaJethwa Jan 22, 2024
b8813a6
Merge branch 'carbon-design-system:master' into enhancement-localeInt…
RiyaJethwa Jan 22, 2024
d7ef3df
fix(type):deleted unrequired imports
RiyaJethwa Jan 22, 2024
0ca33ac
fix(type):updated branch
RiyaJethwa Jan 22, 2024
40b9032
feat(localeOptions):updated locale object and locale conversion for axis
RiyaJethwa Jan 29, 2024
4fae08f
Merge branch 'carbon-design-system:master' into enhancement-localeInt…
RiyaJethwa Jan 29, 2024
57cf915
Merge branch 'carbon-design-system:master' into enhancement-localeInt…
RiyaJethwa Feb 3, 2024
04bc907
fix(localeInterface):axis ticks format
RiyaJethwa Feb 5, 2024
f6259bb
Merge branch 'carbon-design-system:master' into enhancement-localeInt…
RiyaJethwa Feb 5, 2024
2db59ad
fix(type):updated branch
RiyaJethwa Feb 5, 2024
e799a2a
fix(localeInterface):change in optionsObject property structure
RiyaJethwa Feb 7, 2024
2d8273d
fix(localeInterface):added locale demo
RiyaJethwa Feb 8, 2024
72459c4
fix(localeInterface):date translation for modal and colorScale
RiyaJethwa Feb 12, 2024
ab1a29c
fix(model):removing unused imports
RiyaJethwa Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/core/src/components/axes/ruler-binned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class BinnedRuler extends Ruler {
renderType = RenderTypes.SVG

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
showRuler(event: CustomEvent, [x, y]: [number, number]) {
const svg = this.parent

Expand All @@ -32,7 +32,12 @@ export class BinnedRuler extends Ruler {
const ruler = DOMUtils.appendOrSelect(svg, 'g.ruler').attr('aria-label', 'ruler')
const rulerLine = DOMUtils.appendOrSelect(ruler, 'line.ruler-line')

const dataPointElements = svg.selectAll('[role=graphics-symbol]') as Selection<SVGGraphicsElement, any, Element, any>
const dataPointElements = svg.selectAll('[role=graphics-symbol]') as Selection<
SVGGraphicsElement,
any,
Element,
any
>

const elementsToHighlight = dataPointElements.filter((d: any) => {
if (
Expand Down Expand Up @@ -95,7 +100,10 @@ export class BinnedRuler extends Ruler {
...(getProperty(options, 'tooltip', 'showTotal') === true
? [
{
label: get(options, 'tooltip.totalLabel') || 'Total',
label:
get(options, 'locale.translations.total') ||
get(options, 'tooltip.totalLabel') ||
'Total',
value: activeDataGroupNames.reduce(
(accum: number, currentValue: any) =>
accum + parseFloat(get(sampleMatchData, `data.${currentValue}`)),
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/components/axes/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class Toolbar extends Component {
.classed('cds--overflow-menu-options__option--disabled', (d: any) => d.shouldBeDisabled())
.attr('aria-disabled', (d: any) => d.shouldBeDisabled())
.selectAll('button')
.text((d: any) => d.text)
.text((d: any) => d.title)
}

isOverflowMenuOpen() {
Expand Down Expand Up @@ -366,7 +366,6 @@ export class Toolbar extends Component {
getControlConfigs() {
const numberOfIcons = getProperty(this.getOptions(), 'toolbar', 'numberOfIcons') - 1
const controls = getProperty(this.getOptions(), 'toolbar', 'controls')

const overflowSpecificControls: any[] = []
const buttonList: any[] = []
const overflowList: any[] = []
Expand Down Expand Up @@ -467,6 +466,12 @@ export class Toolbar extends Component {
!this.services.zoom.isEmptyState()

const displayData = this.model.getDisplayData()
const options = this.model.getOptions()
const { toolbarExportAsCSV, toolbarExportAsJPG, toolbarExportAsPNG } = getProperty(
options,
'locale',
'translations'
)

let controlConfig: any
switch (controlType) {
Expand Down Expand Up @@ -538,7 +543,7 @@ export class Toolbar extends Component {
case ToolbarControlTypes.EXPORT_CSV:
controlConfig = {
id: 'toolbar-export-CSV',
title: 'Export as CSV',
title: toolbarExportAsCSV,
shouldBeDisabled: () => false,
iconSVG: {
content: this.getControlIconByType(controlType)
Expand All @@ -549,7 +554,7 @@ export class Toolbar extends Component {
case ToolbarControlTypes.EXPORT_PNG:
controlConfig = {
id: 'toolbar-export-PNG',
title: 'Export as PNG',
title: toolbarExportAsPNG,
shouldBeDisabled: () => false,
iconSVG: {
content: this.getControlIconByType(controlType)
Expand All @@ -560,7 +565,7 @@ export class Toolbar extends Component {
case ToolbarControlTypes.EXPORT_JPG:
controlConfig = {
id: 'toolbar-export-JPG',
title: 'Export as JPG',
title: toolbarExportAsJPG,
shouldBeDisabled: () => false,
iconSVG: {
content: this.getControlIconByType(controlType)
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/components/essentials/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ export class Modal extends Component {
getModalHTML() {
const options = this.model.getOptions()

const { toolbarTabularModalTitle } = getProperty(options, 'locale', 'translations')

const chartprefix = getProperty(options, 'style', 'prefix')

const tableArray = this.model.getTabularDataArray()

return `
<div class="cds--modal-container cds--modal-container">
<div class="cds--modal-header cds--modal-header">
<p class="cds--modal-header__label cds--type-delta cds--modal-header__label cds--type-delta" id="modal-title">Tabular representation</p>
<p class="cds--modal-header__label cds--type-delta cds--modal-header__label cds--type-delta" id="modal-title">${toolbarTabularModalTitle}</p>

<p class="cds--modal-header__heading cds--type-beta cds--modal-header__heading cds--type-beta" id="modal-description">${
options.title
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/components/essentials/tooltip-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ export class AxisChartsTooltip extends Tooltip {
)
}

console.log(options)

items.push({
label: options.tooltip.groupLabel,
label: get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel'),
value: datum[groupMapsTo],
color: this.model.getFillColor(datum[groupMapsTo]),
class: this.model.getColorClassName({
Expand Down Expand Up @@ -113,7 +115,10 @@ export class AxisChartsTooltip extends Tooltip {
// use the primary/only range id
const rangeIdentifier = cartesianScales.getRangeIdentifier()
items.push({
label: get(options, 'tooltip.totalLabel') || 'Total',
label:
get(options, 'locale.translations.total') ||
get(options, 'tooltip.totalLabel') ||
'Total',
value: data.reduce(
(accumulator: number, datum: any) => accumulator + datum[rangeIdentifier],
0
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/components/graphs/boxplot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { select } from 'd3'
import { flipDomainAndRangeBasedOnOrientation, generateSVGPathString } from '@/tools'
import { flipDomainAndRangeBasedOnOrientation, generateSVGPathString, getProperty } from '@/tools'
import { boxplot as boxplotConfigs } from '@/configuration'
import { BoxplotChartModel } from '@/model/boxplot'
import { Component } from '@/components/component'
import {
CartesianOrientations,
ColorClassNameTypes,
Events,
RenderTypes
} from '@/interfaces/enums'
import { CartesianOrientations, ColorClassNameTypes, Events, RenderTypes } from '@/interfaces/enums'
import { Roles } from '@/interfaces/a11y'

export class Boxplot extends Component {
Expand Down Expand Up @@ -339,7 +334,9 @@ export class Boxplot extends Component {
hoveredElement,
items: [
{
label: options.tooltip.groupLabel,
label:
getProperty(options, 'locale', 'translations', 'group') ||
getProperty(options, 'tooltip', 'groupLabel'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getProperty(options, 'tooltip', 'groupLabel'),
getProperty(options, 'tooltip', 'groupLabel') || 'Group',

value: datum[groupMapsTo],
class: self.model.getColorClassName({
classNameTypes: [ColorClassNameTypes.TOOLTIP]
Expand Down Expand Up @@ -447,7 +444,9 @@ export class Boxplot extends Component {
hoveredElement,
items: [
{
label: options.tooltip.groupLabel,
label:
getProperty(options, 'locale', 'translations', 'group') ||
getProperty(options, 'tooltip', 'groupLabel'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getProperty(options, 'tooltip', 'groupLabel'),
getProperty(options, 'tooltip', 'groupLabel') || 'Group',

value: datum[groupMapsTo],
class: self.model.getColorClassName({
classNameTypes: [ColorClassNameTypes.TOOLTIP]
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/components/graphs/bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class Bullet extends Component {
animate
})
)
.attr('d', ({ datum: d, value }: { datum: any, value: any }) => {
.attr('d', ({ datum: d, value }: { datum: any; value: any }) => {
/*
* Orientation support for horizontal/vertical bar charts
* Determine coordinates needed for a vertical set of paths
Expand Down Expand Up @@ -336,14 +336,19 @@ export class Bullet extends Component {
})

const performanceAreaTitles = getProperty(options, 'bullet', 'performanceAreaTitles')
const matchingRangeIndex = (self.model as BulletChartModel).getMatchingRangeIndexForDatapoint(datum)
const matchingRangeIndex = (
self.model as BulletChartModel
).getMatchingRangeIndexForDatapoint(datum)

self.services.events.dispatchEvent(Events.Tooltip.SHOW, {
event,
hoveredElement,
items: [
{
label: options.tooltip.groupLabel || 'Group',
label:
getProperty(options, 'locale', 'translations', 'group') ||
getProperty(options, 'tooltip', 'groupLabel') ||
'Group',
value: datum[groupMapsTo],
class: self.model.getColorClassName({
classNameTypes: [ColorClassNameTypes.TOOLTIP],
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/components/graphs/circle-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ export class CirclePack extends Component {
.size([width, height])
.padding((d: any) => {
// add 3 px to account for the stroke width 1.5px
return d.depth >= 1 ? circlePackConfigs.padding.children + 3 : circlePackConfigs.padding.mainGroup + 3
return d.depth >= 1
? circlePackConfigs.padding.children + 3
: circlePackConfigs.padding.mainGroup + 3
})

const nodeData = packLayout(root)
.descendants()
.splice(1)
.filter((node) => {
.filter(node => {
// filter based on hierarchy level
return node.depth <= hierarchyLevel
})
Expand Down Expand Up @@ -258,7 +260,10 @@ export class CirclePack extends Component {
const options = self.model.getOptions()
totalValue = [
{
label: get(options, 'tooltip.totalLabel') || 'Total',
label:
get(options, 'locale.translations.total') ||
get(options, 'tooltip.totalLabel') ||
'Total',
value: datum.value,
bold: true
}
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/components/graphs/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class Heatmap extends Component {
eventsFragment.addEventListener(Events.Axis.LABEL_BLUR, this.handleAxisMouseOut)
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render(animate = true) {
const svg = this.getComponentContainer({ withinChartClip: true })
// Lower the chart so the axes are always visible
Expand Down Expand Up @@ -102,7 +102,8 @@ export class Heatmap extends Component {
`translate(${mainXScale(d[domainIdentifier])}, ${mainYScale(d[rangeIdentifier])})`
)
.append('rect')
.attr('class', (d: any) => this.model.getColorClassName({
.attr('class', (d: any) =>
this.model.getColorClassName({
value: d.value,
originalClassName: `heat-${d.index}`
})
Expand Down Expand Up @@ -202,7 +203,8 @@ export class Heatmap extends Component {
const self = this
const { cartesianScales } = this.services
const options = this.getOptions()
const totalLabel = get(options, 'tooltip.totalLabel')
const totalLabel =
get(options, 'locale.translations.total') || get(options, 'tooltip.totalLabel') || 'Total'

const domainIdentifier = cartesianScales.getDomainIdentifier()
const rangeIdentifier = cartesianScales.getRangeIdentifier()
Expand Down Expand Up @@ -252,7 +254,7 @@ export class Heatmap extends Component {
value: datum[rangeIdentifier]
},
{
label: totalLabel || 'Total',
label: totalLabel,
value: datum['value'],
color: hoveredElement.style('fill')
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/graphs/wordcloud.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extent, scaleLinear, select } from 'd3'
import cloud from 'd3-cloud'
import { debounce } from 'lodash-es'
import { debounce, get } from 'lodash-es'
import { Component } from '@/components/component'
import { DOMUtils } from '@/services/essentials/dom-utils'
import { Events, ColorClassNameTypes, RenderTypes } from '@/interfaces/enums'
Expand Down Expand Up @@ -217,7 +217,8 @@ export class WordCloud extends Component {
value: datum.value
},
{
label: options.tooltip.groupLabel,
label:
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel'),
get(options, 'locale.translations.group') || get(options, 'tooltip.groupLabel') || 'Group',

value: datum[groupMapsTo],
class: self.model.getColorClassName({
classNameTypes: [ColorClassNameTypes.TOOLTIP],
Expand Down
45 changes: 32 additions & 13 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
StackedBarOptions,
ToolbarOptions,
ZoomBarsOptions,
Locale
} from '@/interfaces/components'

/*
Expand All @@ -70,6 +71,23 @@ const standardTruncationOptions = {
numCharacter: 14
}

/**
* Locale options
*/
const locale: Locale = {
code: navigator.language, // read from browser's navigator.language
number: value => value.toLocaleString(navigator.language), // based on code property if specified
date: value => value.toLocaleDateString(navigator.language), // based on code property if specified
translations: {
group: 'Group',
total: 'Total',
toolbarTabularModalTitle: 'Tabular representation',
toolbarExportAsCSV: 'Export to CSV',
toolbarExportAsJPG: 'Export to JPG',
toolbarExportAsPNG: 'Export to PNG'
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RiyaJethwa pls make this object a bit more organized, could be this way

{
	group: 'Group',
	total: 'Total',
        tabularRep: {
             title: "Tabular representation'",
	    downloadAsCSV: 'Download as CSV'
        },
        toolbar: {
	     exportAsCSV: 'Export to CSV',
	     exportAsJPG: 'Export to JPG',
	     exportAsPNG: 'Export to PNG',
        }
}

}

/**
* Legend options
*/
Expand Down Expand Up @@ -179,6 +197,7 @@ const chart: BaseChartOptions = {
theme: ChartTheme.WHITE,
tooltip: baseTooltip,
legend,
locale,
style: {
prefix: 'cc'
},
Expand Down Expand Up @@ -229,9 +248,9 @@ const chart: BaseChartOptions = {
*/
const thematicChart: ThematicChartOptions = merge({}, chart, {
thematic: {
projection: Projection.geoNaturalEarth1,
},
});
projection: Projection.geoNaturalEarth1
}
})

/**
* Options common to any chart with an axis
Expand Down Expand Up @@ -474,10 +493,10 @@ const gaugeChart: GaugeChartOptions = merge({}, chart, {
const donutChart: DonutChartOptions = merge({}, pieChart, {
donut: {
center: {
numberFontSize: (radius) => `${Math.min((radius / 100) * 24, 24)}px`,
titleFontSize: (radius) => `${Math.min((radius / 100) * 15, 15)}px`,
titleYPosition: (radius) => Math.min((radius / 80) * 20, 20),
numberFormatter: (number) => Math.floor(number).toLocaleString()
numberFontSize: radius => `${Math.min((radius / 100) * 24, 24)}px`,
titleFontSize: radius => `${Math.min((radius / 100) * 15, 15)}px`,
titleYPosition: radius => Math.min((radius / 80) * 20, 20),
numberFormatter: number => Math.floor(number).toLocaleString()
},
alignment: Alignments.LEFT
}
Expand Down Expand Up @@ -520,7 +539,7 @@ const radarChart: RadarChartOptions = merge({}, chart, {
gridline: {
enabled: true
},
valueFormatter: (value) => (value !== null && value !== undefined ? value : 'N/A')
valueFormatter: value => (value !== null && value !== undefined ? value : 'N/A')
}
} as RadarChartOptions)

Expand Down Expand Up @@ -589,10 +608,10 @@ const heatmapChart: HeatmapChartOptions = merge({}, chart, {
const choroplethChart: ChoroplethChartOptions = merge({}, thematicChart, {
choropleth: {
colorLegend: {
type: 'linear',
},
},
} as ChoroplethChartOptions);
type: 'linear'
}
}
} as ChoroplethChartOptions)

export const options = {
alluvialChart,
Expand Down Expand Up @@ -623,7 +642,7 @@ export const options = {
thematicChart,
treeChart,
treemapChart,
wordCloudChart,
wordCloudChart
}

export {
Expand Down
Loading