From bfe16a7a74081b9a81fcdfb41e4ef4eee0a3fa99 Mon Sep 17 00:00:00 2001 From: Rafal Slawik Date: Sun, 21 Jul 2024 19:20:05 +0000 Subject: [PATCH] Pass cols and rows to arrayToDataTable It allows dates to parsed and columns types to be omitted. --- demo/index.html | 18 +++++++++++++++++- google-chart.ts | 3 +-- test/basic-tests.ts | 40 ++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/demo/index.html b/demo/index.html index baf6758..ed283a4 100644 --- a/demo/index.html +++ b/demo/index.html @@ -227,7 +227,7 @@

Chart gallery

@@ -441,6 +441,22 @@

Chart gallery

}); +

Here's the same timeline chart that parses dates from rows:

+ + + +

Here's a wordtree:

', function() { }); suite('Data Source Types', function() { - test('[rows] and [cols]', function (done) { - chart.cols = [ - {'label': 'Data', 'type': 'string'}, - {'label': 'Value', 'type': 'number'} - ]; + function waitForRender(done: () => void) { + chart.addEventListener('google-chart-ready', () => void done()); + } + test('[rows] and [cols] without type', function (done) { + chart.cols = ['Data', 'Value']; chart.rows = [ ['Something', 1] ]; - chart.addEventListener('google-chart-ready', function() { - done(); - }); + waitForRender(done); }); - test('[rows] and [cols] with date string repr is broken', function(done) { - chart.cols = [ { 'type': 'date' } ]; - chart.rows = [ ['Date(1789, 3, 30)'] ]; - waitCheckAndDone(function() { - const chartDiv = chart.shadowRoot!.getElementById('chartdiv')!; - return chartDiv.innerHTML == - 'Error: Type mismatch. Value Date(1789, 3, 30) ' + - 'does not match type date in column index 0'; - }, done); + test('[rows] and [cols] with type', function(done) { + chart.type = 'timeline'; + chart.cols = [ + 'Data', + {type: 'date', label: 'Start'}, + {type: 'date', label: 'End'} + ]; + chart.rows = [[ + 'Something', + 'Date(2024, 6, 1)', + 'Date(2024, 7, 1)' + ]]; + waitForRender(done); }); var setDataAndWaitForRender = function(data: DataTableLike|string, done: () => void) { chart.data = data; - chart.addEventListener('google-chart-ready', function() { - done(); - }); + waitForRender(done); }; test('[data] is 2D Array', function(done) { setDataAndWaitForRender([ ['Data', 'Value'], ['Something', 1] ], done);