forked from github/dataease
Merge pull request #3435 from dataease/pr@dev@perf_map_colors
perf(视图-地图): 分离渐变色
This commit is contained in:
commit
bf7871ce29
@ -86,7 +86,7 @@ export const colorCases = [
|
|||||||
export const gradientColorCases = [
|
export const gradientColorCases = [
|
||||||
{
|
{
|
||||||
name: '渐变色1',
|
name: '渐变色1',
|
||||||
value: 'gradient1',
|
value: 'gradient1_continuous_gradient',
|
||||||
colors: [
|
colors: [
|
||||||
['rgba(144,202,249,0.5)', 'rgba(1,87,155,0.9)'],
|
['rgba(144,202,249,0.5)', 'rgba(1,87,155,0.9)'],
|
||||||
['rgba(127,222,234,1)', 'rgba(0,77,65,1)'],
|
['rgba(127,222,234,1)', 'rgba(0,77,65,1)'],
|
||||||
@ -101,3 +101,72 @@ export const gradientColorCases = [
|
|||||||
export const isGradientValue = value => {
|
export const isGradientValue = value => {
|
||||||
return value && gradientColorCases.some(item => item.value === value)
|
return value && gradientColorCases.some(item => item.value === value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getColorType = value => {
|
||||||
|
if (value.endsWith('_split_gradient')) {
|
||||||
|
return 'split_gradient'
|
||||||
|
}
|
||||||
|
const cloneColorCases = JSON.parse(JSON.stringify(colorCases))
|
||||||
|
if (cloneColorCases.some(item => item.value === value)) {
|
||||||
|
return 'simple'
|
||||||
|
}
|
||||||
|
return 'gradient'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMapColorCases = () => {
|
||||||
|
const cloneColorCases = JSON.parse(JSON.stringify(colorCases))
|
||||||
|
return cloneColorCases.map(colorItem => {
|
||||||
|
const curColors = colorItem.colors
|
||||||
|
const len = curColors.length
|
||||||
|
const start = curColors[0]
|
||||||
|
const end = curColors[len - 1]
|
||||||
|
const itemResult = {
|
||||||
|
name: colorItem.name,
|
||||||
|
value: colorItem.value + '_split_gradient',
|
||||||
|
baseColors: [start, end],
|
||||||
|
colors: stepsColor(start, end, 9, 1)
|
||||||
|
}
|
||||||
|
return itemResult
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stepsColor(start, end, steps, gamma) {
|
||||||
|
var i; var j; var ms; var me; var output = []; var so = []
|
||||||
|
gamma = gamma || 1
|
||||||
|
var normalize = function(channel) {
|
||||||
|
return Math.pow(channel / 255, gamma)
|
||||||
|
}
|
||||||
|
start = parseColor(start).map(normalize)
|
||||||
|
end = parseColor(end).map(normalize)
|
||||||
|
for (i = 0; i < steps; i++) {
|
||||||
|
ms = (steps - 1) === 0 ? 0 : (i / (steps - 1))
|
||||||
|
me = 1 - ms
|
||||||
|
for (j = 0; j < 3; j++) {
|
||||||
|
so[j] = pad(
|
||||||
|
Math.round(
|
||||||
|
Math.pow(start[j] * me + end[j] * ms, 1 / gamma) * 255
|
||||||
|
).toString(16)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
output.push('#' + so.join(''))
|
||||||
|
}
|
||||||
|
function parseColor(hexStr) {
|
||||||
|
return hexStr.length === 4
|
||||||
|
? hexStr
|
||||||
|
.substr(1)
|
||||||
|
.split('')
|
||||||
|
.map(function(s) {
|
||||||
|
return 0x11 * parseInt(s, 16)
|
||||||
|
})
|
||||||
|
: [hexStr.substr(1, 2), hexStr.substr(3, 2), hexStr.substr(5, 2)].map(
|
||||||
|
function(s) {
|
||||||
|
return parseInt(s, 16)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
function pad(s) {
|
||||||
|
return s.length === 1 ? '0' + s : s
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<el-tooltip
|
<el-tooltip
|
||||||
class="item"
|
class="item"
|
||||||
effect="dark"
|
effect="dark"
|
||||||
content="重置"
|
:content="$t('commons.reset')"
|
||||||
placement="top"
|
placement="top"
|
||||||
>
|
>
|
||||||
<i class="el-icon-refresh" />
|
<i class="el-icon-refresh" />
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<div class="custom-switch-div">
|
<div class="custom-switch-div">
|
||||||
<el-switch
|
<el-switch
|
||||||
v-model="enableCustom"
|
v-model="enableCustom"
|
||||||
active-text="自定义"
|
:active-text="$t('commons.reset')"
|
||||||
inactive-text=""
|
inactive-text=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -47,7 +47,7 @@
|
|||||||
@tab-click="handleClick"
|
@tab-click="handleClick"
|
||||||
>
|
>
|
||||||
<el-tab-pane
|
<el-tab-pane
|
||||||
v-for="(pane, i) in tabPanes"
|
v-for="(pane, i) in tabPanes.filter(item => item.name === 'simple' || (showIndex === 1 && item.name === 'split_gradient') || (showIndex === 2 && item.name === 'gradient'))"
|
||||||
:key="i"
|
:key="i"
|
||||||
:label="pane.label"
|
:label="pane.label"
|
||||||
:name="pane.name"
|
:name="pane.name"
|
||||||
@ -84,22 +84,29 @@
|
|||||||
v-for="(co,index) in option.colors"
|
v-for="(co,index) in option.colors"
|
||||||
v-else
|
v-else
|
||||||
:key="index"
|
:key="index"
|
||||||
class="color-span-base is-editor"
|
class="color-span-base"
|
||||||
|
:class="option.value.endsWith('_split_gradient') && index % 8 !== 0 ? 'static-editor' : 'is-editor'"
|
||||||
>
|
>
|
||||||
<el-color-picker
|
<span
|
||||||
v-if="i === 0"
|
v-if="option.value.endsWith('_split_gradient') && index % 8 !== 0"
|
||||||
v-model="option.colors[index]"
|
class="color-span-base-split"
|
||||||
@change="switchColorItem(option.colors, index)"
|
:style="{background: formatBgColor(co)}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<de-color-picker
|
<de-color-picker
|
||||||
v-else
|
v-else-if="option.value.endsWith('_continuous_gradient')"
|
||||||
:id="option.value + index"
|
:id="option.value + index"
|
||||||
ref="de-color-picker"
|
ref="de-color-picker"
|
||||||
v-model="option.colors[index]"
|
v-model="option.colors[index]"
|
||||||
:base-id="option.value + index"
|
:base-id="option.value + index"
|
||||||
show-alpha
|
show-alpha
|
||||||
color-format="rgb"
|
color-format="rgb"
|
||||||
@change="switchColorItem(option.colors, index)"
|
@change="switchColorItem(option.colors, option.value)"
|
||||||
|
/>
|
||||||
|
<el-color-picker
|
||||||
|
v-else
|
||||||
|
v-model="option.colors[index]"
|
||||||
|
@change="switchColorItem(option.colors, option.value)"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@ -132,7 +139,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { colorCases, gradientColorCases } from './base'
|
import { colorCases, gradientColorCases, getMapColorCases, getColorType, stepsColor } from './base'
|
||||||
import DeColorPicker from './DeColorPicker'
|
import DeColorPicker from './DeColorPicker'
|
||||||
export default {
|
export default {
|
||||||
name: 'GradientColorSelector',
|
name: 'GradientColorSelector',
|
||||||
@ -148,6 +155,10 @@ export default {
|
|||||||
colors: []
|
colors: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
showIndex: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -161,12 +172,17 @@ export default {
|
|||||||
activeName: 'simple',
|
activeName: 'simple',
|
||||||
tabPanes: [
|
tabPanes: [
|
||||||
{
|
{
|
||||||
label: '纯色',
|
label: this.$t('chart.solid_color'),
|
||||||
name: 'simple',
|
name: 'simple',
|
||||||
data: JSON.parse(JSON.stringify(colorCases))
|
data: JSON.parse(JSON.stringify(colorCases))
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '渐变',
|
label: this.$t('chart.split_gradient'),
|
||||||
|
name: 'split_gradient',
|
||||||
|
data: JSON.parse(JSON.stringify(getMapColorCases()))
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: this.$t('chart.continuous_gradient'),
|
||||||
name: 'gradient',
|
name: 'gradient',
|
||||||
data: JSON.parse(JSON.stringify(gradientColorCases))
|
data: JSON.parse(JSON.stringify(gradientColorCases))
|
||||||
}
|
}
|
||||||
@ -200,10 +216,27 @@ export default {
|
|||||||
parents.scrollTo(0, top)
|
parents.scrollTo(0, top)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
switchColorItem(colors, index) {
|
switchColorItem(colors, value) {
|
||||||
this.colorDto.colors = JSON.parse(JSON.stringify(colors))
|
const activeName = getColorType(value)
|
||||||
|
if (activeName === 'split_gradient') {
|
||||||
|
const start = colors[0]
|
||||||
|
const end = colors[colors.length - 1]
|
||||||
|
const targetColors = stepsColor(start, end, 9, 1)
|
||||||
|
this.colorDto.colors = JSON.parse(JSON.stringify(targetColors))
|
||||||
|
this.fillSplitGradientPanel()
|
||||||
|
} else {
|
||||||
|
this.colorDto.colors = JSON.parse(JSON.stringify(colors))
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit('color-change', JSON.parse(JSON.stringify(this.colorDto)))
|
this.$emit('color-change', JSON.parse(JSON.stringify(this.colorDto)))
|
||||||
},
|
},
|
||||||
|
fillSplitGradientPanel() {
|
||||||
|
this.tabPanes[1].data.forEach(item => {
|
||||||
|
if (item.value === this.colorDto.value) {
|
||||||
|
item.colors = this.colorDto.colors
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
initcolorDto() {
|
initcolorDto() {
|
||||||
let haspPropValue = true
|
let haspPropValue = true
|
||||||
if (!this.colorDto.value) {
|
if (!this.colorDto.value) {
|
||||||
@ -211,9 +244,9 @@ export default {
|
|||||||
this.colorDto.colors = this.colorCases[0].colors
|
this.colorDto.colors = this.colorCases[0].colors
|
||||||
haspPropValue = false
|
haspPropValue = false
|
||||||
}
|
}
|
||||||
this.activeName = this.colorCases.some(item => item.value === this.colorDto.value) ? 'simple' : 'gradient'
|
this.activeName = getColorType(this.colorDto.value)
|
||||||
if (haspPropValue) {
|
if (haspPropValue) {
|
||||||
this.tabPanes[this.activeName === 'simple' ? 0 : 1].data.forEach(item => {
|
this.tabPanes[this.activeName === 'simple' ? 0 : this.activeName === 'split_gradient' ? 1 : 2].data.forEach(item => {
|
||||||
if (item.value === this.colorDto.value) {
|
if (item.value === this.colorDto.value) {
|
||||||
item.colors = JSON.parse(JSON.stringify(this.colorDto.colors))
|
item.colors = JSON.parse(JSON.stringify(this.colorDto.colors))
|
||||||
}
|
}
|
||||||
@ -270,14 +303,15 @@ export default {
|
|||||||
return str
|
return str
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.tabPanes[1].data = JSON.parse(JSON.stringify(this.gradientColorCases))
|
const len = this.tabPanes.length
|
||||||
|
this.tabPanes[len - 1].data = JSON.parse(JSON.stringify(this.gradientColorCases))
|
||||||
},
|
},
|
||||||
formatBgColor(color, useValue) {
|
formatBgColor(color, useValue) {
|
||||||
let activeName = this.activeName
|
let activeName = this.activeName
|
||||||
if (useValue) {
|
if (useValue) {
|
||||||
activeName = this.colorCases.some(item => item.value === this.colorDto.value) ? 'simple' : 'gradient'
|
activeName = getColorType(this.colorDto.value)
|
||||||
}
|
}
|
||||||
if (activeName === 'simple') {
|
if (activeName === 'simple' || activeName === 'split_gradient') {
|
||||||
return color
|
return color
|
||||||
}
|
}
|
||||||
return 'linear-gradient(0.0deg,' + color[0] + ' 0.0,' + color[1] + ' 100.0%)'
|
return 'linear-gradient(0.0deg,' + color[0] + ' 0.0,' + color[1] + ' 100.0%)'
|
||||||
@ -296,11 +330,8 @@ export default {
|
|||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
if (this.colorDto.value) {
|
if (this.colorDto.value) {
|
||||||
let activeName = 'simple'
|
const activeName = getColorType(this.colorDto.value);
|
||||||
if (this.gradientColorCases.some(item => item.value === this.colorDto.value)) {
|
(activeName === 'simple' ? colorCases : activeName === 'split_gradient' ? getMapColorCases() : gradientColorCases).forEach(curcase => {
|
||||||
activeName = 'gradient'
|
|
||||||
}
|
|
||||||
(activeName === 'simple' ? colorCases : gradientColorCases).forEach(curcase => {
|
|
||||||
if (curcase.value === this.colorDto.value) {
|
if (curcase.value === this.colorDto.value) {
|
||||||
this.colorDto.colors = JSON.parse(JSON.stringify(curcase.colors))
|
this.colorDto.colors = JSON.parse(JSON.stringify(curcase.colors))
|
||||||
this.$emit('color-change', JSON.parse(JSON.stringify(this.colorDto)))
|
this.$emit('color-change', JSON.parse(JSON.stringify(this.colorDto)))
|
||||||
@ -318,7 +349,7 @@ export default {
|
|||||||
}
|
}
|
||||||
.gradient-popper {
|
.gradient-popper {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
padding: 0 10px;
|
padding: 0 10px !important;
|
||||||
margin-top: 1px !important;
|
margin-top: 1px !important;
|
||||||
border-top: none;
|
border-top: none;
|
||||||
height: 300px;
|
height: 300px;
|
||||||
@ -340,7 +371,8 @@ export default {
|
|||||||
.color-span-base {
|
.color-span-base {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
display:inline-block;
|
display:flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
.is-editor {
|
.is-editor {
|
||||||
width:23px !important;
|
width:23px !important;
|
||||||
@ -352,7 +384,11 @@ export default {
|
|||||||
align-items: center !important;
|
align-items: center !important;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding-left: 5px !important;
|
padding-left: 5px !important;
|
||||||
|
.static-editor:nth-child(2) {
|
||||||
|
margin-left: 5px !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-switch-div {
|
.custom-switch-div {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
@ -380,4 +416,11 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.is-split {
|
||||||
|
width: 28px !important;
|
||||||
|
}
|
||||||
|
.color-span-base-split {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -912,6 +912,9 @@ export default {
|
|||||||
password_input_error: 'Original password input error'
|
password_input_error: 'Original password input error'
|
||||||
},
|
},
|
||||||
chart: {
|
chart: {
|
||||||
|
solid_color: 'Solid color',
|
||||||
|
split_gradient: 'Split gradient',
|
||||||
|
continuous_gradient: 'Continuous gradient',
|
||||||
map_center_lost: 'The graph is missing the centroid or center attribute, please complete it and try again',
|
map_center_lost: 'The graph is missing the centroid or center attribute, please complete it and try again',
|
||||||
margin_model: 'Model',
|
margin_model: 'Model',
|
||||||
margin_model_auto: 'Auto',
|
margin_model_auto: 'Auto',
|
||||||
|
@ -912,6 +912,9 @@ export default {
|
|||||||
password_input_error: '原始密碼輸入錯誤'
|
password_input_error: '原始密碼輸入錯誤'
|
||||||
},
|
},
|
||||||
chart: {
|
chart: {
|
||||||
|
solid_color: '純色',
|
||||||
|
split_gradient: '分離漸變',
|
||||||
|
continuous_gradient: '連續漸變',
|
||||||
map_center_lost: '圖形缺失中心點centroid或center屬性,請補全後再試',
|
map_center_lost: '圖形缺失中心點centroid或center屬性,請補全後再試',
|
||||||
margin_model: '模式',
|
margin_model: '模式',
|
||||||
margin_model_auto: '自動',
|
margin_model_auto: '自動',
|
||||||
|
@ -911,6 +911,9 @@ export default {
|
|||||||
password_input_error: '原始密码输入错误'
|
password_input_error: '原始密码输入错误'
|
||||||
},
|
},
|
||||||
chart: {
|
chart: {
|
||||||
|
solid_color: '纯色',
|
||||||
|
split_gradient: '分离渐变',
|
||||||
|
continuous_gradient: '连续渐变',
|
||||||
map_center_lost: '图形缺失中心点centroid或center属性,请补全后再试',
|
map_center_lost: '图形缺失中心点centroid或center属性,请补全后再试',
|
||||||
margin_model: '模式',
|
margin_model: '模式',
|
||||||
margin_model_auto: '自动',
|
margin_model_auto: '自动',
|
||||||
|
Loading…
Reference in New Issue
Block a user