-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1797 from Inist-CNRS/lda-chart-routine
LDA Chart and Routine
- Loading branch information
Showing
10 changed files
with
336 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/app/js/formats/vega-lite/component/clustered-chart/ClusteredChart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { CustomActionVegaLite } from '../vega-lite-component'; | ||
import { VEGA_LITE_DATA_INJECT_TYPE_A } from '../../../chartsUtils'; | ||
import PropTypes from 'prop-types'; | ||
import React, { useMemo } from 'react'; | ||
|
||
const ClusteredChart = ({ data, topic, params }) => { | ||
const values = useMemo(() => { | ||
return data.filter(value => value.source === topic); | ||
}, [data, topic]); | ||
|
||
const spec = useMemo(() => { | ||
const { colors, xTitle, yTitle } = params; | ||
const specToReturn = { | ||
$schema: 'https://vega.github.io/schema/vega-lite/v5.json', | ||
config: { legend: { disable: true } }, | ||
title: topic, | ||
encoding: { | ||
y: { field: 'target', type: 'nominal', sort: null }, | ||
x: { field: 'weight', type: 'quantitative', sort: null }, | ||
}, | ||
layer: [ | ||
{ | ||
mark: 'bar', | ||
encoding: { | ||
color: { | ||
field: 'weight', | ||
scale: { range: colors.split(' ') }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
mark: { | ||
type: 'text', | ||
align: 'left', | ||
baseline: 'middle', | ||
dx: 3, | ||
}, | ||
encoding: { | ||
text: { | ||
field: 'weight', | ||
type: 'quantitative', | ||
format: '.4f', | ||
}, | ||
}, | ||
}, | ||
], | ||
width: 'container', | ||
height: { step: 20 }, | ||
}; | ||
|
||
if (xTitle && xTitle !== '') { | ||
specToReturn.encoding.x.title = xTitle; | ||
} | ||
|
||
if (yTitle && yTitle !== '') { | ||
specToReturn.encoding.y.title = yTitle; | ||
} | ||
|
||
return specToReturn; | ||
}, [values, topic, params]); | ||
return ( | ||
<CustomActionVegaLite | ||
spec={spec} | ||
data={{ | ||
values, | ||
}} | ||
injectType={VEGA_LITE_DATA_INJECT_TYPE_A} | ||
/> | ||
); | ||
}; | ||
|
||
ClusteredChart.propTypes = { | ||
data: PropTypes.array.isRequired, | ||
topic: PropTypes.string.isRequired, | ||
params: PropTypes.shape({ | ||
colors: PropTypes.string.isRequired, | ||
xTitle: PropTypes.string, | ||
yTitle: PropTypes.string, | ||
}), | ||
}; | ||
|
||
export default ClusteredChart; |
73 changes: 73 additions & 0 deletions
73
src/app/js/formats/vega-lite/component/clustered-chart/ClusteredChartAdmin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import translate from 'redux-polyglot/translate'; | ||
import PropTypes from 'prop-types'; | ||
import { Box, TextField } from '@mui/material'; | ||
|
||
import { polyglot as polyglotPropTypes } from '../../../../propTypes'; | ||
import ColorPickerParamsAdmin from '../../../shared/ColorPickerParamsAdmin'; | ||
import { MONOCHROMATIC_DEFAULT_COLORSET } from '../../../colorUtils'; | ||
import updateAdminArgs from '../../../shared/updateAdminArgs'; | ||
|
||
export const defaultArgs = { | ||
colors: MONOCHROMATIC_DEFAULT_COLORSET, | ||
}; | ||
|
||
const ClusteredChartAdmin = props => { | ||
const { args, p } = props; | ||
const { colors, xTitle, yTitle } = args; | ||
|
||
const handleColors = colors => { | ||
updateAdminArgs('colors', colors || defaultArgs.colors, props); | ||
}; | ||
|
||
const handleXAxisTitle = event => { | ||
updateAdminArgs('xTitle', event.target.value, props); | ||
}; | ||
|
||
const handleYAxisTitle = event => { | ||
updateAdminArgs('yTitle', event.target.value, props); | ||
}; | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
flexWrap="wrap" | ||
justifyContent="space-between" | ||
gap={2} | ||
> | ||
<ColorPickerParamsAdmin | ||
colors={colors} | ||
onChange={handleColors} | ||
polyglot={p} | ||
/> | ||
<TextField | ||
fullWidth | ||
label={p.t('format_x_axis_title')} | ||
onChange={handleXAxisTitle} | ||
value={xTitle} | ||
/> | ||
<TextField | ||
fullWidth | ||
label={p.t('format_y_axis_title')} | ||
onChange={handleYAxisTitle} | ||
value={yTitle} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
ClusteredChartAdmin.defaultProps = { | ||
args: defaultArgs, | ||
}; | ||
|
||
ClusteredChartAdmin.propTypes = { | ||
args: PropTypes.shape({ | ||
colors: PropTypes.string, | ||
xTitle: PropTypes.string, | ||
yTitle: PropTypes.string, | ||
}), | ||
onChange: PropTypes.func.isRequired, | ||
p: polyglotPropTypes.isRequired, | ||
}; | ||
|
||
export default translate(ClusteredChartAdmin); |
85 changes: 85 additions & 0 deletions
85
src/app/js/formats/vega-lite/component/clustered-chart/ClusteredChartView.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, { useMemo } from 'react'; | ||
import compose from 'recompose/compose'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'lodash'; | ||
import { Grid, Paper } from '@mui/material'; | ||
|
||
import injectData from '../../../injectData'; | ||
import { field as fieldPropTypes } from '../../../../propTypes'; | ||
import ClusteredChart from './ClusteredChart'; | ||
|
||
const ClusteredChartView = ({ data, colors, xTitle, yTitle }) => { | ||
const { values } = data; | ||
|
||
const topics = useMemo(() => { | ||
return _.chain(values) | ||
.map(value => value.source) | ||
.uniq() | ||
.sort((a, b) => | ||
a.localeCompare(b, 'fr', { | ||
sensitivity: 'accent', | ||
numeric: true, | ||
usage: 'sort', | ||
ignorePunctuation: true, | ||
}), | ||
) | ||
.value(); | ||
}, [values]); | ||
|
||
return ( | ||
<div style={{ margin: '12px' }}> | ||
<Grid | ||
container | ||
justifyContent="center" | ||
rowSpacing={1} | ||
columnSpacing={1} | ||
> | ||
{topics.map(topic => ( | ||
<Grid key={topic} item xs={6}> | ||
<Paper style={{ padding: '6px' }}> | ||
<ClusteredChart | ||
data={values} | ||
topic={topic} | ||
params={{ | ||
colors, | ||
xTitle, | ||
yTitle, | ||
}} | ||
/> | ||
</Paper> | ||
</Grid> | ||
))} | ||
</Grid> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state, { formatData }) => { | ||
if (!formatData) { | ||
return { | ||
data: { | ||
values: [], | ||
}, | ||
}; | ||
} | ||
return { | ||
data: { | ||
values: formatData, | ||
}, | ||
}; | ||
}; | ||
|
||
ClusteredChartView.propTypes = { | ||
field: fieldPropTypes.isRequired, | ||
resource: PropTypes.object.isRequired, | ||
data: PropTypes.any, | ||
colors: PropTypes.string.isRequired, | ||
xTitle: PropTypes.string, | ||
yTitle: PropTypes.string, | ||
}; | ||
|
||
export default compose( | ||
injectData(), | ||
connect(mapStateToProps), | ||
)(ClusteredChartView); |
12 changes: 12 additions & 0 deletions
12
src/app/js/formats/vega-lite/component/clustered-chart/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import DefaultFormat from '../../../DefaultFormat'; | ||
import Icon from '../../VegaLiteIcon'; | ||
import Component from './ClusteredChartView'; | ||
import AdminComponent, { defaultArgs } from './ClusteredChartAdmin'; | ||
|
||
export default { | ||
...DefaultFormat, | ||
Component, | ||
AdminComponent, | ||
defaultArgs, | ||
Icon, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
; suppress inspection "DuplicateSectionInFile" for whole file | ||
; suppress inspection "DuplicateKeyInSection" for whole file | ||
; Export and format clustered precompute data into an valid format for vega-lite | ||
prepend = delegate?file=../worker.ini | ||
mimeType = application/json | ||
label = clustered-precomputed | ||
|
||
[use] | ||
plugin = basics | ||
plugin = lodex | ||
plugin = analytics | ||
|
||
[buildContext] | ||
connectionStringURI = get('connectionStringURI') | ||
precomputedName = get('precomputedName') | ||
|
||
[env] | ||
path = connectionStringURI | ||
value = get('connectionStringURI') | ||
|
||
path = precomputedName | ||
value = get('precomputedName') | ||
|
||
[LodexRunQuery] | ||
|
||
[LodexFilterPrecomputed] | ||
|
||
[assign] | ||
path = id | ||
value = fix(`["${self.source}","${self.target}"]`) | ||
|
||
path = value | ||
value = get('weight') | ||
|
||
[reducing] | ||
|
||
[assign] | ||
path = source | ||
value = fix(JSON.parse(self.id)[1]) | ||
|
||
path = target | ||
value = fix(JSON.parse(self.id)[0]) | ||
|
||
path = weight | ||
value = fix(self.value[0]) | ||
|
||
[keep] | ||
path = source | ||
path = target | ||
path = weight | ||
|
||
[sort] | ||
path = weight | ||
reverse = true | ||
|
||
[LodexOutput] | ||
indent = true |