Display error message when Scatterplot Visualization errors out (#11284)

This commit is contained in:
marthasharkey 2024-10-18 12:30:14 +01:00 committed by GitHub
parent f470e9c63c
commit 27a535f6d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 12 deletions

View File

@ -56,8 +56,9 @@ interface Data {
data: Point[]
isTimeSeries: boolean
x_value_type: string
is_multi_series?: boolean
is_multi_series: boolean
get_row_method: string
error_message: string | null
}
interface Focus {
@ -186,16 +187,22 @@ const data = computed<Data>(() => {
if (Array.isArray(rawData)) {
rawData = {}
}
const axis: AxesConfiguration = rawData.axis ?? {
x: { label: '', scale: isTimeSeries ? ScaleType.Time : ScaleType.Linear },
y: { label: '', scale: ScaleType.Linear },
}
const axis: AxesConfiguration =
rawData.axis && 'x' in rawData.axis && 'y' in rawData.axis ?
rawData.axis
: {
x: { label: '', scale: isTimeSeries ? ScaleType.Time : ScaleType.Linear },
y: { label: '', scale: ScaleType.Linear },
}
const points = rawData.points ?? { labels: 'visible' }
const focus: Focus | undefined = rawData.focus
// eslint-disable-next-line camelcase
const is_multi_series: boolean = !!rawData.is_multi_series
// eslint-disable-next-line camelcase
const get_row_method: string = rawData.get_row_method || 'get_row'
// eslint-disable-next-line camelcase
const error_message: string | null = rawData.error_message || null
return {
axis,
points,
@ -207,6 +214,8 @@ const data = computed<Data>(() => {
x_value_type: rawData.x_value_type || '',
// eslint-disable-next-line camelcase
get_row_method,
// eslint-disable-next-line camelcase
error_message,
isTimeSeries,
}
})
@ -578,6 +587,9 @@ const makeFilterPattern = (
Ast.tryNumberToEnso(max, module)!,
])
}
const errorMessage = computed(() => data.value.error_message)
function getAstPatternFilterAndSort(
series: string[],
xColName: string,
@ -861,7 +873,10 @@ config.setToolbar([
</script>
<template>
<div ref="containerNode" class="ScatterplotVisualization">
<div v-if="errorMessage" class="WarningsScatterplotVisualization">
{{ errorMessage }}
</div>
<div v-else ref="containerNode" class="ScatterplotVisualization">
<svg :width="width" :height="height">
<g ref="legendNode"></g>
<g :transform="`translate(${margin.left}, ${margin.top})`">
@ -904,6 +919,10 @@ config.setToolbar([
flex-direction: column;
}
.WarningsScatterplotVisualization {
padding: 18px;
}
.ScatterplotVisualization .selection {
rx: 4px;
stroke: transparent;

View File

@ -237,13 +237,14 @@ json_from_table table bounds limit =
fields_for_axes = get_axes_field number_of_numeric_cols
axes = table.axes fields_for_axes
is_multi_series = number_of_numeric_cols > 0
JS_Object.from_pairs [[data_field, data], [axis_field, axes], ["is_multi_series", is_multi_series], ["get_row_method", "get_row"], ["x_value_type", x_value_type.to_name]] . to_json
error_message = if axes.length < 2 then "Two numeric columns required for Scatterplot" else Nothing
JS_Object.from_pairs [[data_field, data], [axis_field, axes], ["is_multi_series", is_multi_series], ["get_row_method", "get_row"], ["x_value_type", x_value_type.to_name], ["error_message", error_message]] . to_json
## PRIVATE
json_from_vector : Vector Any -> Vector Integer | Nothing -> Integer | Nothing -> Text
json_from_vector vec bounds limit =
data = vec.point_data |> bound_data bounds |> limit_data limit
JS_Object.from_pairs [[data_field, data], [axis_field, Nothing], ["is_multi_series", False], ["get_row_method", "at"], ["x_value_type", Value_Type.Integer.to_name]] . to_json
JS_Object.from_pairs [[data_field, data], [axis_field, Nothing], ["is_multi_series", False], ["get_row_method", "at"], ["x_value_type", Value_Type.Integer.to_name], ["error_message", Nothing]] . to_json
## PRIVATE

View File

@ -12,9 +12,9 @@ import project
add_specs suite_builder =
expect_text text axis_expected_text data_expected_text row_method is_multi =
json = Json.parse text
json.field_names.should_equal ['data', 'axis', 'is_multi_series', 'get_row_method', 'x_value_type']
json.field_names.should_equal ['data', 'axis', 'is_multi_series', 'get_row_method', 'x_value_type', 'error_message']
expect_text = '{"axis": ' + axis_expected_text + ', "data": ' + data_expected_text + ', "is_multi_series": ' + is_multi + ', "get_row_method": ' + row_method + ', "x_value_type": "Integer"' + '}'
expect_text = '{"axis": ' + axis_expected_text + ', "data": ' + data_expected_text + ', "is_multi_series": ' + is_multi + ', "get_row_method": ' + row_method + ', "x_value_type": "Integer"' + ', "error_message":null}'
expected_result = Json.parse expect_text
json.should_equal expected_result
@ -88,7 +88,7 @@ add_specs suite_builder =
vector = [0,10,20,30]
text = Scatter_Plot.process_to_json_text vector limit=2
json = Json.parse text
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type']
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type', 'error_message']
data = json.get 'data'
data.should_be_a Vector
data.length . should_equal 2
@ -97,7 +97,7 @@ add_specs suite_builder =
vector = (-15).up_to 15 . map (x -> x * x)
text = Scatter_Plot.process_to_json_text vector limit=10
json = Json.parse text
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type']
json.field_names.should_equal ['data','axis', 'is_multi_series', 'get_row_method', 'x_value_type', 'error_message']
data = json.get 'data'
data.should_be_a Vector
data.length . should_equal 10