Added separate controls for X and Y grid colors
This commit is contained in:
@ -88,7 +88,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"gridColor": {
|
"yGridColor": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "#e0e0e0"
|
||||||
|
},
|
||||||
|
"xGridColor": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "#e0e0e0"
|
"default": "#e0e0e0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '62449dbdc80e118c522c');
|
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '9e08ac91fd20a1bb3a3d');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -88,7 +88,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"gridColor": {
|
"yGridColor": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "#e0e0e0"
|
||||||
|
},
|
||||||
|
"xGridColor": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "#e0e0e0"
|
"default": "#e0e0e0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -9,7 +9,8 @@ const BarGraph = ({
|
|||||||
title,
|
title,
|
||||||
showGridX,
|
showGridX,
|
||||||
showGridY,
|
showGridY,
|
||||||
gridColor,
|
xGridColor,
|
||||||
|
yGridColor,
|
||||||
gridWidth,
|
gridWidth,
|
||||||
showBarValues,
|
showBarValues,
|
||||||
xAxisLabel,
|
xAxisLabel,
|
||||||
@ -105,26 +106,22 @@ const BarGraph = ({
|
|||||||
g.append('g')
|
g.append('g')
|
||||||
.attr('class', 'grid x-grid')
|
.attr('class', 'grid x-grid')
|
||||||
.attr('transform', `translate(0,${innerHeight})`)
|
.attr('transform', `translate(0,${innerHeight})`)
|
||||||
|
.style('color', xGridColor)
|
||||||
|
.style('stroke-width', gridWidth)
|
||||||
.call(d3.axisBottom(xScale)
|
.call(d3.axisBottom(xScale)
|
||||||
.tickSize(-innerHeight)
|
.tickSize(-innerHeight)
|
||||||
.tickFormat(''))
|
.tickFormat(''));
|
||||||
.call(g => g.selectAll('.tick line')
|
|
||||||
.attr('stroke', gridColor)
|
|
||||||
.attr('stroke-width', gridWidth)
|
|
||||||
.attr('opacity', 0.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Y grid
|
// Add Y grid
|
||||||
if (showGridY) {
|
if (showGridY) {
|
||||||
g.append('g')
|
g.append('g')
|
||||||
.attr('class', 'grid y-grid')
|
.attr('class', 'grid y-grid')
|
||||||
|
.style('color', yGridColor)
|
||||||
|
.style('stroke-width', gridWidth)
|
||||||
.call(d3.axisLeft(yScale)
|
.call(d3.axisLeft(yScale)
|
||||||
.tickSize(-innerWidth)
|
.tickSize(-innerWidth)
|
||||||
.tickFormat(''))
|
.tickFormat(''));
|
||||||
.call(g => g.selectAll('.tick line')
|
|
||||||
.attr('stroke', gridColor)
|
|
||||||
.attr('stroke-width', gridWidth)
|
|
||||||
.attr('opacity', 0.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add bars
|
// Add bars
|
||||||
@ -184,7 +181,7 @@ const BarGraph = ({
|
|||||||
.text(yAxisLabel);
|
.text(yAxisLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [data, width, height, title, showGridX, showGridY, gridColor, gridWidth, showBarValues, xAxisLabel, yAxisLabel, colorSource, defaultBarColor, customColors, barOpacity]);
|
}, [data, width, height, title, showGridX, showGridY, xGridColor, yGridColor, gridWidth, showBarValues, xAxisLabel, yAxisLabel, colorSource, defaultBarColor, customColors, barOpacity]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -33,7 +33,8 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
barOpacity,
|
barOpacity,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
showGridY,
|
showGridY,
|
||||||
gridColor,
|
yGridColor,
|
||||||
|
xGridColor,
|
||||||
chartData,
|
chartData,
|
||||||
dataSource,
|
dataSource,
|
||||||
displayChartTitle,
|
displayChartTitle,
|
||||||
@ -122,20 +123,29 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
img.src = url;
|
img.src = url;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Grid Color Popover
|
// Grid Color Popovers
|
||||||
const [isGridColorPopoverOpen, setIsGridColorPopoverOpen] = useState(false);
|
const [isYGridColorPopoverOpen, setIsYGridColorPopoverOpen] = useState(false);
|
||||||
|
const [isXGridColorPopoverOpen, setIsXGridColorPopoverOpen] = useState(false);
|
||||||
|
|
||||||
// Toggle the popover visibility
|
// Toggle the popover visibility
|
||||||
const toggleGridColorPopover = () => {
|
const toggleYGridColorPopover = () => {
|
||||||
setIsGridColorPopoverOpen(!isGridColorPopoverOpen);
|
setIsYGridColorPopoverOpen(!isYGridColorPopoverOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle color change
|
const toggleXGridColorPopover = () => {
|
||||||
const onGridColorChange = (newColor) => {
|
setIsXGridColorPopoverOpen(!isXGridColorPopoverOpen);
|
||||||
setAttributes({ gridColor: newColor });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Grid Color Popover
|
// Handle color changes
|
||||||
|
const onYGridColorChange = (newColor) => {
|
||||||
|
setAttributes({ yGridColor: newColor });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onXGridColorChange = (newColor) => {
|
||||||
|
setAttributes({ xGridColor: newColor });
|
||||||
|
};
|
||||||
|
|
||||||
|
// Background Color Popover
|
||||||
const [isBackgroundColorPopoverOpen, setIsBackgroundColorPopoverOpen] = useState(false);
|
const [isBackgroundColorPopoverOpen, setIsBackgroundColorPopoverOpen] = useState(false);
|
||||||
|
|
||||||
// Toggle the background popover visibility
|
// Toggle the background popover visibility
|
||||||
@ -213,31 +223,7 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
/>
|
/>
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
<PanelBody title="Appearance">
|
<PanelBody title="Appearance">
|
||||||
<div className="grid-color-row" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '10px' }}>
|
|
||||||
<span>Grid Color</span>
|
|
||||||
<Button
|
|
||||||
className="grid-color-button"
|
|
||||||
onClick={toggleGridColorPopover}
|
|
||||||
style={{
|
|
||||||
backgroundColor: gridColor,
|
|
||||||
width: '26px',
|
|
||||||
height: '26px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
border: 'none',
|
|
||||||
}}
|
|
||||||
></Button>
|
|
||||||
{isGridColorPopoverOpen && (
|
|
||||||
<Popover
|
|
||||||
position="bottom center"
|
|
||||||
onClose={toggleGridColorPopover} // Close the popover when clicked outside
|
|
||||||
>
|
|
||||||
<ColorPicker
|
|
||||||
color={gridColor}
|
|
||||||
onChangeComplete={(color) => onGridColorChange(color.hex)} // Update color
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="background-color-row" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '10px' }}>
|
<div className="background-color-row" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '10px' }}>
|
||||||
<span>Background Color</span>
|
<span>Background Color</span>
|
||||||
<Button
|
<Button
|
||||||
@ -280,15 +266,7 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
max={1}
|
max={1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
/>
|
/>
|
||||||
<div className="components-base-control">
|
|
||||||
<label className="components-base-control__label">
|
|
||||||
{__('Background Color', 'lcp')}
|
|
||||||
</label>
|
|
||||||
<ColorPicker
|
|
||||||
color={backgroundColor}
|
|
||||||
onChangeComplete={(color) => setAttributes({ backgroundColor: color.hex })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
label={__('Show Bar Values', 'lcp')}
|
label={__('Show Bar Values', 'lcp')}
|
||||||
checked={showBarValues}
|
checked={showBarValues}
|
||||||
@ -316,23 +294,63 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
checked={showGridY}
|
checked={showGridY}
|
||||||
onChange={(value) => setAttributes({ showGridY: value })}
|
onChange={(value) => setAttributes({ showGridY: value })}
|
||||||
/>
|
/>
|
||||||
{(showGridX || showGridY) && (
|
{showGridY && (
|
||||||
<>
|
<div className="y-grid-color-row" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '8px' }}>
|
||||||
<div className="components-base-control">
|
<span>Y-Axis Grid Color</span>
|
||||||
<label className="components-base-control__label">
|
<Button
|
||||||
{__('Grid Color', 'lcp')}
|
className="grid-color-button"
|
||||||
</label>
|
onClick={toggleYGridColorPopover}
|
||||||
|
style={{
|
||||||
|
backgroundColor: yGridColor,
|
||||||
|
width: '26px',
|
||||||
|
height: '26px',
|
||||||
|
borderRadius: '50%',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
}}
|
||||||
|
></Button>
|
||||||
|
{isYGridColorPopoverOpen && (
|
||||||
|
<Popover
|
||||||
|
position="bottom center"
|
||||||
|
onClose={toggleYGridColorPopover}
|
||||||
|
>
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
color={gridColor}
|
color={yGridColor}
|
||||||
onChangeComplete={(color) => setAttributes({ gridColor: color.hex })}
|
onChangeComplete={(color) => onYGridColorChange(color.hex)}
|
||||||
/>
|
/>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showGridX && (
|
||||||
|
<div className="x-grid-color-row" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '8px' }}>
|
||||||
|
<span>X-Axis Grid Color</span>
|
||||||
|
<Button
|
||||||
|
className="grid-color-button"
|
||||||
|
onClick={toggleXGridColorPopover}
|
||||||
|
style={{
|
||||||
|
backgroundColor: xGridColor,
|
||||||
|
width: '26px',
|
||||||
|
height: '26px',
|
||||||
|
borderRadius: '50%',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
}}
|
||||||
|
></Button>
|
||||||
|
{isXGridColorPopoverOpen && (
|
||||||
|
<Popover
|
||||||
|
position="bottom center"
|
||||||
|
onClose={toggleXGridColorPopover}
|
||||||
|
>
|
||||||
|
<ColorPicker
|
||||||
|
color={xGridColor}
|
||||||
|
onChangeComplete={(color) => onXGridColorChange(color.hex)}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{(showGridX || showGridY) && (
|
||||||
<RangeControl
|
<RangeControl
|
||||||
label={__('Grid Width', 'lcp')}
|
label={__('Grid Width', 'lcp')}
|
||||||
value={gridWidth}
|
value={gridWidth}
|
||||||
@ -341,7 +359,6 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
max={5}
|
max={5}
|
||||||
step={1}
|
step={1}
|
||||||
/>
|
/>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
@ -411,7 +428,8 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
barOpacity={barOpacity}
|
barOpacity={barOpacity}
|
||||||
showGridX={showGridX}
|
showGridX={showGridX}
|
||||||
showGridY={showGridY}
|
showGridY={showGridY}
|
||||||
gridColor={gridColor}
|
yGridColor={yGridColor}
|
||||||
|
xGridColor={xGridColor}
|
||||||
gridWidth={gridWidth}
|
gridWidth={gridWidth}
|
||||||
title={displayChartTitle ? chartTitle : ''}
|
title={displayChartTitle ? chartTitle : ''}
|
||||||
showSorting={showSorting}
|
showSorting={showSorting}
|
||||||
|
|||||||
Reference in New Issue
Block a user