Images.san 4.4 KB
Newer Older
B
BingBlog 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
<template>
    <div class="visual-dl-scalar-container">
        <div class="visual-dl-scalar-left">
            <div class="visual-dl-scalar-config-container">
                <ui-config
                    runsItems="{{runsItems}}"
                    config="{=config=}"
                ></ui-config>
            </div>
        </div>
        <div class="visual-dl-scalar-right">
            <ui-chart-page
                config="{{config}}"
                runsItems="{{runsItems}}"
                tagList="{{filteredTagsList}}"
                title="Tags matching {{config.groupNameReg}}"
            ></ui-chart-page>
            <ui-chart-page
                san-for="item in groupedTags"
                config="{{config}}"
                runsItems="{{runsItems}}"
                tagList="{{item.tags}}"
                title="{{item.group}}"
            ></ui-chart-page>
        </div>
    </div>
</template>

<script>
import {getPluginImagesTags, getRuns} from '../service';
import config from './ui/config';
import chartPage from './ui/chartPage';
import {debounce, flatten, uniq} from 'lodash';
export default {
    components: {
        'ui-config': config,
        'ui-chart-page': chartPage
    },
    computed: {
        runsItems() {
            let runsArray = this.data.get('runsArray') || [];
            return runsArray.map(item => {
                return {
                    name: item,
                    value: item
                };
            });
        },
        tagsList() {
            let tags = this.data.get('tags');

            let runs = Object.keys(tags);
            let tagsArray = runs.map(run => Object.keys(tags[run]));
            let allUniqTags = uniq(flatten(tagsArray));

            // get the data for every chart
            return allUniqTags.map(tag => {
                let tagList = runs.map(run => {
                    return {
                        run,
                        tag: tags[run][tag]
                    };
                });
                return {
                    tagList,
                    tag,
                    group: tag.split('/')[0]
                };
            });
        },
        groupedTags() {
            let tagsList = this.data.get('tagsList') || [];
            // put data in group
            let groupData = {};
            tagsList.forEach(item => {
                let group = item.group;
                if (groupData[group] === undefined) {
                    groupData[group] = [];
                    groupData[group].push(item);
                }
                else {
                    groupData[group].push(item);
                }
            });

            // to array
            let groups = Object.keys(groupData);
            return groups.map(group => {
                return {
                    group,
                    tags: groupData[group]
                };
            });
        }
    },
    initData() {
        return {
            runsArray: [],
            tags: [],
            config: {
                groupNameReg: '.*',
                smoothing: '0.5',
                horizontal: '1',
                sortingMethod: '2',
                link: [],
                chart: []
            }
        };
    },
    inited() {
        getPluginImagesTags().then(({errno, data}) => {
            this.data.set('tags', data);

            // filter when inited
            let groupNameReg = this.data.get('config.groupNameReg');
            this.filterTagsList(groupNameReg);
        });
        getRuns().then(({errno, data}) => {
            this.data.set('runsArray', data);
        });

        // need debounce, can't use computed
        this.watch('config.groupNameReg', debounce(this.filterTagsList, 300));
    },

    filterTagsList(groupNameReg) {
        let tagsList = this.data.get('tagsList') || [];
        let regExp = new RegExp(groupNameReg);
        let filtedTagsList = tagsList.filter(item => regExp.test(item.tag));
        this.data.set('filteredTagsList', filtedTagsList);
    }
};

</script>

<style lang="stylus">

@import '../style/variables';

+prefix-classes('visual-dl-scalar-')
    .container
        padding-left 300px
        position relative
        .left
            width 280px
            min-height 300px
            border solid 1px #e4e4e4
            position absolute
            left 0
        .right
            width 100%
            border solid 1px #e4e4e4
            min-height 300px
            padding 20px
</style>