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

Add an advanced mode to vega / vega lite chart #1704

Merged
merged 39 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
740348e
feat: add an advanced mode to bar chart
AlasDiablo Sep 14, 2023
29efdd9
refactor: rename variable and tweak some code
AlasDiablo Sep 15, 2023
a120914
refactor: convert PieChartAdmin Component into a FunctionComponent
AlasDiablo Sep 15, 2023
642713e
refactor: convert HeatMapAdmin Component into a FunctionComponent
AlasDiablo Sep 15, 2023
b8790bc
refactor: convert CartographyAdmin Component into a FunctionComponent
AlasDiablo Sep 15, 2023
ddedebe
refactor: convert BubblePlotAdmin Component into a FunctionComponent
AlasDiablo Sep 15, 2023
03baeec
feat: update model to use editMode variable
AlasDiablo Sep 15, 2023
05956a2
feat: update props type
AlasDiablo Sep 15, 2023
718fc93
refactor: update model import
AlasDiablo Sep 15, 2023
c453011
feat: add advanced mode to all vega lite chart
AlasDiablo Sep 15, 2023
65c0104
refactor: generify advance mode
AlasDiablo Sep 18, 2023
994124e
refactor: update vega model to handle advance mode
AlasDiablo Sep 18, 2023
fcd9721
feat: add advanced mode to all vega chart
AlasDiablo Sep 18, 2023
7b05b1f
Update src/app/custom/translations.tsv
AlasDiablo Sep 18, 2023
5f2e279
Update src/app/custom/translations.tsv
AlasDiablo Sep 18, 2023
0b6fc88
refactor: rename variable and add comment
AlasDiablo Sep 20, 2023
40335dc
fix: remove the use of this in FlowMapAdmin function component
AlasDiablo Sep 20, 2023
a267fe2
refactor: convert FlowMapView to a function component
AlasDiablo Sep 20, 2023
2e8b8d2
refactor: convert BarChartView to a function component
AlasDiablo Sep 20, 2023
ba56ed2
fix: use correct call to polyglot props value
AlasDiablo Sep 20, 2023
213e8a3
refactor: convert RadarChartView to a function component
AlasDiablo Sep 20, 2023
3b4354f
refactor: optimize vega / vega lite pre render components
AlasDiablo Sep 20, 2023
31fb00d
fix: add missing deps in BarChartView spec builder
AlasDiablo Sep 20, 2023
9dbb5ad
refactor: convert CartographyView to a function component
AlasDiablo Sep 20, 2023
2c875a6
refactor: convert BubblePlotView to a function component
AlasDiablo Sep 20, 2023
670a7d8
refactor: cleanup object deconstruction
AlasDiablo Sep 20, 2023
c953b98
refactor: convert HeatMapView Component into a FunctionComponent
AlasDiablo Sep 20, 2023
3b0988a
refactor: convert PieChartView Component into a FunctionComponent
AlasDiablo Sep 20, 2023
5d4720e
fix: roll-back Vega(Lite)Component to avoid side effect and fix null …
AlasDiablo Sep 21, 2023
55ed6c9
test: update test to take in cause ResizeObserver error caused by ren…
AlasDiablo Sep 21, 2023
3e181e1
docs: fix typo
AlasDiablo Sep 26, 2023
c8a192f
Merge branch 'master' into add-advanced-chart-params
AlasDiablo Sep 26, 2023
14bfd05
docs: fix typo
AlasDiablo Sep 26, 2023
c49a224
fix: update docs and refactor some code
AlasDiablo Oct 2, 2023
c04426c
feat: make clean error message
AlasDiablo Oct 2, 2023
2b95967
refactor: change error messages to increase user experience
AlasDiablo Oct 2, 2023
f35b513
refactor: remove abstract components, enable json saving when error
AlasDiablo Oct 4, 2023
a4e0459
Merge branch 'master' into add-advanced-chart-params
AlasDiablo Oct 4, 2023
32c158f
docs: remove comments
AlasDiablo Oct 9, 2023
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
7 changes: 7 additions & 0 deletions cypress/integration/graph_page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import * as searchDrawer from '../support/searchDrawer';

describe('Graph Page', () => {
beforeEach(() => {
// ResizeObserver doesn't like when the app has to many renders / re-renders
// and throws an exception to say, "I wait for the next paint"
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
cy.on('uncaught:exception', error => {
return !error.message.includes('ResizeObserver');
});

teardown();
menu.openAdvancedDrawer();
menu.goToAdminDashboard();
Expand Down
7 changes: 7 additions & 0 deletions cypress/integration/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import * as searchDrawer from '../support/searchDrawer';
describe('Model Page', () => {
describe('handling old models', () => {
beforeEach(() => {
// ResizeObserver doesn't like when the app has to many renders / re-renders
// and throws an exception to say, "I wait for the next paint"
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
cy.on('uncaught:exception', error => {
return !error.message.includes('ResizeObserver');
});

teardown();
menu.openAdvancedDrawer();
menu.goToAdminDashboard();
Expand Down
3 changes: 3 additions & 0 deletions src/app/custom/translations.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,6 @@
"r-sub-resources-co-occurrences_description" "Identifies sub-resources that co-occur with a given sub-resource and calculates the number of these co-occurrences." "Identifie les sous-ressources co-occurrentes avec une sous-ressource donnée et calcule le nombre de ces co-occurrences."
"r-close-by_title" "close-by" "close-by"
"r-close-by_description" "Is used to create the graph aster plot." "Est utilisée pour créer le graphique aster plot."
regenerate_vega_lite_spec Regenerate Vega Lite specifications Régénérer la spécification Vega Lite
regenerate_vega_spec Regenerate Vega specifications Régénérer la spécification Vega
vega_json_error The json syntax of Vega Lite specification is wrong! La syntaxe json de la spécification Vega Lite est erronée !
16 changes: 16 additions & 0 deletions src/app/js/formats/chartsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@ export const lodexOrderToIdOrder = orderBy => {
return INVALID_VALUE;
}
};

/**
* Convert text value to code value
* @param direction{'vertical' | 'horizontal'}
* @returns {number}
*/
export const lodexDirectionToIdDirection = direction => {
switch (direction) {
case 'vertical':
return AXIS_VERTICAL;
case 'horizontal':
return AXIS_HORIZONTAL;
default:
return INVALID_VALUE;
}
};
AlasDiablo marked this conversation as resolved.
Show resolved Hide resolved
150 changes: 150 additions & 0 deletions src/app/js/formats/shared/VegaAdvancedMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React, { useEffect, useMemo, useState } from 'react';
import translate from 'redux-polyglot/translate';
import PropTypes from 'prop-types';
import { Button, TextField, Tooltip } from '@mui/material';
import ReportProblemIcon from '@mui/icons-material/ReportProblem';
import CachedIcon from '@mui/icons-material/Cached';
import isEqual from 'lodash.isequal';

import { polyglot as polyglotPropTypes } from '../../propTypes';

const styles = {
error: {
container: {
marginLeft: 'auto',
marginRight: '24px',
color: 'red',
},
message: {
container: {
display: 'flex',
flexDirection: 'row',
},
icon: {
marginTop: 'auto',
marginBottom: 'auto',
marginRight: '10px',
},
message: {
borderLeft: 'solid 1px red',
paddingLeft: '10px',
},
},
},
};

const VegaAdvancedMode = ({ p, value, onChange, onClear }) => {
const [currentValue, setCurrentValue] = useState(value || '{}');
const [error, setError] = useState(null);

const valueObject = useMemo(() => {
try {
const json = JSON.parse(value);
setError(null);
return json;
} catch (e) {
setError(e);
return null;
}
}, [value]);

const currentValueObject = useMemo(() => {
try {
const json = JSON.parse(currentValue);
setError(null);
return json;
} catch (e) {
setError(e);
return null;
}
}, [currentValue]);

useEffect(() => {
if (!isEqual(currentValueObject, valueObject)) {
onChange(currentValue);
}
}, [currentValueObject, valueObject]);

const handleChange = event => {
setCurrentValue(event.target.value);
};

return (
<>
<div
style={{
display: 'flex',
flexDirection: 'row',
flex: 1,
}}
>
<div>
<Button
onClick={onClear}
color="primary"
variant="contained"
>
<CachedIcon
sx={{
marginRight: '10px',
}}
/>
{p.t('regenerate_vega_lite_spec')}
</Button>
</div>
<div
style={{
marginLeft: 'auto',
marginRight: 'auto',
}}
>
{error ? (
<Tooltip
title={
<div>
<p>{p.t('vega_json_error')}</p>
<p>{error.message}</p>
</div>
}
>
<ReportProblemIcon
fontSize="large"
sx={{
color: 'red',
}}
/>
</Tooltip>
) : null}
</div>
</div>
<TextField
onChange={handleChange}
value={currentValue}
fullWidth
multiline
/>
{error ? (
<div style={styles.error.container}>
<div style={styles.error.message.container}>
<div style={styles.error.message.icon}>
<ReportProblemIcon fontSize="large" />
</div>
<div style={styles.error.message.message}>
<p>{p.t('vega_json_error')}</p>
<p>{error.message}</p>
</div>
</div>
</div>
) : null}
</>
);
};

VegaAdvancedMode.propTypes = {
p: polyglotPropTypes.isRequired,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
onClear: PropTypes.func.isRequired,
};

export default translate(VegaAdvancedMode);
Loading