feat(图表): 柱状图条形图支持设置柱宽

#11540
#11815
#13548
This commit is contained in:
ulleo 2024-12-05 15:48:55 +08:00
parent f2f2abf6be
commit 610d26c2bd
15 changed files with 210 additions and 8 deletions

View File

@ -1197,6 +1197,7 @@ export default {
color_technology: 'Technology', color_technology: 'Technology',
color_simple: 'Simple', color_simple: 'Simple',
not_alpha: 'Opacity', not_alpha: 'Opacity',
column_width_ratio: 'Column Width Ratio',
area_border_color: 'Map border', area_border_color: 'Map border',
area_base_color: 'Map area fill', area_base_color: 'Map area fill',
size: 'Size', size: 'Size',

View File

@ -1169,6 +1169,7 @@ export default {
color_technology: '科技', color_technology: '科技',
color_simple: '簡潔', color_simple: '簡潔',
not_alpha: '不透明度', not_alpha: '不透明度',
column_width_ratio: '柱寬比例',
area_border_color: '地圖邊線', area_border_color: '地圖邊線',
area_base_color: '地圖區塊填充', area_base_color: '地圖區塊填充',
size: '大小', size: '大小',

View File

@ -1171,6 +1171,7 @@ export default {
color_technology: '科技', color_technology: '科技',
color_simple: '简洁', color_simple: '简洁',
not_alpha: '不透明度', not_alpha: '不透明度',
column_width_ratio: '柱宽比例',
area_border_color: '地图边线', area_border_color: '地图边线',
area_base_color: '地图区块填充', area_base_color: '地图区块填充',
size: '大小', size: '大小',

View File

@ -177,6 +177,10 @@ declare interface ChartBasicStyle {
* 圆角柱倒角 * 圆角柱倒角
*/ */
columnBarRightAngleRadius: number columnBarRightAngleRadius: number
/**
* 一般柱状图宽度占比0 - 100 范围数值
*/
columnWidthRatio: number
/** /**
* 柱间距 * 柱间距
*/ */

View File

@ -65,6 +65,22 @@ const onAlphaChange = v => {
changeBasicStyle('alpha') changeBasicStyle('alpha')
} }
const onColumnWidthRatioChange = v => {
const _v = parseInt(v)
if (_v >= 1 && _v <= 100) {
state.basicStyleForm.columnWidthRatio = _v
} else if (_v < 1) {
state.basicStyleForm.columnWidthRatio = 1
} else if (_v > 100) {
state.basicStyleForm.columnWidthRatio = 100
} else {
const basicStyle = cloneDeep(props.chart.customAttr.basicStyle)
const oldForm = defaultsDeep(basicStyle, cloneDeep(DEFAULT_BASIC_STYLE)) as ChartBasicStyle
state.basicStyleForm.columnWidthRatio = oldForm.columnWidthRatio
}
changeBasicStyle('columnWidthRatio')
}
const changeMisc = prop => { const changeMisc = prop => {
emit('onMiscChange', { data: state.miscForm, requestData: true }, prop) emit('onMiscChange', { data: state.miscForm, requestData: true }, prop)
} }
@ -1207,6 +1223,40 @@ onMounted(() => {
@change="changeBasicStyle('barGap')" @change="changeBasicStyle('barGap')"
/> />
</el-form-item> </el-form-item>
<div class="alpha-setting" v-if="showProperty('columnWidthRatio')">
<label class="alpha-label" :class="{ dark: 'dark' === themes }">
{{ t('chart.column_width_ratio') }}
</label>
<el-row style="flex: 1" :gutter="8">
<el-col :span="13">
<el-form-item class="form-item alpha-slider" :class="'form-item-' + themes">
<el-slider
:effect="themes"
:min="1"
:max="100"
v-model="state.basicStyleForm.columnWidthRatio"
@change="changeBasicStyle('columnWidthRatio')"
/>
</el-form-item>
</el-col>
<el-col :span="11" style="padding-top: 2px">
<el-form-item class="form-item" :class="'form-item-' + themes">
<el-input
type="number"
:effect="themes"
v-model="state.basicStyleForm.columnWidthRatio"
:min="1"
:max="100"
class="basic-input-number"
:controls="false"
@change="onColumnWidthRatioChange"
>
<template #suffix> % </template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</div>
<!--bar end--> <!--bar end-->
<!--line area start--> <!--line area start-->
<el-row :gutter="8"> <el-row :gutter="8">

View File

@ -1,6 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, PropType, reactive, watch, ref } from 'vue' import { onMounted, PropType, reactive, watch, ref } from 'vue'
import { COLOR_PANEL, DEFAULT_MISC } from '@/views/chart/components/editor/util/chart' import {
COLOR_PANEL,
DEFAULT_BASIC_STYLE,
DEFAULT_MISC
} from '@/views/chart/components/editor/util/chart'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import CustomColorStyleSelect from '@/views/chart/components/editor/editor-style/components/CustomColorStyleSelect.vue' import CustomColorStyleSelect from '@/views/chart/components/editor/editor-style/components/CustomColorStyleSelect.vue'
import { cloneDeep, defaultsDeep } from 'lodash-es' import { cloneDeep, defaultsDeep } from 'lodash-es'
@ -75,6 +79,23 @@ const onAlphaChange = v => {
} }
changeBasicStyle('alpha') changeBasicStyle('alpha')
} }
const onColumnWidthRatioChange = v => {
const _v = parseInt(v)
if (_v >= 1 && _v <= 100) {
state.basicStyleForm.columnWidthRatio = _v
} else if (_v < 1) {
state.basicStyleForm.columnWidthRatio = 1
} else if (_v > 100) {
state.basicStyleForm.columnWidthRatio = 100
} else {
const basicStyle = cloneDeep(props.chart.customAttr.basicStyle)
const oldForm = defaultsDeep(basicStyle, cloneDeep(DEFAULT_BASIC_STYLE)) as ChartBasicStyle
state.basicStyleForm.columnWidthRatio = oldForm.columnWidthRatio
}
changeBasicStyle('columnWidthRatio')
}
const onSubAlphaChange = v => { const onSubAlphaChange = v => {
const _v = parseInt(v) const _v = parseInt(v)
if (_v >= 0 && _v <= 100) { if (_v >= 0 && _v <= 100) {
@ -208,6 +229,40 @@ onMounted(() => {
<el-radio label="roundAngle" :effect="themes">{{ t('chart.roundAngle') }}</el-radio> <el-radio label="roundAngle" :effect="themes">{{ t('chart.roundAngle') }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<div class="alpha-setting" v-if="showProperty('columnWidthRatio')">
<label class="alpha-label" :class="{ dark: 'dark' === themes }">
{{ t('chart.column_width_ratio') }}
</label>
<el-row style="flex: 1" :gutter="8">
<el-col :span="13">
<el-form-item class="form-item alpha-slider" :class="'form-item-' + themes">
<el-slider
:effect="themes"
:min="1"
:max="100"
v-model="state.basicStyleForm.columnWidthRatio"
@change="changeBasicStyle('columnWidthRatio')"
/>
</el-form-item>
</el-col>
<el-col :span="11" style="padding-top: 2px">
<el-form-item class="form-item" :class="'form-item-' + themes">
<el-input
type="number"
:effect="themes"
v-model="state.basicStyleForm.columnWidthRatio"
:min="1"
:max="100"
class="basic-input-number"
:controls="false"
@change="onColumnWidthRatioChange"
>
<template #suffix> % </template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</div>
</template> </template>
<template v-else> <template v-else>
<el-row :gutter="8"> <el-row :gutter="8">

View File

@ -1589,6 +1589,7 @@ export const DEFAULT_BASIC_STYLE: ChartBasicStyle = {
barDefault: true, barDefault: true,
radiusColumnBar: 'rightAngle', radiusColumnBar: 'rightAngle',
columnBarRightAngleRadius: 20, columnBarRightAngleRadius: 20,
columnWidthRatio: 60,
barWidth: 40, barWidth: 40,
barGap: 0.4, barGap: 0.4,
lineType: 'solid', lineType: 'solid',

View File

@ -27,7 +27,7 @@ import {
TOOLTIP_TPL TOOLTIP_TPL
} from '@/views/chart/components/js/panel/common/common_antv' } from '@/views/chart/components/js/panel/common/common_antv'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { DEFAULT_LABEL } from '@/views/chart/components/editor/util/chart' import { DEFAULT_BASIC_STYLE, DEFAULT_LABEL } from '@/views/chart/components/editor/util/chart'
import { clearExtremum, extremumEvt } from '@/views/chart/components/js/extremumUitl' import { clearExtremum, extremumEvt } from '@/views/chart/components/js/extremumUitl'
import { Group } from '@antv/g-canvas' import { Group } from '@antv/g-canvas'
@ -187,6 +187,19 @@ export class Bar extends G2PlotChartView<ColumnOptions, Column> {
columnStyle columnStyle
} }
} }
let columnWidthRatio
const _v = basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
columnWidthRatio = _v / 100.0
} else if (_v < 1) {
columnWidthRatio = 1 / 100.0
} else if (_v > 100) {
columnWidthRatio = 1
}
if (columnWidthRatio) {
options.columnWidthRatio = columnWidthRatio
}
return options return options
} }

View File

@ -31,7 +31,7 @@ export const BAR_RANGE_EDITOR_PROPERTY: EditorProperty[] = [
export const BAR_EDITOR_PROPERTY_INNER: EditorPropertyInner = { export const BAR_EDITOR_PROPERTY_INNER: EditorPropertyInner = {
'background-overall-component': ['all'], 'background-overall-component': ['all'],
'border-style': ['all'], 'border-style': ['all'],
'basic-style-selector': ['colors', 'alpha', 'gradient', 'radiusColumnBar'], 'basic-style-selector': ['colors', 'alpha', 'gradient', 'radiusColumnBar', 'columnWidthRatio'],
'label-selector': ['fontSize', 'color', 'labelFormatter'], 'label-selector': ['fontSize', 'color', 'labelFormatter'],
'tooltip-selector': ['fontSize', 'color', 'tooltipFormatter', 'show'], 'tooltip-selector': ['fontSize', 'color', 'tooltipFormatter', 'show'],
'x-axis-selector': [ 'x-axis-selector': [

View File

@ -26,7 +26,7 @@ import {
} from '@/views/chart/components/js/panel/charts/bar/common' } from '@/views/chart/components/js/panel/charts/bar/common'
import type { Datum } from '@antv/g2plot/esm/types/common' import type { Datum } from '@antv/g2plot/esm/types/common'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { DEFAULT_LABEL } from '@/views/chart/components/editor/util/chart' import { DEFAULT_BASIC_STYLE, DEFAULT_LABEL } from '@/views/chart/components/editor/util/chart'
import { Group } from '@antv/g-canvas' import { Group } from '@antv/g-canvas'
const { t } = useI18n() const { t } = useI18n()
@ -171,6 +171,20 @@ export class HorizontalBar extends G2PlotChartView<BarOptions, Bar> {
barStyle barStyle
} }
} }
let barWidthRatio
const _v = basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
barWidthRatio = _v / 100.0
} else if (_v < 1) {
barWidthRatio = 1 / 100.0
} else if (_v > 100) {
barWidthRatio = 1
}
if (barWidthRatio) {
options.barWidthRatio = barWidthRatio
}
return options return options
} }

View File

@ -16,6 +16,7 @@ import {
import { cloneDeep, defaultTo } from 'lodash-es' import { cloneDeep, defaultTo } from 'lodash-es'
import { valueFormatter } from '@/views/chart/components/js/formatter' import { valueFormatter } from '@/views/chart/components/js/formatter'
import { Options } from '@antv/g2plot/esm' import { Options } from '@antv/g2plot/esm'
import { DEFAULT_BASIC_STYLE } from '@/views/chart/components/editor/util/chart'
const { t } = useI18n() const { t } = useI18n()
@ -54,7 +55,7 @@ export class ProgressBar extends G2PlotChartView<BarOptions, G2Progress> {
'legend-selector': null, 'legend-selector': null,
'background-overall-component': ['all'], 'background-overall-component': ['all'],
'border-style': ['all'], 'border-style': ['all'],
'basic-style-selector': ['colors', 'alpha', 'gradient', 'radiusColumnBar'], 'basic-style-selector': ['colors', 'alpha', 'gradient', 'radiusColumnBar', 'columnWidthRatio'],
'label-selector': ['hPosition', 'color', 'fontSize', 'showQuota', 'showProportion'], 'label-selector': ['hPosition', 'color', 'fontSize', 'showQuota', 'showProportion'],
'tooltip-selector': ['fontSize', 'color', 'backgroundColor', 'tooltipFormatter', 'show'], 'tooltip-selector': ['fontSize', 'color', 'backgroundColor', 'tooltipFormatter', 'show'],
'y-axis-selector': [ 'y-axis-selector': [
@ -194,6 +195,20 @@ export class ProgressBar extends G2PlotChartView<BarOptions, G2Progress> {
barStyle barStyle
} }
} }
let barWidthRatio
const _v = basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
barWidthRatio = _v / 100.0
} else if (_v < 1) {
barWidthRatio = 1 / 100.0
} else if (_v > 100) {
barWidthRatio = 1
}
if (barWidthRatio) {
options.barWidthRatio = barWidthRatio
}
return options return options
} }
protected configTooltip(chart: Chart, options: BarOptions): BarOptions { protected configTooltip(chart: Chart, options: BarOptions): BarOptions {

View File

@ -21,6 +21,7 @@ import {
} from '@/views/chart/components/js/panel/charts/bar/common' } from '@/views/chart/components/js/panel/charts/bar/common'
import { Datum } from '@antv/g2plot/esm/types/common' import { Datum } from '@antv/g2plot/esm/types/common'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { DEFAULT_BASIC_STYLE } from '@/views/chart/components/editor/util/chart'
const { t } = useI18n() const { t } = useI18n()
const DEFAULT_DATA = [] const DEFAULT_DATA = []
@ -322,6 +323,19 @@ export class RangeBar extends G2PlotChartView<BarOptions, Bar> {
barStyle barStyle
} }
} }
let barWidthRatio
const _v = basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
barWidthRatio = _v / 100.0
} else if (_v < 1) {
barWidthRatio = 1 / 100.0
} else if (_v > 100) {
barWidthRatio = 1
}
if (barWidthRatio) {
options.barWidthRatio = barWidthRatio
}
return options return options
} }

View File

@ -13,6 +13,7 @@ import {
} from '../../common/common_antv' } from '../../common/common_antv'
import { isEmpty } from 'lodash-es' import { isEmpty } from 'lodash-es'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { DEFAULT_BASIC_STYLE } from '@/views/chart/components/editor/util/chart'
const { t } = useI18n() const { t } = useI18n()
/** /**
@ -33,7 +34,7 @@ export class Waterfall extends G2PlotChartView<WaterfallOptions, G2Waterfall> {
propertyInner: EditorPropertyInner = { propertyInner: EditorPropertyInner = {
'background-overall-component': ['all'], 'background-overall-component': ['all'],
'border-style': ['all'], 'border-style': ['all'],
'basic-style-selector': ['colors', 'alpha', 'gradient'], 'basic-style-selector': ['colors', 'alpha', 'gradient', 'columnWidthRatio'],
'label-selector': ['fontSize', 'color', 'vPosition', 'labelFormatter'], 'label-selector': ['fontSize', 'color', 'vPosition', 'labelFormatter'],
'tooltip-selector': ['fontSize', 'color', 'backgroundColor', 'seriesTooltipFormatter', 'show'], 'tooltip-selector': ['fontSize', 'color', 'backgroundColor', 'seriesTooltipFormatter', 'show'],
'title-selector': [ 'title-selector': [
@ -137,6 +138,20 @@ export class Waterfall extends G2PlotChartView<WaterfallOptions, G2Waterfall> {
const customAttr = parseJson(chart.customAttr) const customAttr = parseJson(chart.customAttr)
const { colors, gradient, alpha } = customAttr.basicStyle const { colors, gradient, alpha } = customAttr.basicStyle
const [risingColorRgba, fallingColorRgba, totalColorRgba] = colors const [risingColorRgba, fallingColorRgba, totalColorRgba] = colors
let columnWidthRatio
const _v = customAttr.basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
columnWidthRatio = _v / 100.0
} else if (_v < 1) {
columnWidthRatio = 1 / 100.0
} else if (_v > 100) {
columnWidthRatio = 1
}
if (columnWidthRatio) {
options.columnWidthRatio = columnWidthRatio
}
return { return {
...options, ...options,
total: { total: {

View File

@ -30,7 +30,8 @@ export const CHART_MIX_EDITOR_PROPERTY_INNER: EditorPropertyInner = {
'lineSmooth', 'lineSmooth',
'radiusColumnBar', 'radiusColumnBar',
'subSeriesColor', 'subSeriesColor',
'seriesColor' 'seriesColor',
'columnWidthRatio'
], ],
'x-axis-selector': [ 'x-axis-selector': [
'name', 'name',

View File

@ -35,7 +35,11 @@ import {
} from './chart-mix-common' } from './chart-mix-common'
import type { Datum } from '@antv/g2plot/esm/types/common' import type { Datum } from '@antv/g2plot/esm/types/common'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { DEFAULT_LABEL, DEFAULT_LEGEND_STYLE } from '@/views/chart/components/editor/util/chart' import {
DEFAULT_BASIC_STYLE,
DEFAULT_LABEL,
DEFAULT_LEGEND_STYLE
} from '@/views/chart/components/editor/util/chart'
import type { Options } from '@antv/g2plot/esm' import type { Options } from '@antv/g2plot/esm'
import { Group } from '@antv/g-canvas' import { Group } from '@antv/g-canvas'
@ -303,6 +307,19 @@ export class ColumnLineMix extends G2PlotChartView<DualAxesOptions, DualAxes> {
} }
} }
let columnWidthRatio
const _v = s.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio
if (_v >= 1 && _v <= 100) {
columnWidthRatio = _v / 100.0
} else if (_v < 1) {
columnWidthRatio = 1 / 100.0
} else if (_v > 100) {
columnWidthRatio = 1
}
if (columnWidthRatio) {
tempOption.geometryOptions[0].columnWidthRatio = columnWidthRatio
}
return tempOption return tempOption
} }