Skip to content

Commit 7060dce

Browse files
Fix geosolutions-it#11721 Add support for line traces classification - fix switching bar to line classification (geosolutions-it#11906)
1 parent 3431b19 commit 7060dce

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

web/client/components/charts/WidgetChart.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,16 @@ export const toPlotly = (_props) => {
626626
// for pie: Position legend to right and centered vertically
627627
// for bar: use groupclick to be for item toggle by overriding the default 'togglegroup' with 'toggleitem'
628628
// ** see: https://plotly.com/javascript/reference/layout/#layout-legend-groupclick
629-
...((types.includes('pie') && isModeBarVisible) ? { legend: {x: 1.05, y: 0.5} } : types.includes('bar') ? {legend: {
630-
"tracegroupgap": 10,
631-
"groupclick": "toggleitem"
632-
}} : {}),
629+
...((types.includes('pie') && isModeBarVisible)
630+
? { legend: {x: 1.05, y: 0.5} }
631+
: (types.includes('bar') || types.includes('line'))
632+
? {
633+
legend: {
634+
"tracegroupgap": 10,
635+
"groupclick": "toggleitem"
636+
}
637+
}
638+
: {}),
633639
hovermode: 'x unified',
634640
uirevision: true,
635641
shapes: [...(layout?.shapes || [])],

web/client/components/charts/__tests__/WidgetChart-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,4 +1186,24 @@ describe('Widget Chart: data conversions ', () => {
11861186
});
11871187
});
11881188
});
1189+
describe('legend layout for bar and line charts', () => {
1190+
it('bar: legend has tracegroupgap and groupclick toggleitem', () => {
1191+
const { layout } = toPlotly({
1192+
type: 'bar',
1193+
width: 400,
1194+
...DATASET_1,
1195+
classifyGeoJSONSync
1196+
});
1197+
expect(layout.legend).toEqual({ tracegroupgap: 10, groupclick: 'toggleitem' });
1198+
});
1199+
it('line: legend has tracegroupgap and groupclick toggleitem', () => {
1200+
const { layout } = toPlotly({
1201+
type: 'line',
1202+
width: 400,
1203+
...DATASET_1,
1204+
classifyGeoJSONSync
1205+
});
1206+
expect(layout.legend).toEqual({ tracegroupgap: 10, groupclick: 'toggleitem' });
1207+
});
1208+
});
11891209
});

web/client/components/widgets/builder/wizard/chart/ChartStyleEditor.jsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,11 @@ import Select from "react-select";
1414
import Message from "../../../../I18N/Message";
1515
import ChartClassification from './ChartClassification';
1616
import set from 'lodash/fp/set';
17-
import { DEFAULT_CLASSIFICATION } from '../../../../../utils/WidgetsUtils';
1817

1918
const chartStyleEditors = {
2019
line: ({ data, onChangeStyle, options, onChange }) => {
2120
const msMode = data?.style?.msMode || 'simple';
2221
const mode = data?.style?.mode || 'lines';
23-
const classificationData = {
24-
...data,
25-
style: {
26-
...data?.style,
27-
msClassification: data?.style?.msClassification || DEFAULT_CLASSIFICATION
28-
}
29-
};
3022

3123
// Filter mode options based on msMode
3224
const modeOptions = [
@@ -77,7 +69,7 @@ const chartStyleEditors = {
7769
</FormGroup>
7870
{msMode === 'classification' && (
7971
<ChartClassification
80-
data={classificationData}
72+
data={data}
8173
options={options}
8274
onChange={onChange}
8375
onChangeStyle={onChangeStyle}

web/client/utils/WidgetsUtils.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ export const FONT = {
4040
COLOR: "#000000"
4141
};
4242

43-
export const DEFAULT_CLASSIFICATION = {
44-
intervals: 5,
45-
method: "jenks",
46-
ramp: "viridis",
47-
reverse: false
48-
};
49-
5043
/**
5144
* Get a widget by its dependency path
5245
* @param {string} k - The dependency path

0 commit comments

Comments
 (0)