# All files / src/lib workflow.js

100% Statements 17/17
100% Branches 2/2
100% Functions 9/9
100% Lines 14/14

    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
    411x
    43x

    1x
    30x
    43x
    20x
    8x

    35x

    10x
    10x

    45x
    45x

    15x

    15x

     const addSize = (sizeCalculation, classes) =>
        item => ({ ...item, ...sizeCalculation.ofDivWith(item, classes) });

    const addStylingClassesFor = (semantics, isItemId) =>
        item => {
            for(const semantic of semantics) {
                if(isItemId(semantic.id, item)) {
                    return { ...item, stylingClass: semantic.classname };
                }
            }
            return item;
        };

    const isSelectedState = (id, state) => id === state.id;
    const isTransitionTarget = (id, transition) => id === transition.target;

    export default class Workflow {

        constructor({ states, transitions }) {
            this.states = states;
            this.transitions = transitions;
        }

        addLabelSize(sizeCalculation) {
            return new Workflow({
                states: this.states.map(addSize(sizeCalculation, 'vue-workflow-chart-state')),
                transitions: this.transitions.map(
                    addSize(sizeCalculation, 'vue-workflow-chart-transition-label')),
            });
        }

        addStylingClassesFor(semantics) {
            return new Workflow({
                states: this.states.map(addStylingClassesFor(semantics, isSelectedState)),
                transitions: this.transitions.map(
                    addStylingClassesFor(semantics, isTransitionTarget)),
            });
        }
    }