Dear All,
Please find attached two modules that are an attempt to add interactive an matplotlib scatter plot inside the table view of Camelot. This is useful for myself. I hope it is useful for others as well. But note I have some questions for possible improvement (see below). This is really a first stab by a Python enthusiast, not production code at all. See some issues and questions below.
There are two modules. The first, "chart_controls", provides GUI elements that can be added to the right column (list_actions) and the code to actually create the chart. The controls allow the user to flexibly select the x and y variable in the plot.
The second (optional) module contains some additional functionality to load a second database and plot data in the same chart with a different color. There is functionality to apply the same header filter values as set in the Camelot GUI at that time although this is only implemented with the Dutch values of the filters (it needs an alternative way to read the filters or internationalisation). Filter in the sidebar are not implemented.
To make it work, simply add the provided classes to and EntityAdmin. The following is an examle for the VisitorReport in the Camelot examples. I have added a fictive "payments" column to the model to have two numbers that can be plotted against each other. This yields the screenshot as attached.
class Admin(EntityAdmin):
# other elements omitted
list_actions = [list_actions_box((
xy_combo_box('x: ', 'xvar', list_display, 'visitors'),
xy_combo_box('y: ', 'yvar', list_display, 'payments'),
comparison_data_group_box(),
use_selection_check_box(),
),'Chart Controls'),
chart_button(list_display,comp_data_mod = 'model',comp_data_class='VisitorReport'),
]
Some questions for improvement:
- Currently, the retrieval of data and the creation of the chart happens in the GUI thread. How could I move it to the model thread? The issue here is that I also would like to have access to gui_context to read the values of the values of some QWidgets.
- It would be nice to have a draggable horizontal QSplitter between the chart and the table so that these elements can be resized. Can that be done without editting core Camelot code? I tried to create a QSplitter and add the (already existing) table as a child (see commented out code starting at line 260 in the chart_controls module). This didn't work. I probably don't sufficiently understand the structure of the GUI elements and need to look in the code anyway. If core Camelot code needs to be editted, then where to start?
- In order to apply the same filters to the data from the secondary database I read the filter operators (equal to, larger than, ...) from the GUI using the currentText method of the QWidgets. That results in internationalised values. Is there a way to get them in the same language all the time so that my code consistently works? I guess that one method could be to force the language in the application (but not the most elegant solution).
- Is there a function call available that directly opens the form for a certain object? I could possibly use it in the plot to open the object belonging to a specific data point.
Regards,
Rogier Eggers