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

plugin.js « scatter « charts « plugins « src - github.com/nasa/openmct.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 600c2970fdd34590da416d0015ea6614dc0f6a32 (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
/*****************************************************************************
 * Open MCT, Copyright (c) 2014-2022, United States Government
 * as represented by the Administrator of the National Aeronautics and Space
 * Administration. All rights reserved.
 *
 * Open MCT is licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 * Open MCT includes source code licensed under additional open source
 * licenses. See the Open Source Licenses file (LICENSES.md) included with
 * this source code distribution or the Licensing information page available
 * at runtime from the About dialog for additional information.
 *****************************************************************************/
import { SCATTER_PLOT_KEY } from './scatterPlotConstants.js';
import ScatterPlotViewProvider from './ScatterPlotViewProvider';
import ScatterPlotInspectorViewProvider from './inspector/ScatterPlotInspectorViewProvider';
import ScatterPlotCompositionPolicy from './ScatterPlotCompositionPolicy';
import Vue from "vue";
import ScatterPlotForm from "./ScatterPlotForm.vue";

export default function () {
    return function install(openmct) {
        openmct.forms.addNewFormControl('scatter-plot-form-control', getScatterPlotFormControl(openmct));

        openmct.types.addType(SCATTER_PLOT_KEY, {
            key: SCATTER_PLOT_KEY,
            name: "Scatter Plot",
            cssClass: "icon-plot-scatter",
            description: "View data as a scatter plot.",
            creatable: true,
            initialize: function (domainObject) {
                domainObject.composition = [];
                domainObject.configuration = {
                    styles: {},
                    axes: {},
                    ranges: {}
                };
            },
            form: [
                {
                    name: 'Underlay data (JSON file)',
                    key: 'selectFile',
                    control: 'file-input',
                    text: 'Select File...',
                    type: 'application/json',
                    removable: true,
                    hideFromInspector: true,
                    property: [
                        "selectFile"
                    ]
                },
                {
                    name: "Underlay ranges",
                    control: "scatter-plot-form-control",
                    cssClass: "l-input",
                    key: "scatterPlotForm",
                    required: false,
                    hideFromInspector: false,
                    property: [
                        "configuration",
                        "ranges"
                    ],
                    validate: ({ value }, callback) => {
                        const { rangeMin, rangeMax, domainMin, domainMax } = value;
                        const valid = {
                            rangeMin,
                            rangeMax,
                            domainMin,
                            domainMax
                        };

                        if (callback) {
                            callback(valid);
                        }

                        const values = Object.values(valid);
                        const hasAllValues = values.every(rangeValue => rangeValue !== undefined);
                        const hasNoValues = values.every(rangeValue => rangeValue === undefined);

                        return hasAllValues || hasNoValues;
                    }
                }
            ],
            priority: 891
        });

        openmct.objectViews.addProvider(new ScatterPlotViewProvider(openmct));

        openmct.inspectorViews.addProvider(new ScatterPlotInspectorViewProvider(openmct));

        openmct.composition.addPolicy(new ScatterPlotCompositionPolicy(openmct).allow);
    };

    function getScatterPlotFormControl(openmct) {
        return {
            show(element, model, onChange) {
                const rowComponent = new Vue({
                    el: element,
                    components: {
                        ScatterPlotForm
                    },
                    provide: {
                        openmct
                    },
                    data() {
                        return {
                            model,
                            onChange
                        };
                    },
                    template: `<scatter-plot-form :model="model" @onChange="onChange"></scatter-plot-form>`
                });

                return rowComponent;
            }
        };
    }
}