-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Selection Menu to allow text selection #11352
base: develop
Are you sure you want to change the base?
Changes from 3 commits
c78e79d
e4de551
64f68a0
9bc004c
81399ae
eee5725
95b51c2
b789707
b20f534
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,7 +297,6 @@ const yLabelLeft = computed( | |
getTextWidthBySizeAndFamily(data.value.axis.y.label, LABEL_FONT_STYLE) / 2, | ||
) | ||
const yLabelTop = computed(() => -margin.value.left + 15) | ||
const showYLabelText = computed(() => !data.value.is_multi_series) | ||
const xTickFormat = computed(() => { | ||
switch (data.value.x_value_type) { | ||
case 'Time': | ||
|
@@ -308,6 +307,22 @@ const xTickFormat = computed(() => { | |
return '%d/%m/%Y %H:%M:%S' | ||
} | ||
}) | ||
const seriesLabels = computed(() => | ||
Object.keys(data.value.axis) | ||
.filter((s) => s != 'x') | ||
.map((s) => { | ||
return data.value.axis[s as keyof AxesConfiguration].label | ||
}), | ||
Comment on lines
+320
to
+324
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are using both the keys and the values of |
||
) | ||
|
||
const yLabelText = computed(() => { | ||
if (!data.value.is_multi_series) { | ||
return data.value.axis.y.label | ||
} | ||
if (yAxisSelected.value) { | ||
return yAxisSelected.value === 'none' ? null : yAxisSelected.value | ||
} else return null | ||
}) | ||
const isUsingIndexForX = computed(() => data.value.axis.x.label === 'index') | ||
|
||
watchEffect(() => { | ||
|
@@ -722,26 +737,21 @@ watchPostEffect(() => { | |
|
||
watchPostEffect(() => { | ||
if (data.value.is_multi_series) { | ||
const seriesLabels = Object.keys(data.value.axis) | ||
.filter((s) => s != 'x') | ||
.map((s) => { | ||
return data.value.axis[s as keyof AxesConfiguration].label | ||
}) | ||
const formatLabel = (string: string) => | ||
string.length > 10 ? `${string.substr(0, 10)}...` : string | ||
|
||
const color = d3 | ||
.scaleOrdinal<string>() | ||
.domain(seriesLabels) | ||
.domain(seriesLabels.value) | ||
.range(d3.schemeCategory10) | ||
.domain(seriesLabels) | ||
.domain(seriesLabels.value) | ||
|
||
d3Legend.value.selectAll('circle').remove() | ||
d3Legend.value.selectAll('text').remove() | ||
|
||
d3Legend.value | ||
.selectAll('dots') | ||
.data(seriesLabels) | ||
.data(seriesLabels.value) | ||
.enter() | ||
.append('circle') | ||
.attr('cx', function (d, i) { | ||
|
@@ -753,7 +763,7 @@ watchPostEffect(() => { | |
|
||
d3Legend.value | ||
.selectAll('labels') | ||
.data(seriesLabels) | ||
.data(seriesLabels.value) | ||
.enter() | ||
.append('text') | ||
.attr('x', function (d, i) { | ||
|
@@ -834,6 +844,17 @@ function zoomToSelected(override?: boolean) { | |
|
||
useEvent(document, 'keydown', bindings.handler({ zoomToSelected: () => zoomToSelected() })) | ||
|
||
const yAxisSelected = ref('none') | ||
const makeSeriesLabelOptions = () => { | ||
const seriesOptions: { [key: string]: { label: string } } = {} | ||
seriesLabels.value.forEach((label, index) => { | ||
seriesOptions[label] = { | ||
label: label, | ||
} | ||
}) | ||
return seriesOptions | ||
} | ||
|
||
config.setToolbar([ | ||
{ | ||
icon: 'select', | ||
|
@@ -857,6 +878,18 @@ config.setToolbar([ | |
disabled: () => !createNewFilterNodeEnabled.value, | ||
onClick: createNewFilterNode, | ||
}, | ||
{ | ||
selected: yAxisSelected, | ||
title: 'Choose Y Axis Label', | ||
isTextDropdown: true, | ||
heading: 'Y Axis Label: ', | ||
options: { | ||
none: { | ||
label: 'No Label', | ||
}, | ||
...makeSeriesLabelOptions(), | ||
}, | ||
}, | ||
]) | ||
</script> | ||
|
||
|
@@ -881,12 +914,11 @@ config.setToolbar([ | |
v-text="data.axis.x.label" | ||
></text> | ||
<text | ||
v-if="showYLabelText" | ||
class="label label-y" | ||
text-anchor="end" | ||
:x="yLabelLeft" | ||
:y="yLabelTop" | ||
v-text="data.axis.y.label" | ||
v-text="yLabelText" | ||
></text> | ||
<g ref="pointsNode" clip-path="url(#clip)"></g> | ||
<g ref="zoomNode" class="zoom" :width="boxWidth" :height="boxHeight" fill="none"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import { ToValue } from '@/util/reactivity' | |
import { Ref } from 'vue' | ||
|
||
export interface Button { | ||
icon: Icon | URLString | ||
iconStyle?: Record<string, string> | ||
title?: string | ||
dataTestid?: string | ||
|
@@ -13,21 +12,26 @@ export interface Button { | |
export interface ActionButton extends Button { | ||
onClick: () => void | ||
disabled?: ToValue<boolean> | ||
icon: Icon | URLString | ||
} | ||
|
||
export interface ToggleButton extends Button { | ||
toggle: Ref<boolean> | ||
disabled?: ToValue<boolean> | ||
icon: Icon | URLString | ||
} | ||
|
||
export interface SelectionMenuOption extends Button { | ||
label?: string | ||
icon?: Icon | URLString | ||
} | ||
|
||
export interface SelectionMenu { | ||
selected: Ref<string> | ||
title?: string | ||
options: Record<string, SelectionMenuOption> | ||
isTextDropdown?: boolean | ||
heading?: string | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the export interface TextSelectionMenu {
type: 'textSelectionMenu'
selected: Ref<string>
title?: string
options: Record<string, TextSelectionMenuOption>
heading?: string
} The reason for the Eventually, every type will have a So far, every type has had distinctive enough fields that we haven't needed to make any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok! Thanks, I wasn't sure if it was best to adapt the current dropdown or make a new one so I'll separate it now! |
||
|
||
export type ToolbarItem = ActionButton | ToggleButton | SelectionMenu | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not-present (
undefined
) ornull
would have the same meaning--let's avoid a distinction without a difference.