-
Notifications
You must be signed in to change notification settings - Fork 13
/
Widths.vue
160 lines (134 loc) · 4.25 KB
/
Widths.vue
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
<template lang="pug">
.width-panel
.widgets
.widget
b-select.selector(expanded v-model="dataColumn")
option(label="None" value="")
optgroup(v-for="dataset in datasetChoices"
:key="dataset" :label="dataset")
option(v-for="column in numericColumnsInDataset(dataset)" :value="`${dataset}/${column}`" :label="column")
.widgets
.widget
p Scaling
b-field
b-input(:disabled="!dataColumn" v-model="xscaleFactor" placeholder="1.0" type="number")
//- .widgets
//- .widget
//- p Transform
//- b-field.has-addons
//- p.control(v-for="transform of transforms" :key="transform")
//- b-button.is-small(
//- :disabled="!dataColumn"
//- :class="{'is-warning': dataColumn && transform==selectedTransform}"
//- @click="selectedTransform=transform"
//- :title="dataColumn ? 'Transforms occur after scaling':'Select a data field first'"
//- ) {{ transform }}
</template>
<script lang="ts">
import { Vue, Component, Watch, Prop } from 'vue-property-decorator'
import { VizLayerConfiguration, DataTable, DataType } from '@/Globals'
export type WidthDefinition = {
dataset?: string
columnName: string
scaleFactor?: number
}
@Component({ components: {}, props: {} })
export default class VueComponent extends Vue {
@Prop() vizConfiguration!: VizLayerConfiguration
@Prop() datasets!: { [id: string]: DataTable }
private transforms = ['none', 'sqrt', 'pow5']
private dataColumn = ''
private xscaleFactor = '100'
private selectedTransform = this.transforms[0]
private datasetLabels = [] as string[]
private mounted() {
this.datasetsAreLoaded()
}
@Watch('vizConfiguration')
private vizConfigChanged() {
const config = this.vizConfiguration.display?.width
if (config?.columnName) {
const selectedColumn = `${config.dataset}/${config.columnName}`
this.dataColumn = selectedColumn
this.datasetLabels = [...this.datasetLabels]
}
}
@Watch('datasets')
private datasetsAreLoaded() {
const datasetIds = Object.keys(this.datasets)
const { dataset, columnName, scaleFactor } = this.vizConfiguration.display.width
if (dataset && columnName) {
console.log('SPECIFIED WIDTH: ', dataset, columnName, scaleFactor)
this.dataColumn = `${dataset}/${columnName}`
if (!!scaleFactor) this.xscaleFactor = '' + scaleFactor
} else if (datasetIds.length) {
const secondColumn = Object.keys(this.datasets[datasetIds[0]])[1]
if (secondColumn) this.dataColumn = `${datasetIds[0]}/${secondColumn}`
}
this.datasetLabels = datasetIds
}
@Watch('xscaleFactor')
@Watch('dataColumn')
private emitWidthSpecification() {
const slash = this.dataColumn.indexOf('/')
if (slash === -1) {
this.clickedSingle()
return
}
const dataset = this.dataColumn.substring(0, slash)
const columnName = this.dataColumn.substring(slash + 1)
const width: WidthDefinition = {
dataset,
columnName,
scaleFactor: parseFloat(this.xscaleFactor),
}
setTimeout(() => this.$emit('update', { width }), 50)
}
private clickedSingle() {
const width: WidthDefinition = {
dataset: '',
columnName: '',
scaleFactor: parseFloat(this.xscaleFactor),
}
// the link viewer is on main thread so lets make
// sure user gets some visual feedback
setTimeout(() => this.$emit('update', { width }), 50)
}
private get datasetChoices(): string[] {
return this.datasetLabels.filter(label => label !== 'csvBase')
}
private numericColumnsInDataset(datasetId: string): string[] {
const dataset = this.datasets[datasetId]
if (!dataset) return []
const allColumns = Object.keys(dataset).filter(
// skip first row, it has ID
(colName, i) => i > 0 && dataset[colName].type === DataType.NUMBER
)
return allColumns
}
}
</script>
<style scoped lang="scss">
@import '@/styles.scss';
.width-panel {
padding-right: 0rem;
}
.widgets {
display: flex;
margin-bottom: 0.5rem;
p {
margin-top: 5px;
font-size: 1rem;
margin-right: 1rem;
}
}
.widget {
flex: 1;
margin-right: 0.75rem;
}
.selector {
margin-top: 0.75rem;
overflow-x: auto;
max-width: 100%;
}
</style>