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

Introduce EDD_Graph class #1424

Closed
pippinsplugins opened this issue Jul 26, 2013 · 15 comments
Closed

Introduce EDD_Graph class #1424

pippinsplugins opened this issue Jul 26, 2013 · 15 comments

Comments

@pippinsplugins
Copy link
Contributor

We need to write a new class for handling the creation and display of graphs.

The class should allow us to pass an array of data and set arguments such as tick size then generate the graph.

This will be extremely useful for add-ons, such as Commissions, that want to generate their own graphs.

Related: #1376

@pippinsplugins
Copy link
Contributor Author

Punting to 1.9. I'm really not yet sure how to go about this one.

@pippinsplugins
Copy link
Contributor Author

Might look at http://www.chartjs.org/

@chriscct7
Copy link
Member

FYI "I'm currently working on a big refactor of the library into a more object oriented structure." on the Github's readme for that project. Looks like he's almost done with it, so if we want to use this we should keep in mind we should prob wait for the finish of the refactor.

@pippinsplugins
Copy link
Contributor Author

I think to start I will use Flot, just so it stays the same as what we have, then when Charts.js is finished with the rewrite, we can migrate.

@pippinsplugins
Copy link
Contributor Author

Flot API for reference https://github.com/flot/flot/blob/master/API.md

@pippinsplugins
Copy link
Contributor Author

Todo:

  • Option for ticksize
  • Option for time format
  • Option to Set number of Y axis

@evertiro
Copy link

evertiro commented Dec 9, 2013

if( class_exists( 'EDD_Graph' ) ) {
    $this = 'win';
}

@amdrew
Copy link
Contributor

amdrew commented Dec 9, 2013

👍 can't wait

@pippinsplugins
Copy link
Contributor Author

Further todo:

  • Add graph type options (bar, line, pie, etc)

@pippinsplugins
Copy link
Contributor Author

This is ready for testing!

Quick and dirty example:

// Single line example
$data = array(
    'Line Label' => array(
        array( 1, 5 ),
        array( 3, 8 ),
        array( 10, 2 )
    )
);

$graph = new EDD_Graph( $data );
$graph->display();

// Multi line example
$data = array(

    'Line Label' => array(
        array( 1, 5 ),
        array( 3, 8 ),
        array( 10, 2 )
    ),

    'Second Line Label' => array(
        array( 1, 7 ),
        array( 4, 5 ),
        array( 12, 8 )
    )
);

$graph = new EDD_Graph( $data );
$graph->display();

// Example with options set to other than default:
$data = array(

    'Line Label' => array(
        array( 1, 5 ),
        array( 3, 8 ),
        array( 10, 2 )
    ),

    'Second Line Label' => array(
        array( 1, 7 ),
        array( 4, 5 ),
        array( 12, 8 )
    )
);

$graph = new EDD_Graph( $data );
$graph->set( 'bgcolor' => '#000' );
$graph->set( 'color' => '#fff' );
$graph->display();

@pippinsplugins
Copy link
Contributor Author

Note on the data format.

'Line Label' => array(
    array( 1, 5 ),
    array( 3, 8 ),
    array( 10, 2 )
)

Each inner array represents a data point on the graph. Each inner array should be structured as array( 'value on x axis', 'value on y axis' ).

@amdrew
Copy link
Contributor

amdrew commented Dec 10, 2013

@pippinsplugins I believe your last example above is incorrect. Should be:

$graph->set( 'bgcolor', '#000' );
$graph->set( 'color', '#fff' );

Throws an unexpected double arrow error otherwise

@pippinsplugins
Copy link
Contributor Author

Oops! You're right, thanks!

pippinsplugins added a commit that referenced this issue Dec 11, 2013
@pippinsplugins
Copy link
Contributor Author

With scripts loaded in EDD_Graph you can now output a graph anywhere you want, including the frontend. Note, if you want to display a graph on the front end, you have to include includes/admin/reporting/class-edd-graph.php first.

pippinsplugins added a commit that referenced this issue Dec 11, 2013
@pippinsplugins
Copy link
Contributor Author

Merged into release/1.9

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

4 participants