@dataloop-ai/components 0.16.45 → 0.16.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -2
- package/package.json +10 -9
- package/src/App.vue +116 -57
- package/src/assets/globals.scss +2 -0
- package/src/components/basic/DlAlert/DlAlert.vue +1 -1
- package/src/components/basic/DlButton/DlButton.vue +13 -13
- package/src/components/basic/DlCard/DlCard.vue +217 -0
- package/src/components/basic/DlCard/index.ts +3 -0
- package/src/components/basic/DlCard/types.ts +20 -0
- package/src/components/basic/DlChip/DlChip.vue +1 -0
- package/src/components/basic/DlEllipsis/DlEllipsis.vue +90 -0
- package/src/components/basic/DlEllipsis/index.ts +2 -0
- package/src/components/basic/DlListItem/DlListItem.vue +11 -5
- package/src/components/basic/index.ts +2 -0
- package/src/components/compound/DlCharts/charts/DlBarChart/DlBarChart.vue +8 -1
- package/src/components/compound/DlCharts/charts/DlColumnChart/DlColumnChart.vue +22 -6
- package/src/components/compound/DlCharts/charts/DlConfusionMatrix/DlConfusionMatrix.vue +526 -0
- package/src/components/compound/DlCharts/charts/DlConfusionMatrix/index.ts +2 -0
- package/src/components/compound/DlCharts/charts/DlConfusionMatrix/utils.ts +96 -0
- package/src/components/compound/DlCharts/charts/DlDoughnutChart/DlDoughnutChart.vue +2 -2
- package/src/components/compound/DlCharts/charts/DlLineChart/DlLineChart.vue +22 -6
- package/src/components/compound/DlCharts/charts/index.ts +1 -0
- package/src/components/compound/DlCharts/components/DlBrush.vue +8 -1
- package/src/components/compound/DlCharts/components/DlChartScrollBar.vue +34 -21
- package/src/components/compound/DlCharts/types/DlConfusionMatrix.types.ts +19 -0
- package/src/components/compound/DlCharts/types/index.ts +2 -1
- package/src/components/compound/DlCharts/types/props.ts +14 -0
- package/src/components/compound/DlDialogBox/DlDialogBox.vue +1 -1
- package/src/components/compound/DlDialogBox/components/DlDialogBoxFooter.vue +1 -0
- package/src/components/compound/DlDropdownButton/DlDropdownButton.vue +58 -12
- package/src/components/compound/DlInput/DlInput.vue +45 -23
- package/src/components/compound/DlJsonEditor/DlJsonEditor.vue +13 -29
- package/src/components/compound/DlPagination/DlPagination.vue +14 -4
- package/src/components/compound/DlPagination/components/PageNavigation.vue +24 -25
- package/src/components/compound/DlPagination/components/PaginationLegend.vue +2 -1
- package/src/components/compound/DlPagination/components/QuickNavigation.vue +1 -0
- package/src/components/compound/DlSearches/DlSmartSearch/DlSmartSearch.vue +86 -49
- package/src/components/compound/DlSearches/DlSmartSearch/components/DlSmartSearchInput.vue +20 -13
- package/src/components/compound/DlSearches/DlSmartSearch/components/DlSuggestionsDropdown.vue +43 -4
- package/src/components/compound/DlSearches/DlSmartSearch/utils/highlightSyntax.ts +1 -55
- package/src/components/compound/DlSearches/DlSmartSearch/utils/index.ts +42 -10
- package/src/components/compound/DlSearches/DlSmartSearch/utils/utils.ts +107 -0
- package/src/components/compound/DlSelect/DlSelect.vue +41 -8
- package/src/components/compound/DlTable/DlTable.vue +13 -10
- package/src/components/compound/DlTable/styles/dl-table-styles.scss +16 -4
- package/src/components/compound/DlToggleButton/DlToggleButton.vue +109 -0
- package/src/components/compound/DlToggleButton/config.ts +27 -0
- package/src/components/compound/DlToggleButton/index.ts +3 -0
- package/src/components/compound/DlToggleButton/types.ts +4 -0
- package/src/components/compound/index.ts +1 -0
- package/src/components/compound/types.ts +1 -0
- package/src/components/essential/DlColorPicker/DlColorPicker.vue +4 -1
- package/src/components/essential/DlColorPicker/components/DlColors.vue +2 -6
- package/src/components/essential/DlIcon/DlIcon.vue +5 -1
- package/src/components/essential/DlMenu/DlMenu.vue +30 -2
- package/src/components/essential/DlSeparator/DlSeparator.vue +62 -0
- package/src/components/essential/DlSeparator/index.ts +2 -0
- package/src/components/essential/DlSpinner/DlSpinner.vue +53 -217
- package/src/components/essential/DlSpinner/components/DlSpinnerCircle.vue +44 -0
- package/src/components/essential/DlSpinner/components/DlSpinnerClock.vue +79 -0
- package/src/components/essential/DlSpinner/components/DlSpinnerDots.vue +113 -0
- package/src/components/essential/DlSpinner/components/DlSpinnerGrid.vue +166 -0
- package/src/components/essential/DlSpinner/components/DlSpinnerLogo.vue +152 -0
- package/src/components/essential/DlSpinner/index.ts +14 -1
- package/src/components/essential/DlSpinner/styles/spinnerStyles.scss +111 -0
- package/src/components/essential/DlSpinner/types.ts +7 -0
- package/src/components/essential/index.ts +1 -0
- package/src/components/essential/types.ts +1 -0
- package/src/components/shared/DlItemSection/DlItemSection.vue +21 -15
- package/src/components/shared/DlVirtualScroll/DlVirtualScroll.vue +36 -21
- package/src/components/shared/DlVirtualScroll/useVirtualScroll.ts +8 -10
- package/src/{demo → demos}/DlButtonDemo.vue +15 -0
- package/src/demos/DlCardDemo.vue +47 -0
- package/src/{demo → demos}/DlColorPickerDemo.vue +16 -1
- package/src/demos/DlConfusionMatrixDemo.vue +53 -0
- package/src/{demo → demos}/DlDialogBoxDemo.vue +4 -1
- package/src/demos/DlDropdownButtonDemo.vue +386 -0
- package/src/demos/DlEllipsisDemo.vue +30 -0
- package/src/{demo → demos}/DlLineChartDemo.vue +8 -8
- package/src/{demo → demos}/DlMenuDemo.vue +61 -2
- package/src/{demo → demos}/DlSearchDemo.vue +3 -2
- package/src/demos/DlSeparatorDemo.vue +44 -0
- package/src/demos/DlSpinnerDemo.vue +59 -0
- package/src/{demo → demos}/DlTableDemo.vue +117 -29
- package/src/demos/DlToggleButtonDemo.vue +57 -0
- package/src/{demo → demos}/DlTooltipDemo.vue +43 -2
- package/src/{demo → demos}/DlWidgetDemo.vue +34 -19
- package/src/{demo → demos}/SmartSearchDemo/DlSmartSearchDemo.vue +2 -50
- package/src/{demo → demos}/index.ts +14 -56
- package/src/hooks/use-arrow-navigation.ts +58 -0
- package/src/hooks/use-suggestions.ts +97 -74
- package/src/utils/colors.ts +1 -1
- package/src/utils/draggable-table.ts +2 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/parse-smart-query.ts +87 -0
- package/src/components/compound/DlCharts/types.ts +0 -1
- package/src/demo/DlDropdownButtonDemo.vue +0 -260
- package/src/demo/DlSpinnerDemo.vue +0 -20
- /package/src/{demo → demos}/BarChartDemo.vue +0 -0
- /package/src/{demo → demos}/ColumnChartDemo.vue +0 -0
- /package/src/{demo → demos}/DlAccordionDemo.vue +0 -0
- /package/src/{demo → demos}/DlAlertDemo.vue +0 -0
- /package/src/{demo → demos}/DlAvatarDemo.vue +0 -0
- /package/src/{demo → demos}/DlBadgeDemo.vue +0 -0
- /package/src/{demo → demos}/DlChartDoughnutDemo.vue +0 -0
- /package/src/{demo → demos}/DlCheckboxDemo.vue +0 -0
- /package/src/{demo → demos}/DlChipDemo.vue +0 -0
- /package/src/{demo → demos}/DlCounterDemo.vue +0 -0
- /package/src/{demo → demos}/DlDateTimeRangeDemo.vue +0 -0
- /package/src/{demo → demos}/DlIconDemo.vue +0 -0
- /package/src/{demo → demos}/DlInputDemo.vue +0 -0
- /package/src/{demo → demos}/DlKpiDemo.vue +0 -0
- /package/src/{demo → demos}/DlLinkDemo.vue +0 -0
- /package/src/{demo → demos}/DlListDemo.vue +0 -0
- /package/src/{demo → demos}/DlOptionGroupDemo.vue +0 -0
- /package/src/{demo → demos}/DlPaginationDemo.vue +0 -0
- /package/src/{demo → demos}/DlPanelContainerDemo.vue +0 -0
- /package/src/{demo → demos}/DlPopupDemo.vue +0 -0
- /package/src/{demo → demos}/DlProgressBarDemo.vue +0 -0
- /package/src/{demo → demos}/DlProgressChartDemo.vue +0 -0
- /package/src/{demo → demos}/DlRadioDemo.vue +0 -0
- /package/src/{demo → demos}/DlRangeDemo.vue +0 -0
- /package/src/{demo → demos}/DlSelectDemo.vue +0 -0
- /package/src/{demo → demos}/DlSkeletonDemo.vue +0 -0
- /package/src/{demo → demos}/DlSliderDemo.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/CenteredStepperInDialogBox.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/DlStepperDemo.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/SimpleStepper.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/StepperInDialogBox.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/index.ts +0 -0
- /package/src/{demo → demos}/DlStepperDemo/steps/AssignmentsStep.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/steps/DataStep.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/steps/GeneralStep.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/steps/InstructionStep.vue +0 -0
- /package/src/{demo → demos}/DlStepperDemo/steps/QualityStep.vue +0 -0
- /package/src/{demo → demos}/DlSwitchDemo.vue +0 -0
- /package/src/{demo → demos}/DlTabsDemo.vue +0 -0
- /package/src/{demo → demos}/DlTdDemo.vue +0 -0
- /package/src/{demo → demos}/DlTextAreaDemo.vue +0 -0
- /package/src/{demo → demos}/DlTextHolderDemo.vue +0 -0
- /package/src/{demo → demos}/DlThDemo.vue +0 -0
- /package/src/{demo → demos}/DlToastDemo.vue +0 -0
- /package/src/{demo → demos}/DlTrDemo.vue +0 -0
- /package/src/{demo → demos}/DlTrendDemo.vue +0 -0
- /package/src/{demo → demos}/DlTypographyDemo.vue +0 -0
- /package/src/{demo → demos}/SmartSearchDemo/schema.ts +0 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:style="`max-width: ${maxWidth}`"
|
|
4
|
+
class="confusion-matrix-container"
|
|
5
|
+
>
|
|
6
|
+
<div
|
|
7
|
+
v-if="isValidMatrix"
|
|
8
|
+
ref="wrapper"
|
|
9
|
+
:style="matrixStyles"
|
|
10
|
+
class="wrapper"
|
|
11
|
+
>
|
|
12
|
+
<span
|
|
13
|
+
ref="labelY"
|
|
14
|
+
class="label-tag y"
|
|
15
|
+
>
|
|
16
|
+
{{ leftLabel }}
|
|
17
|
+
</span>
|
|
18
|
+
<div
|
|
19
|
+
ref="yAxisOuter"
|
|
20
|
+
class="y-axis-outer"
|
|
21
|
+
>
|
|
22
|
+
<div
|
|
23
|
+
ref="yAxis"
|
|
24
|
+
class="y-axis"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
v-for="(label, index) in labels"
|
|
28
|
+
:key="index"
|
|
29
|
+
class="y-axis__element"
|
|
30
|
+
>
|
|
31
|
+
<img
|
|
32
|
+
v-if="labelImages[0]"
|
|
33
|
+
class="legend-avatar"
|
|
34
|
+
:src="labelImages[index]"
|
|
35
|
+
>
|
|
36
|
+
<span v-else>
|
|
37
|
+
{{ label }}
|
|
38
|
+
</span>
|
|
39
|
+
<dl-tooltip :offset="[0, 0]">
|
|
40
|
+
{{ labelStrings[index] }}
|
|
41
|
+
</dl-tooltip>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div
|
|
46
|
+
ref="verticalWrapper"
|
|
47
|
+
class="vertical_wrapper"
|
|
48
|
+
>
|
|
49
|
+
<div
|
|
50
|
+
ref="matrixWrapper"
|
|
51
|
+
class="matrix-wrapper"
|
|
52
|
+
@scroll="handleMatrixScroll"
|
|
53
|
+
>
|
|
54
|
+
<div
|
|
55
|
+
ref="matrix"
|
|
56
|
+
class="matrix"
|
|
57
|
+
>
|
|
58
|
+
<div
|
|
59
|
+
v-for="cell in flattenedMatrix"
|
|
60
|
+
:key="`${cell.x}-${cell.y}`"
|
|
61
|
+
class="matrix__cell"
|
|
62
|
+
:style="`background-color: ${getCellBackground(
|
|
63
|
+
cell.value
|
|
64
|
+
)}; color: var(--dl-color-text${
|
|
65
|
+
cell.value < 0.5 ? '-darker' : ''
|
|
66
|
+
}-buttons)`"
|
|
67
|
+
@mouseenter="handleShowTooltip(cell, $event)"
|
|
68
|
+
@mouseleave="handleHideTooltip"
|
|
69
|
+
@mousedown="openLink(cell)"
|
|
70
|
+
>
|
|
71
|
+
{{
|
|
72
|
+
cell.value > 0
|
|
73
|
+
? normalized
|
|
74
|
+
? cell.value
|
|
75
|
+
: cell.unnormalizedValue
|
|
76
|
+
: null
|
|
77
|
+
}}
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="x-axis">
|
|
82
|
+
<span
|
|
83
|
+
v-for="(label, index) in visibleLabels"
|
|
84
|
+
:key="index"
|
|
85
|
+
class="x-axis__element"
|
|
86
|
+
:style="`${
|
|
87
|
+
!labelImages[0] ? 'transform: rotate(70deg);' : ''
|
|
88
|
+
}`"
|
|
89
|
+
>
|
|
90
|
+
<span class="x-axis__element--text">
|
|
91
|
+
<img
|
|
92
|
+
v-if="labelImages[0]"
|
|
93
|
+
class="legend-avatar"
|
|
94
|
+
:src="labelImages[index]"
|
|
95
|
+
>
|
|
96
|
+
<span v-else>
|
|
97
|
+
{{ label }}
|
|
98
|
+
</span>
|
|
99
|
+
<dl-tooltip> {{ labelStrings[index] }}</dl-tooltip>
|
|
100
|
+
</span>
|
|
101
|
+
</span>
|
|
102
|
+
</div>
|
|
103
|
+
<dl-brush
|
|
104
|
+
track-size="18px"
|
|
105
|
+
thumb-size="20px"
|
|
106
|
+
:max="matrix.length"
|
|
107
|
+
:max-range="2"
|
|
108
|
+
:selection-color="getCellBackground(0.1)"
|
|
109
|
+
:color="getCellBackground()"
|
|
110
|
+
:step="1"
|
|
111
|
+
drag-range
|
|
112
|
+
@update:model-value="handleBrushUpdate"
|
|
113
|
+
/>
|
|
114
|
+
<span class="label-tag x"> {{ bottomLabel }} </span>
|
|
115
|
+
</div>
|
|
116
|
+
<div
|
|
117
|
+
ref="colorSpectrum"
|
|
118
|
+
class="color-spectrum"
|
|
119
|
+
>
|
|
120
|
+
<div class="color-spectrum__gradient" />
|
|
121
|
+
<div class="color-spectrum__gradation">
|
|
122
|
+
<div
|
|
123
|
+
v-for="value in gradationValues"
|
|
124
|
+
:key="value"
|
|
125
|
+
class="color-spectrum__gradation--element"
|
|
126
|
+
>
|
|
127
|
+
<span class="color-spectrum__gradation--element-line">-</span>
|
|
128
|
+
{{ value !== gradationValues[0] ? value : null }}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
<div
|
|
134
|
+
v-else
|
|
135
|
+
class="invalid"
|
|
136
|
+
>
|
|
137
|
+
The given props cannot create a valid matrix.
|
|
138
|
+
</div>
|
|
139
|
+
<div
|
|
140
|
+
v-if="tooltipState?.visible"
|
|
141
|
+
:style="tooltipStyles"
|
|
142
|
+
class="tooltip"
|
|
143
|
+
>
|
|
144
|
+
<span class="tooltip__x">{{ tooltipState.xLabel }}</span>
|
|
145
|
+
<span class="tooltip__y">{{ tooltipState.yLabel }}</span>
|
|
146
|
+
<span>
|
|
147
|
+
<span
|
|
148
|
+
v-if="tooltipState.value"
|
|
149
|
+
class="tooltip__color"
|
|
150
|
+
:style="`background-color: ${getCellBackground(
|
|
151
|
+
tooltipState.value
|
|
152
|
+
)}`"
|
|
153
|
+
/>
|
|
154
|
+
{{ normalized ? 'Normalized' : 'Unnormalized' }}
|
|
155
|
+
{{ tooltipState.value }}
|
|
156
|
+
</span>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</template>
|
|
160
|
+
|
|
161
|
+
<script lang="ts">
|
|
162
|
+
import { defineComponent, PropType } from 'vue-demi'
|
|
163
|
+
import DlBrush from '../../components/DlBrush.vue'
|
|
164
|
+
import DlTooltip from '../../../../essential/DlTooltip/DlTooltip.vue'
|
|
165
|
+
import {
|
|
166
|
+
DlConfusionMatrixCell,
|
|
167
|
+
DlConfusionMatrixLabel,
|
|
168
|
+
DlConfusionMatrixBrushState
|
|
169
|
+
} from '../../types'
|
|
170
|
+
import { hexToRgbA } from '../../../../../utils/colors'
|
|
171
|
+
import { colorNames } from '../../../../../utils/css-color-names'
|
|
172
|
+
import { useThemeVariables } from '../../../../../hooks/use-theme'
|
|
173
|
+
import {
|
|
174
|
+
getGradationValues,
|
|
175
|
+
validateMatrix,
|
|
176
|
+
setZoom,
|
|
177
|
+
getCellWidth,
|
|
178
|
+
flattenConfusionMatrix
|
|
179
|
+
} from './utils'
|
|
180
|
+
import { debounce } from 'lodash'
|
|
181
|
+
export default defineComponent({
|
|
182
|
+
components: {
|
|
183
|
+
DlBrush,
|
|
184
|
+
DlTooltip
|
|
185
|
+
},
|
|
186
|
+
props: {
|
|
187
|
+
labels: {
|
|
188
|
+
required: true,
|
|
189
|
+
type: Array as PropType<string[] | DlConfusionMatrixLabel[]>,
|
|
190
|
+
default: (): string[] | DlConfusionMatrixLabel[] => []
|
|
191
|
+
},
|
|
192
|
+
matrix: {
|
|
193
|
+
required: true,
|
|
194
|
+
type: Array as PropType<number[][] | DlConfusionMatrixCell[][]>,
|
|
195
|
+
default: (): number[][] | DlConfusionMatrixCell[][] => []
|
|
196
|
+
},
|
|
197
|
+
normalized: {
|
|
198
|
+
type: Boolean,
|
|
199
|
+
default: true
|
|
200
|
+
},
|
|
201
|
+
color: {
|
|
202
|
+
type: String,
|
|
203
|
+
default: '--dl-color-secondary'
|
|
204
|
+
},
|
|
205
|
+
bottomLabel: {
|
|
206
|
+
type: String,
|
|
207
|
+
default: 'Predicted Label'
|
|
208
|
+
},
|
|
209
|
+
leftLabel: {
|
|
210
|
+
type: String,
|
|
211
|
+
default: 'True Label'
|
|
212
|
+
},
|
|
213
|
+
maxWidth: {
|
|
214
|
+
type: String,
|
|
215
|
+
default: '800px'
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
setup(props) {
|
|
219
|
+
const { variables } = useThemeVariables()
|
|
220
|
+
|
|
221
|
+
const getCellBackground = (value: number = 1) => {
|
|
222
|
+
return hexToRgbA(
|
|
223
|
+
{ ...variables, ...colorNames }[props.color],
|
|
224
|
+
value
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
return { variables, getCellBackground }
|
|
228
|
+
},
|
|
229
|
+
data(): {
|
|
230
|
+
tooltipState: { x: string; y: string } | null
|
|
231
|
+
currentBrushState: { min: number; max: number }
|
|
232
|
+
cellWidth: number
|
|
233
|
+
} {
|
|
234
|
+
return {
|
|
235
|
+
tooltipState: null,
|
|
236
|
+
currentBrushState: { min: 0, max: this.matrix.length },
|
|
237
|
+
cellWidth: null
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
computed: {
|
|
241
|
+
visibleLabels(): string[] | DlConfusionMatrixLabel[] {
|
|
242
|
+
return this.labels.slice(
|
|
243
|
+
this.currentBrushState.min,
|
|
244
|
+
this.currentBrushState.max
|
|
245
|
+
)
|
|
246
|
+
},
|
|
247
|
+
labelStrings(): string[] | DlConfusionMatrixLabel[] {
|
|
248
|
+
if (typeof this.labels[0] === 'object')
|
|
249
|
+
return this.labels.map((label: any) => label.title)
|
|
250
|
+
else return this.labels
|
|
251
|
+
},
|
|
252
|
+
labelImages(): string[] {
|
|
253
|
+
return this.visibleLabels.map((label: any) => label.image)
|
|
254
|
+
},
|
|
255
|
+
isValidMatrix(): boolean {
|
|
256
|
+
return validateMatrix(this.matrix, this.labels)
|
|
257
|
+
},
|
|
258
|
+
flattenedMatrix(): DlConfusionMatrixCell[] {
|
|
259
|
+
return flattenConfusionMatrix(this.matrix, this.labelStrings)
|
|
260
|
+
},
|
|
261
|
+
matrixStyles(): object {
|
|
262
|
+
return {
|
|
263
|
+
'--matrix-rows': this.matrix.length,
|
|
264
|
+
'--cell-dimensions': `${this.cellWidth}px`,
|
|
265
|
+
'--general-color': this.getCellBackground()
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
tooltipStyles(): object {
|
|
269
|
+
return {
|
|
270
|
+
left: `${this.tooltipState?.x + 10}px`,
|
|
271
|
+
top: `${this.tooltipState?.y + 15}px`
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
gradationValues(): number[] {
|
|
275
|
+
return this.normalized
|
|
276
|
+
? [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
277
|
+
: getGradationValues(this.matrix)
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
mounted() {
|
|
281
|
+
if (!this.isValidMatrix) return
|
|
282
|
+
this.resizeMatrix()
|
|
283
|
+
const resizeObserver = new ResizeObserver(this.resizeMatrix)
|
|
284
|
+
resizeObserver.observe(this.$refs.wrapper as Element)
|
|
285
|
+
window.onresize = this.resizeMatrix
|
|
286
|
+
},
|
|
287
|
+
methods: {
|
|
288
|
+
resizeMatrix() {
|
|
289
|
+
const colorSpectrum = this.$refs.colorSpectrum as HTMLElement
|
|
290
|
+
const verticalWrapper = this.$refs.verticalWrapper as HTMLElement
|
|
291
|
+
const labelY = this.$refs.labelY as HTMLElement
|
|
292
|
+
const yAxisOuter = this.$refs.yAxisOuter as HTMLElement
|
|
293
|
+
const width = verticalWrapper?.offsetWidth
|
|
294
|
+
|
|
295
|
+
labelY.style.marginTop = `-${this.leftLabel.length * 16}px`
|
|
296
|
+
this.cellWidth = width / this.matrix.length
|
|
297
|
+
colorSpectrum.style.height = `${width}px`
|
|
298
|
+
yAxisOuter.style.height = `${width}px`
|
|
299
|
+
},
|
|
300
|
+
handleBrushUpdate(brush: DlConfusionMatrixBrushState) {
|
|
301
|
+
if (
|
|
302
|
+
brush.min === this.currentBrushState.min &&
|
|
303
|
+
brush.max === this.currentBrushState.max
|
|
304
|
+
)
|
|
305
|
+
return
|
|
306
|
+
this.updateBrush(this, brush)
|
|
307
|
+
},
|
|
308
|
+
updateBrush: debounce(
|
|
309
|
+
(ctx: any, brush: DlConfusionMatrixBrushState) => {
|
|
310
|
+
setZoom(
|
|
311
|
+
ctx.matrix.length / (brush.max - brush.min),
|
|
312
|
+
ctx.$refs.matrix
|
|
313
|
+
)
|
|
314
|
+
const scroll = brush.min * getCellWidth() + 2
|
|
315
|
+
const container = ctx.$refs.matrixWrapper
|
|
316
|
+
container.scroll(scroll, scroll)
|
|
317
|
+
ctx.currentBrushState = brush
|
|
318
|
+
ctx.resizeYAxis()
|
|
319
|
+
},
|
|
320
|
+
30
|
|
321
|
+
),
|
|
322
|
+
resizeYAxis() {
|
|
323
|
+
(this.$refs.yAxis as HTMLElement).style.height = `${
|
|
324
|
+
getCellWidth() * this.matrix.length
|
|
325
|
+
}px`
|
|
326
|
+
},
|
|
327
|
+
handleMatrixScroll(e: MouseEvent) {
|
|
328
|
+
const target = e.target as HTMLElement
|
|
329
|
+
;(this.$refs.yAxisOuter as HTMLElement).scroll(0, target.scrollTop)
|
|
330
|
+
},
|
|
331
|
+
handleShowTooltip(cell: DlConfusionMatrixCell, e: MouseEvent) {
|
|
332
|
+
this.showTooltip(this, cell, e)
|
|
333
|
+
},
|
|
334
|
+
handleHideTooltip() {
|
|
335
|
+
this.hideTooltip(this)
|
|
336
|
+
},
|
|
337
|
+
showTooltip: debounce(
|
|
338
|
+
(ctx: any, cell: DlConfusionMatrixCell, e: MouseEvent) => {
|
|
339
|
+
ctx.tooltipState = {
|
|
340
|
+
value: ctx.normalized ? cell.value : cell.unnormalizedValue,
|
|
341
|
+
xLabel: cell.xLabel,
|
|
342
|
+
yLabel: cell.yLabel,
|
|
343
|
+
x: e.pageX,
|
|
344
|
+
y: e.pageY,
|
|
345
|
+
visible: true
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
200
|
|
349
|
+
),
|
|
350
|
+
hideTooltip: debounce((ctx: any) => {
|
|
351
|
+
if (ctx?.tooltipState) ctx.tooltipState.visible = false
|
|
352
|
+
}, 200),
|
|
353
|
+
openLink(cell: DlConfusionMatrixCell) {
|
|
354
|
+
if (!cell.link) return
|
|
355
|
+
window.open(cell.link, '_blank')
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
</script>
|
|
360
|
+
|
|
361
|
+
<style lang="scss">
|
|
362
|
+
.confusion-matrix-container {
|
|
363
|
+
margin: auto;
|
|
364
|
+
}
|
|
365
|
+
.wrapper {
|
|
366
|
+
display: flex;
|
|
367
|
+
width: 100%;
|
|
368
|
+
height: 100%;
|
|
369
|
+
user-select: none;
|
|
370
|
+
}
|
|
371
|
+
.vertical_wrapper {
|
|
372
|
+
width: 80%;
|
|
373
|
+
display: flex;
|
|
374
|
+
flex-direction: column;
|
|
375
|
+
align-items: center;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.label-tag {
|
|
379
|
+
font-size: 0.8em;
|
|
380
|
+
color: var(--dl-color-medium);
|
|
381
|
+
}
|
|
382
|
+
.label-tag.y {
|
|
383
|
+
writing-mode: vertical-rl;
|
|
384
|
+
transform: rotate(180deg);
|
|
385
|
+
text-align: center;
|
|
386
|
+
margin-right: 10px;
|
|
387
|
+
}
|
|
388
|
+
.label-tag.x {
|
|
389
|
+
margin-top: 15px;
|
|
390
|
+
}
|
|
391
|
+
.x-axis {
|
|
392
|
+
width: 100%;
|
|
393
|
+
display: flex;
|
|
394
|
+
justify-content: space-between;
|
|
395
|
+
margin-top: 10px;
|
|
396
|
+
min-height: 100px;
|
|
397
|
+
max-height: 100px;
|
|
398
|
+
&__element {
|
|
399
|
+
width: var(--cell-dimensions);
|
|
400
|
+
line-height: 100px;
|
|
401
|
+
overflow: hidden;
|
|
402
|
+
text-overflow: ellipsis;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
.y-axis {
|
|
406
|
+
margin-right: 10px;
|
|
407
|
+
display: flex;
|
|
408
|
+
flex-direction: column;
|
|
409
|
+
justify-content: space-between;
|
|
410
|
+
&__element {
|
|
411
|
+
text-align: center;
|
|
412
|
+
line-height: var(--cell-dimensions);
|
|
413
|
+
overflow: hidden;
|
|
414
|
+
text-overflow: ellipsis;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
.y-axis-outer {
|
|
418
|
+
overflow: hidden;
|
|
419
|
+
width: 200px;
|
|
420
|
+
}
|
|
421
|
+
.y-axis,
|
|
422
|
+
.x-axis {
|
|
423
|
+
color: var(--dl-color-darker);
|
|
424
|
+
font-size: 0.7em;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.matrix-wrapper {
|
|
428
|
+
display: flex;
|
|
429
|
+
overflow-y: scroll;
|
|
430
|
+
overflow-x: hidden;
|
|
431
|
+
}
|
|
432
|
+
.matrix-wrapper::-webkit-scrollbar {
|
|
433
|
+
width: 14px;
|
|
434
|
+
}
|
|
435
|
+
.matrix-wrapper::-webkit-scrollbar-thumb {
|
|
436
|
+
border: 4px solid rgba(0, 0, 0, 0);
|
|
437
|
+
background-clip: padding-box;
|
|
438
|
+
border-radius: 9999px;
|
|
439
|
+
background-color: var(--dl-color-separator);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.matrix {
|
|
443
|
+
display: grid;
|
|
444
|
+
grid-template-rows: repeat(var(--matrix-rows), 1fr);
|
|
445
|
+
grid-template-columns: repeat(var(--matrix-rows), 1fr);
|
|
446
|
+
|
|
447
|
+
&__cell {
|
|
448
|
+
font-size: 80%;
|
|
449
|
+
cursor: pointer;
|
|
450
|
+
border: 1px solid var(--dl-color-separator);
|
|
451
|
+
box-sizing: border-box;
|
|
452
|
+
width: var(--cell-dimensions);
|
|
453
|
+
height: var(--cell-dimensions);
|
|
454
|
+
display: flex;
|
|
455
|
+
align-items: center;
|
|
456
|
+
justify-content: center;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.color-spectrum {
|
|
461
|
+
color: var(--dl-color-darker);
|
|
462
|
+
display: flex;
|
|
463
|
+
margin: 0px 15px;
|
|
464
|
+
&__gradient {
|
|
465
|
+
width: 40%;
|
|
466
|
+
background-image: linear-gradient(
|
|
467
|
+
var(--general-color),
|
|
468
|
+
var(--dl-color-text-buttons)
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
&__gradation {
|
|
472
|
+
width: 60%;
|
|
473
|
+
font-size: 0.8em;
|
|
474
|
+
display: flex;
|
|
475
|
+
flex-direction: column;
|
|
476
|
+
justify-content: space-between;
|
|
477
|
+
&--element {
|
|
478
|
+
width: 100%;
|
|
479
|
+
display: flex;
|
|
480
|
+
&-line {
|
|
481
|
+
color: var(--dl-color-separator);
|
|
482
|
+
margin-right: 5px;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
.tooltip {
|
|
489
|
+
position: absolute;
|
|
490
|
+
border: 1px solid var(--dl-color-separator);
|
|
491
|
+
padding: 8px;
|
|
492
|
+
font-size: 0.8em;
|
|
493
|
+
display: flex;
|
|
494
|
+
flex-direction: column;
|
|
495
|
+
background-color: var(--dl-color-shadow);
|
|
496
|
+
border-radius: 3px;
|
|
497
|
+
animation: fadeIn 0.4s;
|
|
498
|
+
|
|
499
|
+
&__color {
|
|
500
|
+
display: inline-block;
|
|
501
|
+
width: 12px;
|
|
502
|
+
height: 12px;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
@keyframes fadeIn {
|
|
507
|
+
0% {
|
|
508
|
+
opacity: 0;
|
|
509
|
+
}
|
|
510
|
+
100% {
|
|
511
|
+
opacity: 1;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.invalid {
|
|
516
|
+
display: flex;
|
|
517
|
+
justify-content: center;
|
|
518
|
+
align-items: center;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
.legend-avatar {
|
|
522
|
+
border-radius: 50%;
|
|
523
|
+
width: 30px;
|
|
524
|
+
height: 30px;
|
|
525
|
+
}
|
|
526
|
+
</style>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DlConfusionMatrixCell, DlConfusionMatrixLabel } from '../../types'
|
|
2
|
+
|
|
3
|
+
export function getCellWidth() {
|
|
4
|
+
return document.querySelector('.matrix__cell').getBoundingClientRect().width
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function setZoom(zoom: number, el: HTMLElement) {
|
|
8
|
+
const transformOrigin = [0, 0]
|
|
9
|
+
const p = ['webkit', 'moz', 'ms', 'o']
|
|
10
|
+
const s = 'scale(' + zoom + ')'
|
|
11
|
+
const oString =
|
|
12
|
+
transformOrigin[0] * 100 + '% ' + transformOrigin[1] * 100 + '%'
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < p.length; i++) {
|
|
15
|
+
el.style[(p[i] + 'Transform') as any] = s
|
|
16
|
+
el.style[(p[i] + 'TransformOrigin') as any] = oString
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
el.style['transform'] = s
|
|
20
|
+
el.style['transformOrigin'] = oString
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function validateMatrix(
|
|
24
|
+
matrix: number[][] | DlConfusionMatrixCell[][],
|
|
25
|
+
labels: string[] | DlConfusionMatrixLabel[]
|
|
26
|
+
) {
|
|
27
|
+
let validation = true
|
|
28
|
+
if (matrix.length !== labels.length) return false
|
|
29
|
+
for (let i = 0; i < matrix.length; i++) {
|
|
30
|
+
if (matrix[i].length !== matrix.length) validation = false
|
|
31
|
+
}
|
|
32
|
+
return validation
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function normalizeMatrix(flatMatrix: DlConfusionMatrixCell[]) {
|
|
36
|
+
const values = flatMatrix.map((cell) => cell.value)
|
|
37
|
+
const largest = Math.max(...values)
|
|
38
|
+
flatMatrix.forEach((cell) => {
|
|
39
|
+
cell.unnormalizedValue = cell.value
|
|
40
|
+
cell.value = Number((cell.value / largest).toFixed(1))
|
|
41
|
+
})
|
|
42
|
+
return flatMatrix
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getGradationValues(
|
|
46
|
+
matrix: number[][] | DlConfusionMatrixCell[][],
|
|
47
|
+
step = 5
|
|
48
|
+
) {
|
|
49
|
+
let max = Number.MIN_VALUE
|
|
50
|
+
let min = Number.MAX_VALUE
|
|
51
|
+
matrix.forEach((row) => {
|
|
52
|
+
row.forEach((cell) => {
|
|
53
|
+
const cellValue = typeof cell === 'object' ? cell.value : cell
|
|
54
|
+
if (cellValue > max) max = cellValue
|
|
55
|
+
if (cellValue < min) min = cellValue
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
const range = (max - min) / step
|
|
59
|
+
const gradationValues = []
|
|
60
|
+
let amount = 0
|
|
61
|
+
for (let i = 0; i < step; i++) {
|
|
62
|
+
gradationValues.push(Number((amount + range).toFixed(1)))
|
|
63
|
+
amount += range
|
|
64
|
+
}
|
|
65
|
+
return gradationValues.reverse()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function flattenConfusionMatrix(
|
|
69
|
+
matrix: number[][] | DlConfusionMatrixCell[][],
|
|
70
|
+
labelStrings: string[] | DlConfusionMatrixLabel[]
|
|
71
|
+
) {
|
|
72
|
+
return normalizeMatrix(
|
|
73
|
+
matrix.flatMap(
|
|
74
|
+
(row: number[] | DlConfusionMatrixCell[], rowIndex: number) => {
|
|
75
|
+
return row.map(
|
|
76
|
+
(
|
|
77
|
+
cell: number | DlConfusionMatrixCell,
|
|
78
|
+
cellIndex: number
|
|
79
|
+
) => {
|
|
80
|
+
const isObject = typeof cell === 'object'
|
|
81
|
+
const value = isObject ? cell.value : cell
|
|
82
|
+
return {
|
|
83
|
+
value,
|
|
84
|
+
unnormalizedValue: value,
|
|
85
|
+
xLabel: labelStrings[rowIndex],
|
|
86
|
+
yLabel: labelStrings[cellIndex],
|
|
87
|
+
x: rowIndex,
|
|
88
|
+
y: cellIndex,
|
|
89
|
+
link: isObject ? cell.link : ''
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -214,8 +214,8 @@ export default defineComponent({
|
|
|
214
214
|
? {
|
|
215
215
|
'justify-content': 'end',
|
|
216
216
|
width: getPixelsFromPercents(
|
|
217
|
-
|
|
218
|
-
sizePercents,
|
|
217
|
+
doughnutChartWidgetHeight.value,
|
|
218
|
+
sizePercents / 1.8,
|
|
219
219
|
'px'
|
|
220
220
|
),
|
|
221
221
|
height: getPixelsFromPercents(
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
:style="cssVars"
|
|
4
|
+
:class="chartWrapperClasses"
|
|
5
|
+
>
|
|
3
6
|
<DlLine
|
|
4
7
|
:id="id"
|
|
5
8
|
ref="lineChart"
|
|
@@ -153,9 +156,10 @@ export default defineComponent({
|
|
|
153
156
|
size: { height: number; width: number }
|
|
154
157
|
) => {
|
|
155
158
|
if (chart?.scales?.x?.width) {
|
|
156
|
-
chartWidth.value = `${
|
|
157
|
-
chart.scales.x.width as unknown as string
|
|
158
|
-
|
|
159
|
+
chartWidth.value = `${
|
|
160
|
+
parseInt(chart.scales.x.width as unknown as string) -
|
|
161
|
+
parseInt(brushProperties.value.thumbSize) / 4
|
|
162
|
+
}px`
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
|
|
@@ -268,6 +272,13 @@ export default defineComponent({
|
|
|
268
272
|
return merge(defaultLineChartProps.legendProps, props.legendProps)
|
|
269
273
|
})
|
|
270
274
|
|
|
275
|
+
const cssVars = computed(() => {
|
|
276
|
+
return {
|
|
277
|
+
'--dl-brush-thumb-size':
|
|
278
|
+
parseInt(brushProperties.value.thumbSize) / 4 + 'px'
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
|
|
271
282
|
const replaceDataColors = (data: ChartData) =>
|
|
272
283
|
updateKeys(
|
|
273
284
|
data,
|
|
@@ -450,7 +461,10 @@ export default defineComponent({
|
|
|
450
461
|
() => chart.value?.scales?.x?.width,
|
|
451
462
|
(val: string) => {
|
|
452
463
|
if (val) {
|
|
453
|
-
chartWidth.value = `${
|
|
464
|
+
chartWidth.value = `${
|
|
465
|
+
parseInt(val as unknown as string) -
|
|
466
|
+
parseInt(brushProperties.value.thumbSize) / 4
|
|
467
|
+
}px`
|
|
454
468
|
}
|
|
455
469
|
},
|
|
456
470
|
{ deep: true }
|
|
@@ -619,7 +633,8 @@ export default defineComponent({
|
|
|
619
633
|
onLeaveLegend,
|
|
620
634
|
onChartLeave,
|
|
621
635
|
chart,
|
|
622
|
-
labelStyles
|
|
636
|
+
labelStyles,
|
|
637
|
+
cssVars
|
|
623
638
|
}
|
|
624
639
|
}
|
|
625
640
|
})
|
|
@@ -644,5 +659,6 @@ export default defineComponent({
|
|
|
644
659
|
.dl-brush,
|
|
645
660
|
.dl-legend {
|
|
646
661
|
align-self: flex-end;
|
|
662
|
+
margin-right: var(--dl-brush-thumb-size);
|
|
647
663
|
}
|
|
648
664
|
</style>
|