From 5463821a7f9a9d31a1d4cd553e75652ed7fc8c54 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 05 六月 2021 13:28:25 +0800 Subject: [PATCH] 2021-06-05 --- src/tabviews/custom/components/chart/antv-bar-line/index.jsx | 236 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 135 insertions(+), 101 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx index 8ef127b..21ce0d1 100644 --- a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx +++ b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx @@ -62,6 +62,7 @@ let vstFields = null if (_config.plot.datatype === 'statistics') { + _config.plot.enabled = 'false' let _column = _config.columns.filter(col => _config.plot.InfoValue === col.field)[0] if (_column) { let decimal = 0 @@ -113,40 +114,109 @@ _config.plot.color = _config.plot.color || 'rgba(0, 0, 0, 0.65)' + let bars = {} if (_config.plot.enabled === 'true' && _config.plot.customs && _config.plot.customs.length > 0) { - let colors = new Map() + let Bar_axis = [] + _config.plot.customs = _config.plot.customs.map(item => { + item.name = transfield[item.type] || item.type + item.chartType = item.shape ? (item.shape[0] || 'bar') : 'bar' + item.shape = item.shape ? (item.shape[1] || '') : '' + + if (item.chartType === 'bar') { + bars[item.type] = true + Bar_axis.push(item.type) + } + + return item + }) + + _config.plot.hasBar = Bar_axis.length > 0 + + if (_config.plot.mutilBar !== 'overlap') { + _config.plot.Bar_axis = Bar_axis + } + } else { + _config.plot.enabled = 'false' + } + + let colors = new Map() + + if (_config.plot.colors && _config.plot.colors.length > 0) { // 棰滆壊璁剧疆 + if (_config.plot.datatype === 'statistics') { + if (_config.plot.ramp === 'true') { + let _s = 'l(0) ' + if (_config.plot.chartType === 'bar') { + _s = 'l(90) ' + } + _config.plot.colors.forEach(item => { + if (!colors.has(item.type)) { + colors.set(item.type, _s + `0:${item.color} 1:${item.color1}`) + } + }) + } else { + _config.plot.colors.forEach(item => { + if (!colors.has(item.type)) { + colors.set(item.type, item.color) + } + }) + } + } else if (_config.plot.enabled === 'true') { + if (_config.plot.ramp === 'true') { + _config.plot.colors.forEach(item => { + let _type = transfield[item.type] || item.type + if (!colors.has(_type)) { + if (bars[item.type]) { + colors.set(_type, `l(90) 0:${item.color} 1:${item.color1}` ) + } else { + colors.set(_type, `l(0) 0:${item.color} 1:${item.color1}` ) + } + } + }) + } else { + _config.plot.colors.forEach(item => { + let _type = transfield[item.type] || item.type + if (!colors.has(_type)) { + colors.set(_type, item.color) + } + }) + } + } else { + if (_config.plot.ramp === 'true') { + let _s = 'l(0) ' + if (_config.plot.chartType === 'bar') { + _s = 'l(90) ' + } + _config.plot.colors.forEach(item => { + if (!transfield[item.type]) return + if (!colors.has(transfield[item.type])) { + colors.set(transfield[item.type], _s + `0:${item.color} 1:${item.color1}` ) + } + }) + } else { + _config.plot.colors.forEach(item => { + if (!transfield[item.type]) return + if (!colors.has(transfield[item.type])) { + colors.set(transfield[item.type], item.color) + } + }) + } + } + _config.plot.$colors = colors + } + + if (_config.plot.enabled === 'true') { let colorIndex = 0 let limit = chartColors.length - - if (_config.plot.colors && _config.plot.colors.length > 0) { - _config.plot.colors.forEach(item => { - if (!colors.has(item.type)) { - colors.set(item.type, item.color) - } - }) - } - let axisIndex = 0 - let hasBar = false - let Bar_axis = [] let fields = [] let legends = [] _config.plot.customs.forEach(item => { - item.name = transfield[item.type] || item.type - item.chartType = item.shape ? (item.shape[0] || 'bar') : 'bar' - item.shape = item.shape ? (item.shape[1] || '') : '' - - if (colors.has(item.type)) { - item.color = colors.get(item.type) + if (colors.has(item.name)) { + item.color = colors.get(item.name) } else { item.color = chartColors[colorIndex % limit] colorIndex++ - } - - if (item.chartType === 'bar') { - hasBar = true - Bar_axis.push(item.type) } if (item.axis === 'true' && axisIndex < 2) { @@ -172,16 +242,7 @@ }) _config.plot.customs = fields _config.plot.legends = legends - _config.plot.hasBar = hasBar _config.plot.axisIndex = axisIndex - - if (_config.plot.mutilBar === 'overlap') { - _config.plot.Bar_axis = [] - } else { - _config.plot.Bar_axis = Bar_axis - } - } else { - _config.plot.enabled = 'false' } this.setState({ @@ -710,21 +771,11 @@ let _data = [] let _valfield = 'value' let _typefield = 'key' - - let colors = new Map() let colorIndex = 0 if (plot.datatype === 'statistics') { _valfield = plot.InfoValue _typefield = plot.InfoType - - if (plot.colors && plot.colors.length > 0) { // 棰滆壊璁剧疆 - plot.colors.forEach(item => { - if (!colors.has(item.type)) { - colors.set(item.type, item.color) - } - }) - } _data = this.getStaticMsg() } else { @@ -733,14 +784,6 @@ if (plot.enabled === 'true') { this.customrender(data) return - } - - if (plot.colors && plot.colors.length > 0) { // 棰滆壊璁剧疆 - plot.colors.forEach(item => { - if (!colors.has(transfield[item.type])) { - colors.set(transfield[item.type], item.color) - } - }) } const ds = new DataSet() @@ -838,11 +881,11 @@ } }) - if (plot.colors && plot.colors.length > 0) { + if (plot.$colors) { let limit = chartColors.length _chart.color(_typefield, (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -865,14 +908,14 @@ }) } - if (plot.point === 'true' && plot.colors && plot.colors.length > 0) { + if (plot.point === 'true' && plot.$colors) { let limit = chartColors.length chart .point() .position(`${plot.Xaxis}*${_valfield}`) .color(_typefield, (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -887,6 +930,12 @@ .color(_typefield) .size(3) .shape('circle') + } + + if (plot.interaction && plot.interaction.length) { + plot.interaction.forEach(t => { + chart.interaction(t) + }) } chart.render() @@ -925,7 +974,7 @@ let padding = [10, 30, 30, 30] - if (!plot.Bar_axis.length) { + if (!plot.Bar_axis) { if (plot.axisIndex === 2) { padding = [10, 50, 30, 50] } else if (plot.axisIndex === 1) { @@ -981,7 +1030,7 @@ nice: true }) - if (plot.Bar_axis.length) { + if (plot.Bar_axis) { const view1 = chart.createView({ region: { start: { x: 0, y: 0 }, @@ -1008,7 +1057,6 @@ }) view1.data(dvt.rows) - view1.interaction('other-visible') view1.scale('value', { nice: true, @@ -1017,16 +1065,7 @@ view1.legend(false) - let colors = new Map() let colorIndex = 0 - - if (plot.colors && plot.colors.length > 0) { - plot.colors.forEach(item => { - if (!colors.has(transfield[item.type])) { - colors.set(transfield[item.type], item.color) - } - }) - } if (plot.adjust !== 'stack') { let _chart = view1 @@ -1049,11 +1088,11 @@ } }) - if (plot.colors && plot.colors.length > 0) { + if (plot.$colors) { let limit = chartColors.length _chart.color('key', (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -1098,11 +1137,11 @@ } }) - if (plot.colors && plot.colors.length > 0) { + if (plot.$colors) { let limit = chartColors.length _chart.color('key', (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -1143,12 +1182,10 @@ }) view2.data(dv.rows) - view2.interaction('other-visible') - view2.legend(false) plot.customs.forEach((item, i) => { - if (item.chartType === 'bar' && !plot.Bar_axis.length) { + if (item.chartType === 'bar' && !plot.Bar_axis) { view2.axis(item.name, item.axis) view2.scale(item.name, { @@ -1187,7 +1224,7 @@ _chart.style({ radius: [plot.barRadius, plot.barRadius, 0, 0] }) } } else if (item.chartType === 'line') { - if (!plot.Bar_axis.length) { + if (!plot.Bar_axis) { view2.axis(item.name, item.axis) } else { view2.axis(item.name, { grid: null, title: null, label: null }) @@ -1233,6 +1270,14 @@ } }) + if (plot.interaction && plot.interaction.length) { + plot.interaction.forEach(t => { + if (t === 'element-active' || t === 'element-highlight') { + chart.interaction(t) + } + }) + } + chart.render() } @@ -1246,20 +1291,11 @@ let _valfield = 'value' let _typefield = 'key' - let colors = new Map() let colorIndex = 0 if (plot.datatype === 'statistics') { _valfield = plot.InfoValue _typefield = plot.InfoType - - if (plot.colors && plot.colors.length > 0) { // 棰滆壊璁剧疆 - plot.colors.forEach(item => { - if (!colors.has(item.type)) { - colors.set(item.type, item.color) - } - }) - } _data = this.getStaticMsg() } else { @@ -1268,14 +1304,6 @@ if (plot.enabled === 'true') { this.customrender(data) return - } - - if (plot.colors && plot.colors.length > 0) { // 棰滆壊璁剧疆 - plot.colors.forEach(item => { - if (!colors.has(transfield[item.type])) { - colors.set(transfield[item.type], item.color) - } - }) } const ds = new DataSet() @@ -1389,11 +1417,11 @@ } }) - if (plot.colors && plot.colors.length > 0) { + if (plot.$colors) { let limit = chartColors.length _chart.color(_typefield, (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -1436,11 +1464,11 @@ } }) - if (plot.colors && plot.colors.length > 0) { + if (plot.$colors) { let limit = chartColors.length _chart.color(_typefield, (key) => { - if (colors.has(key)) { - return colors.get(key) + if (plot.$colors.has(key)) { + return plot.$colors.get(key) } else { colorIndex++ return chartColors[(colorIndex - 1) % limit] @@ -1519,6 +1547,12 @@ }) } + if (plot.interaction && plot.interaction.length) { + plot.interaction.forEach(t => { + chart.interaction(t) + }) + } + chart.render() } -- Gitblit v1.8.0