Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TimeSystemAxis.vue « components « ui « src - github.com/nasa/openmct.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d580b884e6ea3ba6339da4c6393b2c1d55bd9eec (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
<template>
<div
    ref="axisHolder"
    class="c-timesystem-axis"
>
    <div class="nowMarker"><span class="icon-arrow-down"></span></div>
</div>
</template>

<script>
import * as d3Selection from 'd3-selection';
import * as d3Axis from 'd3-axis';
import * as d3Scale from 'd3-scale';
import utcMultiTimeFormat from '@/plugins/timeConductor/utcMultiTimeFormat';

//TODO: UI direction needed for the following property values
const PADDING = 1;
const RESIZE_POLL_INTERVAL = 200;
const PIXELS_PER_TICK = 100;
const PIXELS_PER_TICK_WIDE = 200;
//This offset needs to be re-considered

export default {
    inject: ['openmct', 'domainObject'],
    props: {
        bounds: {
            type: Object,
            default() {
                return {};
            }
        },
        timeSystem: {
            type: Object,
            default() {
                return {};
            }
        },
        contentHeight: {
            type: Number,
            default() {
                return 0;
            }
        },
        renderingEngine: {
            type: String,
            default() {
                return 'svg';
            }
        },
        offset: {
            type: Number,
            default() {
                return 0;
            }
        }
    },
    watch: {
        bounds(newBounds) {
            this.drawAxis(newBounds, this.timeSystem);
        },
        timeSystem(newTimeSystem) {
            this.drawAxis(this.bounds, newTimeSystem);
        }
    },
    mounted() {
        if (this.renderingEngine === 'svg') {
            this.useSVG = true;
        }

        this.container = d3Selection.select(this.$refs.axisHolder);
        this.svgElement = this.container.append("svg:svg");
        // draw x axis with labels. CSS is used to position them.
        this.axisElement = this.svgElement.append("g")
            .attr("class", "axis")
            .attr('font-size', '1.3em')
            .attr("transform", "translate(0,20)");

        this.setDimensions();
        this.drawAxis(this.bounds, this.timeSystem);
        this.resizeTimer = setInterval(this.resize, RESIZE_POLL_INTERVAL);
    },
    destroyed() {
        clearInterval(this.resizeTimer);
    },
    methods: {
        resize() {
            if (this.$refs.axisHolder.clientWidth !== this.width) {
                this.setDimensions();
                this.drawAxis(this.bounds, this.timeSystem);
                this.updateNowMarker();
            }
        },
        updateNowMarker() {
            if (this.openmct.time.clock() === undefined) {
                let nowMarker = document.querySelector('.nowMarker');
                if (nowMarker) {
                    nowMarker.classList.add('hidden');
                }
            } else {
                let nowMarker = document.querySelector('.nowMarker');
                if (nowMarker) {
                    nowMarker.classList.remove('hidden');
                    nowMarker.style.height = this.contentHeight + 'px';
                    const now = this.xScale(Date.now());
                    nowMarker.style.left = now + this.offset + 'px';
                }
            }
        },
        setDimensions() {
            const axisHolder = this.$refs.axisHolder;
            this.width = axisHolder.clientWidth;
            this.offsetWidth = this.width - this.offset;

            this.height = Math.round(axisHolder.getBoundingClientRect().height);

            if (this.useSVG) {
                this.svgElement.attr("width", this.width);
                this.svgElement.attr("height", this.height);
            } else {
                this.svgElement.attr("height", 50);
            }
        },
        drawAxis(bounds, timeSystem) {
            let viewBounds = Object.create(bounds);

            this.setScale(viewBounds, timeSystem);
            this.setAxis(viewBounds);
            this.axisElement.call(this.xAxis);
            this.updateNowMarker();

        },
        setScale(bounds, timeSystem) {
            if (!this.width) {
                return;
            }

            if (timeSystem === undefined) {
                timeSystem = this.openmct.time.timeSystem();
            }

            if (timeSystem.isUTCBased) {
                this.xScale = d3Scale.scaleUtc();
                this.xScale.domain(
                    [new Date(bounds.start), new Date(bounds.end)]
                );
            } else {
                this.xScale = d3Scale.scaleLinear();
                this.xScale.domain(
                    [bounds.start, bounds.end]
                );
            }

            this.xScale.range([PADDING, this.offsetWidth - PADDING * 2]);
        },
        setAxis() {
            this.xAxis = d3Axis.axisTop(this.xScale);
            this.xAxis.tickFormat(utcMultiTimeFormat);

            if (this.width > 1800) {
                this.xAxis.ticks(this.offsetWidth / PIXELS_PER_TICK_WIDE);
            } else {
                this.xAxis.ticks(this.offsetWidth / PIXELS_PER_TICK);
            }
        }
    }
};
</script>