-
Notifications
You must be signed in to change notification settings - Fork 12
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
LDA Chart and Routine #1797
Merged
Merged
LDA Chart and Routine #1797
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb585b7
feat: add lda routine
AlasDiablo a57c838
feat: add LodexExtractOutput to only extract wanted data
AlasDiablo 61662fc
Merge branch 'master' into lda-chart-routine
AlasDiablo d74f49f
feat: update routine and start adding lda format
AlasDiablo f64e8a7
feat: add chart and data manipulation
AlasDiablo d8b7275
feat: add colors options to lda chart
AlasDiablo f682605
refactor (lda chart): cleanup
AlasDiablo 1838a5f
Merge branch 'master' into lda-chart-routine
AlasDiablo 5c68db0
refactor: update lda routine and chart
AlasDiablo 91b5ed3
fix: remove ngrok url
AlasDiablo a6c861b
feat: add translations and update routines catalog
AlasDiablo 46c65eb
refactor: make lda chart generic
AlasDiablo 59008a6
fix: rename routine label
AlasDiablo 0a90dcb
fix: apply suggestions from code review
AlasDiablo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can simplify using
[dedupe]