dosubot[bot] commented on issue #30370:
URL: https://github.com/apache/superset/issues/30370#issuecomment-2370687171

   <!-- Answer -->
   I found a similar closed issue that might be relevant to your problem: 
[chart viz][Time-series bar chart v2] chart will shrink when input customize X 
AXIS TITLE MARGIN or Y AXIS TITLE MARGIN. This issue was resolved by a pull 
request that fixed the customize margin functionality 
<sup>[[1]](https://github.com/apache/superset/issues/18104)</sup>.
   
   To fix the issue where the X-axis title disappears and margins reset or do 
not apply correctly when editing a bar chart in Superset, ensure that the 
`x_axis_title` and `x_axis_title_margin` controls are properly configured and 
rendered. Here is the relevant code snippet:
   
   ```tsx
   import { t } from '@superset-ui/core';
   import {
     ControlPanelsContainerProps,
     ControlStateMapping,
     ControlSubSectionHeader,
     formatSelectOptions,
     sections,
   } from '@superset-ui/chart-controls';
   import { OrientationType } from '../../types';
   
   function createAxisTitleControl(axis: 'x' | 'y') {
     const isXAxis = axis === 'x';
     const isVertical = (controls: ControlStateMapping) =>
       Boolean(controls?.orientation.value === OrientationType.Vertical);
     const isHorizontal = (controls: ControlStateMapping) =>
       Boolean(controls?.orientation.value === OrientationType.Horizontal);
   
     return [
       [
         {
           name: 'x_axis_title',
           config: {
             type: 'TextControl',
             label: t('Axis Title'),
             renderTrigger: true,
             default: '',
             description: t('Changing this control takes effect instantly'),
             visibility: ({ controls }: ControlPanelsContainerProps) =>
               isXAxis ? isVertical(controls) : isHorizontal(controls),
           },
         },
       ],
       [
         {
           name: 'x_axis_title_margin',
           config: {
             type: 'SelectControl',
             freeForm: true,
             clearable: true,
             label: t('AXIS TITLE MARGIN'),
             renderTrigger: true,
             default: sections.TITLE_MARGIN_OPTIONS[0],
             choices: formatSelectOptions(sections.TITLE_MARGIN_OPTIONS),
             description: t('Changing this control takes effect instantly'),
             visibility: ({ controls }: ControlPanelsContainerProps) =>
               isXAxis ? isVertical(controls) : isHorizontal(controls),
           },
         },
       ],
     ];
   }
   
   const config = {
     controlPanelSections: [
       {
         label: t('Chart Title'),
         tabOverride: 'customize',
         expanded: true,
         controlSetRows: [
           [<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
           ...createAxisTitleControl('x'),
         ],
       },
     ],
   };
   
   export default config;
   ```
   
   Ensure that the `x_axis_title` and `x_axis_title_margin` controls are 
correctly set up in your chart configuration. The `renderTrigger: true` 
property ensures that changes to these controls will trigger a re-render of the 
chart, which should apply the updated title and margins correctly. 
Additionally, the `visibility` property ensures that these controls are only 
visible when the chart orientation is appropriate, preventing any 
misconfiguration 
<sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/plugins/plugin-chart-echarts/src/Bubble/controlPanel.tsx)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-chart-controls/src/sections/chartTitle.tsx)</sup><sup>[[4]](https://github.com/apache/superset/blob/master/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to