vue2 RelationGraph 人物关系 & 筛选 图片不显示

官网链接:relation-graph - A Relationship Graph Component

修改效果:

<template>
    <div>
        <div style="margin-top:0px;width: calc(100% - 10px);height:calc(100vh);">
            <RelationGraph ref="graphRef" :options="graphOptions">
                <!-- <template #node="{ node }">
                    <div class="my-node-style" :style="{ 'background-image': 'url(' + node.data.icon + ')' }">
                    </div>
                    <div class="c-node-name" :style="{ color: node.color }">{{ node.text }}</div>
                </template> -->
                <template #graph-plug>
                    <div
                        style="position:absolute;z-index:700;left:20px;top:20px;height:110px;padding-top:6px;padding-left: 30px;padding-right:30px;border: #efefef solid 1px;color: #555555;border-radius: 10px;background-color: rgba(255,255,255,0.79);font-size: 12px;">
                        <div style="">
                            <div style="line-height: 20px;">节点筛选:</div>
                            <el-radio-group v-model="checked_sex" size="mini" @change="doFilter">
                                <el-radio-button label="">全部</el-radio-button>
                                <el-radio-button label="男"></el-radio-button>
                                <el-radio-button label="女"></el-radio-button>
                            </el-radio-group>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <el-radio-group v-model="checked_isgoodman" size="mini" style="margin-left:50px;"
                                @change="doFilter">
                                <el-radio-button label="">全部</el-radio-button>
                                <el-radio-button :label="true">正面人物</el-radio-button>
                                <el-radio-button :label="false">反面人物</el-radio-button>
                            </el-radio-group>
                        </div>
                        <div>
                            <div style="line-height: 20px;">关系筛选:</div>
                            <el-checkbox-group v-model="rel_checkList" @change="doFilter">
                                <el-checkbox v-for="thisItem in all_rel_type" :key="thisItem" :label="thisItem" />
                            </el-checkbox-group>
                        </div>
                    </div>
                </template>
            </RelationGraph>
        </div>

    </div>
</template>

<script>
import RelationGraph from 'relation-graph';
import demoData from './Demo4AdvDataFilterData.json';
const graphOptions = {
    debug: false,
    defaultNodeBorderWidth: 0,
    defaultNodeColor: 'rgba(238, 178, 94, 1)',
    allowSwitchLineShape: true,
    allowSwitchJunctionPoint: true,
    defaultLineShape: 1,
    layout:
    {
        label: '自动布局',
        layoutName: 'force',
        layoutClassName: 'seeks-layout-force'
    },
    defaultJunctionPoint: 'border'

    // 这里可以参考"Graph 图谱"中的参数进行设置
};
export default {
    name: 'RelationGraphDemo',
    components: { RelationGraph },
    data() {
        return {
            g_loading: true,
            demoname: '---',
            checked_sex: '',
            checked_isgoodman: '',
            rel_checkList: ['师生', '上下级', '亲戚', '情人', '朋友', '夫妻', '勾结', '腐化', '举报'],
            all_rel_type: ['师生', '上下级', '亲戚', '情人', '朋友', '夫妻', '勾结', '腐化', '举报'],
            graphOptions
        };
    },
    created() {
    },
    mounted() {
        this.setGraphData();
    },
    methods: {
        setGraphData() {
            demoData.nodes.forEach(node => {
                node.innerHTML = `<div class="c-my-node" style="background-image: url(${node.data.icon}); 
                 background-size: 100%;height: 80px;width: 80px; border-radius: 40px;
                  border: 3px solid ${node.borderColor};">
                  <div class="c-node-name" style="color: ${node.borderColor};">${node.text}</div></div>`;
            });
            const __graph_json_data = demoData
            this.$refs.graphRef.setJsonData(__graph_json_data, (graphInstance) => {
            });
        },
        doFilter() {
            const _all_nodes = this.$refs.graphRef.getInstance().getNodes();
            const _all_links = this.$refs.graphRef.getInstance().getLinks();
            _all_nodes.forEach(thisNode => {
                let _isHideThisLine = false;
                if (this.checked_sex !== '') {
                    if (thisNode.data['sexType'] !== this.checked_sex) {
                        _isHideThisLine = true;
                    }
                }
                if (this.checked_isgoodman !== '') {
                    if (thisNode.data['isGoodMan'] !== this.checked_isgoodman) {
                        _isHideThisLine = true;
                    }
                }
                thisNode.opacity = _isHideThisLine ? 0.1 : 1;
            });
            _all_links.forEach(thisLink => {
                thisLink.relations.forEach(thisLine => {
                    if (this.rel_checkList.indexOf(thisLine.data['type']) === -1) {
                        if (!thisLine.isHide) {
                            thisLine.isHide = true;
                            console.log('Hide line:', thisLine);
                        }
                    } else {
                        if (thisLine.isHide) {
                            thisLine.isHide = false;
                            console.log('Show line:', thisLine);
                        }
                    }
                });
                // thisNode.opacity = _isShowThisNode ? 1 : 0.1
            });
            this.$refs.graphRef.getInstance().dataUpdated();
        }
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.c-my-node {
    background-position: center center;
    background-size: 100%;
    height: 80px;
    width: 80px;
    border-radius: 40px;
    border: #ff8c00 solid 2px;
}




.c-node-name {
    width: 160px;
    margin-left: -40px;
    text-align: center;
    margin-top: 85px;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值