Opened 14 months ago

Closed 12 months ago

Last modified 12 months ago

#3799 closed New feature (fixed)

Make ImageGraph BackgroundColor / TextColor customizable

Reported by: tsteur Owned by: JulienM
Priority: normal Milestone: 2.x - The Great Piwik 2.x Backlog
Component: Core Keywords:
Cc: Sensitive: no

Description

Make backgroundColor, textColor and axisColor of a graph customizable via URL parameters.

This is interesting for new mobile app.

Attachments (2)

piwikgraph.png (22.3 KB) - added by tsteur 13 months ago.
piwikGraph_1.png (6.9 KB) - added by tsteur 13 months ago.

Download all attachments as: .zip

Change History (25)

comment:1 Changed 14 months ago by matt (mattab)

  • Milestone set to 1.12 - Piwik 1.12
  • Owner set to JulienM

New mobile app with pretty graphs FTW

comment:2 Changed 13 months ago by matt (mattab)

  • Milestone changed from 1.12 - The Great 1.x Backlog to 2.x - Piwik 2.x

Changed 13 months ago by tsteur

comment:3 Changed 13 months ago by tsteur

Graph does not have to look like the attachment but would be great to be able to set backgroundColor, textColor and axisColor to those colors via URL parameter.

@JulienM do you think you'll find some time to implement this in the next 4-6 weeks? Otherwise I'll maybe have a look at it

comment:4 Changed 13 months ago by JulienM (JulienMoumne)

Yes I can have a look at it.

Could you give me examples of colors for each parameter?

Also, will you need to specify transparency for the background (and eventually for the other parameters) ?

comment:5 Changed 13 months ago by JulienM (JulienMoumne)

Also, should it be possible to set the legend font color differently from the axes values font color?

comment:6 Changed 13 months ago by JulienM (JulienMoumne)

I have committed in my repo three new ImageGraph API parameters $textColor, $backgroundColor and $gridColor : https://github.com/JulienMoumne/piwik/commit/cd811234e4b838f651ef0ef5d1218175e19d204d

If you can, do tell me if this is what you are looking for.

Last edited 13 months ago by JulienM (previous) (diff)

comment:7 Changed 13 months ago by tsteur

sure!

backgroundColor = #efefef
axisColor or gridColor = #dcdcdc
legendColor = #000000
labelColor = #000000
lineColor = #cb2026

I don't need to be able to change the different line colors of the evolution graph.

comment:8 Changed 13 months ago by tsteur

oh cool! Thx for working on that so fast. I will test it tomorrow.

comment:9 Changed 13 months ago by JulienM (JulienMoumne)

From what I see you may need more granularity than what I implemented. Do tell me after testing if this is the case.

comment:10 Changed 13 months ago by tsteur

Looks good so far! Aweseome! See attachment piwikGraph_1.png. The only missing thing I need in addition is to be able to change the color of a line / bar (which is currently blue by default). I need to set it to "#cb2026". I need to change it only for static graphs, not for evolution graphs where 5 or 6 different colors are used.

Changed 13 months ago by tsteur

comment:11 Changed 13 months ago by JulienM (JulienMoumne)

To change the color of the line and/or bars, try to use &colors=FF00FF on my branch commit.

comment:12 Changed 13 months ago by tsteur

Works perfect! You made my day! Thanks!

BTW: Not sure if it is related: When using this url to generate the graph:

http://apache.piwik/index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Referers&apiAction=getAll&period=day&date=2013-04-05,2013-04-07&filter_sort_column=nb_visits&column=nb_visits&columns=nb_visits&language=en&width=300&height=150&fontSize=9&showMetricTitle=0&aliasedGraph=1&legendAppendMetric=0&backgroundColor=efefef&gridColor=dcdcdc&colors=cb2026&showLegend=0

I'm getting this error which seems to only occur when graph is an evolution graph:

Warning: array_merge(): Argument #2 is not an array in /var/www/piwik/plugins/ImageGraph/StaticGraph.php on line 268 

Backtrace -->

#0 Piwik_ErrorHandler(...) called at [:]
#1 array_merge(...) called at [/var/www/piwik/plugins/ImageGraph/StaticGraph.php:268]
#2 Piwik_ImageGraph_StaticGraph->initpImage(...) called at [/var/www/piwik/plugins/ImageGraph/StaticGraph.php:279]
#3 Piwik_ImageGraph_StaticGraph->getTextWidthHeight(...) called at [/var/www/piwik/plugins/ImageGraph/StaticGraph/Exception.php:55]
#4 Piwik_ImageGraph_StaticGraph_Exception->renderGraph(...) called at [/var/www/piwik/plugins/ImageGraph/API.php:486]
#5 Piwik_ImageGraph_API->get(...) called at [:]
#6 call_user_func_array(...) called at [/var/www/piwik/core/API/Proxy.php:187]
#7 Piwik_API_Proxy->call(...) called at [/var/www/piwik/core/API/Request.php:138]
#8 Piwik_API_Request->process(...) called at [/var/www/piwik/plugins/API/Controller.php:25]
#9 Piwik_API_Controller->index(...) called at [:]
#10 call_user_func_array(...) called at [/var/www/piwik/core/FrontController.php:125]
#11 Piwik_FrontController->dispatch(...) called at [/var/www/piwik/index.php:47]

Link to that file:
https://github.com/JulienMoumne/piwik/blob/cd811234e4b838f651ef0ef5d1218175e19d204d/plugins/ImageGraph/StaticGraph.php

comment:13 Changed 13 months ago by JulienM (JulienMoumne)

Try this https://github.com/JulienMoumne/piwik/commit/d189d5a29a3b4fd4f938bd180fee7aa72e8c5cce

You will still have an exception but this time it will be more explicit.

comment:14 Changed 13 months ago by tsteur

Seems to be fixed. The following error message is displayed within the graph now:

API returned an error. Refererrs.getAll with multiple sites or dates is not supported (yet).

But that's another issue which has nothing to do with the colors (API should not return an evolution graph url for this report). Refererrs.getRefererType works fine.

comment:15 Changed 13 months ago by JulienM (JulienMoumne)

It seems there is an issue with metadata indeed. Could you create a separate ticket for the metadata issue?

Concerning the current ticket, could you confirm you have all you needed and that we can commit and close the ticket?

comment:16 Changed 13 months ago by tsteur

I can confirm I have all I needed. Thx again!

Will open a separate ticket for the other metadata issue.

comment:17 Changed 13 months ago by Julien Moumné

In cd811234e4b838f651ef0ef5d1218175e19d204d:

refs #3799 new ImageGraph API parameters $textColor, $backgroundColor and $gridColor (missing updated expected integration files)

comment:18 Changed 13 months ago by Julien Moumné

In d189d5a29a3b4fd4f938bd180fee7aa72e8c5cce:

refs #3799 new parameter $textColor is required to render exceptions

comment:19 Changed 13 months ago by Julien Moumné

  • Resolution set to fixed
  • Status changed from new to closed

In a57ca6ada254b91cc11d25d5f58fdc525ae0d232:

fixes #3799 update expected integration files

every text is now of the same color
legend text color was and remains 222222
axes figures was 000000 and becomes 222222

comment:20 Changed 13 months ago by matt (mattab)

excellent, I can't wait to see the new graphs that result of this ;-)

comment:21 Changed 12 months ago by tsteur

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:22 Changed 12 months ago by Julien Moumné

  • Resolution set to fixed
  • Status changed from reopened to closed

In 25a5ac6a3a272a646e7bbe6c913271ed6e96abb1:

fixes #3799 apply colors to exception message

comment:23 Changed 12 months ago by tsteur

thx!

Note: See TracTickets for help on using tickets.