From 77f7912e2c1eb80ed9560ead67af8fd89da87aba Mon Sep 17 00:00:00 2001 From: dmt0 Date: Wed, 27 Jun 2018 13:17:48 -0400 Subject: [PATCH] Add table columns if none specified --- src/EditorControls.js | 2 ++ src/shame.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/EditorControls.js b/src/EditorControls.js index 94d3f5d33..262caeea5 100644 --- a/src/EditorControls.js +++ b/src/EditorControls.js @@ -6,6 +6,7 @@ import { shamefullyClearAxisTypes, shamefullyAdjustAxisRef, shamefullyAdjustGeo, + shamefullyAddTableColumns, } from './shame'; import {EDITOR_ACTIONS} from './lib/constants'; import isNumeric from 'fast-isnumeric'; @@ -62,6 +63,7 @@ class EditorControls extends Component { shamefullyClearAxisTypes(graphDiv, payload); shamefullyAdjustAxisRef(graphDiv, payload); + shamefullyAddTableColumns(graphDiv, payload); for (let i = 0; i < payload.traceIndexes.length; i++) { for (const attr in payload.update) { diff --git a/src/shame.js b/src/shame.js index 6d2575159..a1d389df9 100644 --- a/src/shame.js +++ b/src/shame.js @@ -82,3 +82,21 @@ export const shamefullyAdjustGeo = ({layout: {geo = {}}}, {update}) => { update['geo.center'] = {}; } }; + +export const shamefullyAddTableColumns = (graphDiv, {traceIndexes, update}) => { + if ( + update['cells.values'] && + (!graphDiv.data[traceIndexes[0]].header || + !graphDiv.data[traceIndexes[0]].header.valuessrc) + ) { + update['header.values'] = update['cells.valuessrc']; + } else if (update['header.values'] === null) { + update['header.values'] = + graphDiv.data[traceIndexes[0]].cells.valuessrc || null; + } else if ( + update['cells.values'] === null && + !graphDiv.data[traceIndexes[0]].header.valuessrc + ) { + update['header.values'] = null; + } +};