Skip to content
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

request: give support to associative arrays in addRow function #286

Open
fcolecumberri opened this issue Nov 30, 2018 · 1 comment
Open
Assignees

Comments

@fcolecumberri
Copy link

What Version?

Run composer show khill/lavacharts if you don't know

name : khill/lavacharts
descrip. : PHP wrapper library for the Google Chart API
keywords : charts, google, graphs
versions : * 3.0.8
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source : [git] https://github.com/kevinkhill/lavacharts.git ab4aa8d
dist : [zip] https://api.github.com/repos/kevinkhill/lavacharts/zipball/ab4aa8d8bc3d68d0e86b3d59383a0aaee384c6f5 ab4aa8d
names : khill/lavacharts

Issue

Please describe the issue.

It would be nice if the code I present here would work:

$my_table = \Lava::DataTable();
$my_table->addDateColumn("date");
$my_table->addNumberColumn("number");
$my_table->addRow([
    "date" => "01-01-2000",
    "number" => "1",
]);

It would be nice because when you load data dynamically from the data base, its usually an associative array or an object castable to a associative arrays.
but in the file lavacharts/src/DataTables/Rows/RowFactory.php line 84

if ((bool) preg_match('/date|datetime|timeofday/', $columnTypes[$index]) === true)

$columnTypes[$index] check directly to the $index asuming that the row will be a indexed array
I changed it to be like this:

$columnLabels = $this->datatable->getColumnLabels();
//...
if ((bool) preg_match('/date|datetime|timeofday/', isset($columnTypes[$index]) ? $columnTypes[$index] : array_search($index, $columnLabels)) === true) {

I tried to make a pull request, but I just realized that your master branch is quite diferent at this point so I think the change would be similar, I just dont know where to edit.

@kevinkhill
Copy link
Owner

Yes, master is quite different 😆 I really started ripping the guts apart for v4.

If you want to make pull requests, then do so to the 3.1 branch.

@kevinkhill kevinkhill self-assigned this Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants