Skip to content

Commit c0a0769

Browse files
committed
Pie chart: use translated label for missing value
1 parent 5104983 commit c0a0769

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

src/client/components/facet_bar/ChartDialog.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const useStyles = makeStyles(theme => ({
2020
const ChartDialog = props => {
2121
const {
2222
fetchData, facetID, rawData, rawDataUpdateID, createChartData, facetClass,
23-
resultClass, fetching, tooltip, title, xaxisTitle, yaxisTitle, seriesTitle, lineChartConfig
23+
resultClass, fetching, tooltip, title, xaxisTitle, yaxisTitle, seriesTitle, lineChartConfig,
24+
layoutConfig
2425
} = props
2526
let xaxisType = null; let xaxisTickAmount = null; let stroke = null
2627
if (lineChartConfig) {
@@ -72,6 +73,7 @@ const ChartDialog = props => {
7273
xaxisType={xaxisType}
7374
xaxisTickAmount={xaxisTickAmount}
7475
stroke={stroke}
76+
layoutConfig={layoutConfig}
7577
/>
7678
</div>
7779
</GeneralDialog>

src/client/components/facet_bar/FacetHeader.js

+3
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class FacetHeader extends React.Component {
298298
icon={<PieChartIcon />}
299299
tooltip={intl.get('facetBar.pieChart.tooltip')}
300300
dialogTitle={this.props.facetLabel}
301+
layoutConfig={this.props.layoutConfig}
301302
/>}
302303
{barChartButton &&
303304
<ChartDialog
@@ -314,6 +315,7 @@ class FacetHeader extends React.Component {
314315
xaxisTitle={intl.get(`facetBar.barChart.${this.props.facetID}.xaxisTitle`)}
315316
yaxisTitle={intl.get(`facetBar.barChart.${this.props.facetID}.yaxisTitle`)}
316317
seriesTitle={intl.get(`facetBar.barChart.${this.props.facetID}.seriesTitle`)}
318+
layoutConfig={this.props.layoutConfig}
317319
/>}
318320
{lineChartButton &&
319321
<ChartDialog
@@ -331,6 +333,7 @@ class FacetHeader extends React.Component {
331333
yaxisTitle={intl.get(`facetBar.lineChart.${this.props.facetID}.yaxisTitle`)}
332334
seriesTitle={intl.get(`facetBar.lineChart.${this.props.facetID}.seriesTitle`)}
333335
lineChartConfig={this.props.facet.lineChartConfig}
336+
layoutConfig={this.props.layoutConfig}
334337
/>}
335338
{menuButtons.length > 0 &&
336339
<>

src/client/components/facet_bar/HierarchicalFacet.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import IconButton from '@material-ui/core/IconButton'
1414
import NavigateNextIcon from '@material-ui/icons/NavigateNext'
1515
import NavigateBeforeIcon from '@material-ui/icons/NavigateBefore'
1616
import Typography from '@material-ui/core/Typography'
17+
import { generateLabelForMissingValue } from '../../helpers/helpers'
1718

1819
const styles = () => ({
1920
facetSearchContainer: {
@@ -261,9 +262,7 @@ class HierarchicalFacet extends Component {
261262
isSearchMatch = this.state.matches.some(match => match.node.id === node.id)
262263
}
263264
if (node.id === 'http://ldf.fi/MISSING_VALUE') {
264-
// Check if there is a translated label for missing value, or use defaults
265-
node.prefLabel = intl.get(`perspectives.${this.props.facetClass}.properties.${this.props.facetID}.missingValueLabel`) ||
266-
intl.get('facetBar.defaultMissingValueLabel') || 'Unknown'
265+
node.prefLabel = generateLabelForMissingValue({ facetClass: this.props.facetClass, facetID: this.props.facetID })
267266
}
268267
return (
269268
<>

src/client/configs/sampo/ApexCharts/PieChartConfig.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const createApexPieChartData = ({ rawData, screenSize }) => {
1+
import { generateLabelForMissingValue } from '../../../helpers/helpers'
2+
3+
export const createApexPieChartData = ({ rawData, screenSize, facetClass, facetID }) => {
24
const labels = []
35
const series = []
46
let otherCount = 0
@@ -9,6 +11,9 @@ export const createApexPieChartData = ({ rawData, screenSize }) => {
911
if (portion < threshold) {
1012
otherCount += parseInt(item.instanceCount)
1113
} else {
14+
if (item.id === 'http://ldf.fi/MISSING_VALUE') {
15+
item.prefLabel = generateLabelForMissingValue({ facetClass, facetID })
16+
}
1217
labels.push(item.prefLabel)
1318
series.push(parseInt(item.instanceCount))
1419
}

src/client/helpers/helpers.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import querystring from 'querystring'
22
import { has } from 'lodash'
3+
import intl from 'react-intl-universal'
34

45
export const stateToUrl = ({
56
facets,
@@ -151,3 +152,9 @@ export const arrayToObject = ({ array, keyField }) =>
151152
obj[item[keyField]] = item
152153
return obj
153154
}, {})
155+
156+
export const generateLabelForMissingValue = ({ facetClass, facetID }) => {
157+
// Check if there is a translated label for missing value, or use defaults
158+
return intl.get(`perspectives.${facetClass}.properties.${facetID}.missingValueLabel`) ||
159+
intl.get('facetBar.defaultMissingValueLabel') || 'Unknown'
160+
}

0 commit comments

Comments
 (0)