diff --git a/src/plugins/vis_augmenter/public/test_constants.ts b/src/plugins/vis_augmenter/public/test_constants.ts index 435116078487..fdd3fa4373af 100644 --- a/src/plugins/vis_augmenter/public/test_constants.ts +++ b/src/plugins/vis_augmenter/public/test_constants.ts @@ -39,17 +39,17 @@ const TEST_VALUES_SINGLE_ROW_SINGLE_VIS_LAYER = [ ]; const TEST_VALUES_ONLY_VIS_LAYERS = [ - { [TEST_X_AXIS_ID]: 0 }, + { [TEST_X_AXIS_ID]: 0, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 10 }, - { [TEST_X_AXIS_ID]: 15 }, - { [TEST_X_AXIS_ID]: 20 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, + { [TEST_X_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45 }, - { [TEST_X_AXIS_ID]: 50 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_PLUGIN_EVENT_TYPE]: 0 }, ]; const TEST_VALUES_NO_VIS_LAYERS = [ @@ -66,6 +66,20 @@ const TEST_VALUES_NO_VIS_LAYERS = [ { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5 }, ]; +const TEST_VALUES_SINGLE_VIS_LAYER_EMPTY = [ + { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, +]; + const TEST_VALUES_NO_VIS_LAYERS_DIRTY = [ { [TEST_X_AXIS_ID_DIRTY]: 0, [TEST_VALUE_AXIS_ID_DIRTY]: 5 }, { [TEST_X_AXIS_ID_DIRTY]: 5, [TEST_VALUE_AXIS_ID_DIRTY]: 10 }, @@ -81,50 +95,80 @@ const TEST_VALUES_NO_VIS_LAYERS_DIRTY = [ ]; const TEST_VALUES_SINGLE_VIS_LAYER = [ - { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5 }, + { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, - { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, ]; const TEST_VALUES_SINGLE_VIS_LAYER_ON_BOUNDS = [ { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10 }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, - { [TEST_X_AXIS_ID]: 35 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, + { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 1 }, ]; const TEST_VALUES_MULTIPLE_VIS_LAYERS = [ - { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5 }, + { + [TEST_X_AXIS_ID]: 0, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 2, [TEST_PLUGIN_EVENT_TYPE_2]: 1, }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE_2]: 1 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, - { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, - { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE_2]: 2 }, + { + [TEST_X_AXIS_ID]: 10, + [TEST_VALUE_AXIS_ID]: 6, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 15, + [TEST_VALUE_AXIS_ID]: 4, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 1, + }, + { + [TEST_X_AXIS_ID]: 20, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { + [TEST_X_AXIS_ID]: 45, + [TEST_VALUE_AXIS_ID]: 3, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 50, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 2, + }, ]; export const TEST_COLUMNS_NO_VIS_LAYERS = [ @@ -204,6 +248,7 @@ export const TEST_DATATABLE_NO_VIS_LAYERS_DIRTY = { export const TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY = { ...TEST_DATATABLE_NO_VIS_LAYERS, columns: TEST_COLUMNS_SINGLE_VIS_LAYER, + rows: TEST_VALUES_SINGLE_VIS_LAYER_EMPTY, } as OpenSearchDashboardsDatatable; export const TEST_DATATABLE_SINGLE_VIS_LAYER = { @@ -390,20 +435,6 @@ export const TEST_VIS_LAYERS_SINGLE_INVALID_BOUNDS = [ }, ]; -export const TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS = [ - { - originPlugin: TEST_PLUGIN, - type: VisLayerTypes.PointInTimeEvents, - pluginResource: { - type: TEST_PLUGIN_RESOURCE_TYPE, - id: TEST_PLUGIN_RESOURCE_ID, - name: TEST_PLUGIN_RESOURCE_NAME, - urlPath: TEST_PLUGIN_RESOURCE_PATH, - }, - pluginEventType: TEST_PLUGIN_EVENT_TYPE, - }, -]; - export const TEST_VIS_LAYERS_SINGLE_ON_BOUNDS = [ { originPlugin: TEST_PLUGIN, diff --git a/src/plugins/vis_augmenter/public/vega/helpers.test.ts b/src/plugins/vis_augmenter/public/vega/helpers.test.ts index f0df25a81546..ce5c68075afe 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.test.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.test.ts @@ -38,7 +38,6 @@ import { TEST_SPEC_SINGLE_VIS_LAYER, TEST_VIS_LAYERS_MULTIPLE, TEST_VIS_LAYERS_SINGLE, - TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS, TEST_VIS_LAYERS_SINGLE_INVALID_BOUNDS, TEST_VIS_LAYERS_SINGLE_ON_BOUNDS, } from '../test_constants'; @@ -409,19 +408,6 @@ describe('helpers', function () { ) ).toStrictEqual(TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY); }); - // below case should not happen since only VisLayers with a populated - // set of events should be passed from the plugins. but, if it does - // happen, we can handle it more gracefully instead of throwing an error - it('vis layer with empty events adds nothing to datatable', function () { - expect( - addPointInTimeEventsLayersToTable( - TEST_DATATABLE_NO_VIS_LAYERS, - TEST_DIMENSIONS, - // @ts-ignore - TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS - ) - ).toStrictEqual(TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY); - }); it('vis layer with events on edge of bounds are added', function () { expect( addPointInTimeEventsLayersToTable( diff --git a/src/plugins/vis_augmenter/public/vega/helpers.ts b/src/plugins/vis_augmenter/public/vega/helpers.ts index fa2073e3bb63..846a40adf33e 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.ts @@ -228,6 +228,17 @@ export const addPointInTimeEventsLayersToTable = ( if (isEmpty(visLayer.events)) return; const visLayerColumnId = `${visLayer.pluginEventType}`; + // Add placeholder values of 0 for every event value. This is so the tooltip + // can render correctly without showing the 'undefined' string + let row = 0; + while (row < augmentedTable.rows.length) { + augmentedTable.rows[row] = { + ...augmentedTable.rows[row], + [visLayerColumnId]: get(augmentedTable.rows[row], visLayerColumnId, 0) as number, + }; + row++; + } + // if only one row / one datapoint, put all events into this bucket if (augmentedTable.rows.length === 1) { augmentedTable.rows[0] = {