Skip to content

Commit dc89379

Browse files
committed
ChartBuilderModal: Fix margins for title/subtitle
1 parent 2c47a2b commit dc89379

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

packages/components/src/internal/components/chart/ChartBuilderModal.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ const ChartPreview: FC<ChartPreviewProps> = memo(props => {
149149
height: 350,
150150
width,
151151
};
152-
if (!savedChartModel || savedChartModel.visualizationConfig.chartConfig.geomOptions.marginTop === 20) {
153-
chartConfig_.geomOptions.marginTop = 15;
154-
}
155152

156153
if (ref.current) ref.current.innerHTML = ''; // clear again, right before render
157154
LABKEY_VIS.GenericChartHelper.generateChartSVG(divId, chartConfig_, measureStore, trendlineData);

packages/components/src/internal/components/chart/ChartSettingsPanel.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ const LabelInput: FC<LabelInputProps> = memo(({ label, name, onChange, value })
2727
return (
2828
<div>
2929
<label>{label}</label>
30-
<input className="form-control" name={name as string} onChange={onChange_} type="text" value={value} />
30+
<input
31+
className="form-control"
32+
name={name as string}
33+
onChange={onChange_}
34+
type="text"
35+
value={value ?? ''}
36+
/>
3137
</div>
3238
);
3339
});
@@ -157,7 +163,23 @@ export const ChartSettingsPanel: FC<Props> = memo(props => {
157163

158164
const onLabelChange = useCallback(
159165
(key: LabelKey, value: string) => {
160-
setChartConfig(current => ({ ...current, labels: { ...current.labels, [key]: value } }));
166+
setChartConfig(current => {
167+
const labels = { ...current.labels, [key]: value };
168+
let geomOptions = current.geomOptions;
169+
let marginTop = 15;
170+
const hasTitle = !!labels.main?.trim();
171+
const hasSubtitle = !!labels.subtitle?.trim();
172+
173+
if (hasTitle && hasSubtitle) marginTop += 50;
174+
else if (hasTitle) marginTop += 25;
175+
// Yes, really, subtitle only gets the most padding. Our charting library is probably setting some
176+
// default amount if main is present
177+
else if (hasSubtitle) marginTop += 55;
178+
179+
if (marginTop != geomOptions.marginTop) geomOptions = { ...geomOptions, marginTop };
180+
181+
return { ...current, labels, geomOptions };
182+
});
161183
},
162184
[setChartConfig]
163185
);

packages/components/src/internal/components/chart/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const makeGeomOptions = (chartType: string) => ({
114114
marginBottom: null,
115115
marginLeft: null,
116116
marginRight: null,
117-
marginTop: 20, // this will be saved with the chartConfig, but we will override it for the preview in the modal
117+
marginTop: 15,
118118
opacity: chartType === 'bar_chart' || chartType === 'line_plot' ? 1.0 : 0.5,
119119
pieHideWhenLessThanPercentage: 5,
120120
pieInnerRadius: 0,

0 commit comments

Comments
 (0)