Difference between revisions of "Chart2"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Application-Framework-Related Problems)
(Live-Preview when inserting a new Chart)
Line 82: Line 82:
  
 
As a work-around, you can create the chart with some dummy data, and then attach new data using the data provider interface. However, a new interface, probably one that only gets the name and the rectangle would be more appropriate than the work-around.
 
As a work-around, you can create the chart with some dummy data, and then attach new data using the data provider interface. However, a new interface, probably one that only gets the name and the rectangle would be more appropriate than the work-around.
 +
 +
=== Live-Preview when inserting a new Chart ===
 +
 +
In the old implementation, when a chart was inserted into Calc or Writer, you got a dialog that had its own preview in a little window. After pressing OK, the chart was created and inserted into the document.
 +
 +
In the new implementation, the container inserts a new chart first, then creates the wizard dialog (via UNO) and shows all changes directly in the newly inserted chart. When a user presses OK, everything is fine. But when a user presses Cancel, the inserted chart has to be removed again.
 +
 +
This approach is new to the applications. You insert an object (modifying the document), change it, and after pressing Cancel, you might get the unmodified document without the chart you had before. Currently, the implementations create Undo-Actions for inserting a chart. After pressing Cancel, you might still have an Undo or Redo action to get the chart back. That is not what you would expect at this place, although the undo-action might be the correct object to use when you want to make the chart insertion undone. Maybe, it is sufficient here to remove the undo/redo action from the stack of the undo-manager.
  
 
== Graphic-Framework-Related Problems ==
 
== Graphic-Framework-Related Problems ==

Revision as of 14:37, 15 August 2006

Chart2 is a sub-project of the OpenOffice.org Chart Project. Our goal is to develop a new Chart component for (presumably) OOo 2.6.

Charts are used for visualizing data sets from e.g. spreadsheets by two and three dimensional diagrams. There are a lot of different two- and three-dimensional chart types you can choose from. This page gathers information about the new chart implementation of OpenOffice.org. It is especially written to help new comers to the process of developping in the new OOo chart module.

If you would like to participate, if you have comments or questions related to the chart you are welcome on the graphics mailinglists: (users,dev,features,bugs,cvs)@graphics.openoffice.org. See also the section at the bottom of this page called [Some useful information].

Development in the New Chart

As the information on how to compile the new chart and on how to develop in this project have become quite lenghty, they can be found now on separate pages:

Open Technical Issues in the New Chart

There still some architectural issues left that have to be solved. This section serves for showing those problems and showing the progress in finding solutions.

Application-Framework-Related Problems

Identify the XDataProvider reliably

If the chart is embedded in a container document that provides the data for this chart, the chart contains range-strings at several places in its conten.xml stream that are understood by the container, so that the data can be located there. In Calc such a string would look like this: "Sheet1.A2:A7". Such range-strings can appear in the chart:plot-area element of a chart or at a chart:series, chart:categories or chart:domain element.

If a chart has its own data, this data is stored in a local table in the XML-file. The mentioned range-strings are then of a similar form, with the fixed table-name "local_table". But, the local table is also stored, as a kind of cache, if the data comes from outside. Therefore the existence of the local table does not imply that a chart has own data.

So, neither the existence of local data, nor the existence of range-addresses (and even the content, considering that it is allowed that a sheet may also have the name local_table) determines whether or not a chart uses own data or data from the container document.

In the old chart implementation, the chart always reads the internal data and uses it. If the data comes from the container, the container has an additional attribute that contains the complete data-range as one string. It then sets this string at the chart, which gives the chart the knowledge that data comes from outside (actually, in the old implementation, there is always local data. If data in Calc changes, the Calc prepares an SchMemChart object that contains the new local data and sets this object at the chart).

In the new implementation, we must to get rid of the badly-designed approach, as we no longer have one complete address-range for the entire chart.

Solution: We have to introduce a new XML-attribute at the chart that identifies the data provider. This may be a flag denoting "own data" or "external data", or even a URL, or the like, that uniquely identifies the data provider document.

Problem: Currently, it is necessary that when loading a chart, the container document is set as XParent before the chart itself is loaded. Otherwise there is no data provider, and the ranges are not valid for the internal data provider, and therefore are forgotten. A later setting of the data provider does not re-establish the correct range-strings.


Update of the Chart on changed Data

When a chart gets its data from the container document, and the data changes, the changes are notified via a listener mechanism. That is, when the chart queries for data at the XDataProvider, it gets XLabeledDataSequences. At those XLabeledDataSequences it starts listening for changes. If a change event is fired, the chart sets itself as modified, which forces the view to repaint, as it listens to model changes exactly via this mechanism.

However, if a Calc document containing Charts is loaded, the charts are either not loaded immediately because they are not visible, or because the contain a replacement image that shows the last rendered view.

In both cases, changes in the spreadsheet, like a change in data (which should be visible via a newly rendered view) or moving around ranges (which must change the ranges that are stored in the model), are not propagated to the chart, as it is not loaded and therefore is not listening.

In the old implementation, again, the fact that the Calc knew the data-range for each chart, solved this problem. Because the Calc could load all unloaded charts affected by the change, and then notify it. However, this requires internal knowledge of the chart to be exposed to the container document.

Solution: When an OLE-object is loaded, it only shows the replacement image. This state is called the "LOADED" state. This means only a small "stub" is loaded, not the entire object. The XModel of an object (including the entirely applied content of the XML-streams) is loaded in the "RUNNING" state. So when all charts would initially be set into the RUNNING state, this would ensure the existence of all XModels, which would allow the listening to work.

Problem:: It has to be evaluated, if loading the XModel objects of all charts in a document might take too long in loading a document, or if it consumes too much memory.

Context Menus via Framework API

The ChartController implements the XDispatchProvider that allows to find out whether menu entries are enabled or not via queryDispatch. The menu is created via an XML file that is defined in chart2/uiconfig.

The content of the context menu, of course, depends on the context, i.e. there cannot be a generic mechanism (like an xml-file) for defining it. But it should be possible to use context menus via UNO API, and also share the XDispatchProvider to find out if certain commands are available or not. Disabled menu items are not shown in context menus, but this should be handled by the implementation of the popup-menu.

Currently, the menu shows icons next to some menu entries, but the context menu doesn't. It should not be necessary to take care of the icons in the applications. They should work also via the framework.

Calc- and Writer-Related Problems

The com.sun.star.table.XTableCharts object is based on the old chart

When you want to insert a new chart into Calc or Writer, this can be done via the com.sun.star.table.XTableChartSupplier interface that returns an XTableCharts container. At this container there is a method:

void addNewByName(
   [in] string                            aName,
   [in] ::com::sun::star::awt::Rectangle  aRect,
   [in] sequence< CellRangeAddress >      aRanges,
   [in] boolean                           bColumnHeaders,
   [in] boolean                           bRowHeaders );

You need a sequence of CellRangeAddresses to give a range and the parameters whether to use the first column or row for labels. In comparison to the XDataProvider method:

XDataSource createDataSource(
   [in] sequence< ::com::sun::star::beans::PropertyValue > aArguments );

the parameters in aArguments differ in the following way: instead of sequence< CellRangeAddress >, we only have one string. This is no problem, as there exists a conversion. But the parameter "DataRowSource" is missing. So you can only say if the first column or row is used for labels, but not if the data comes from rows or columns. Without this information, the other information is also useless. This renders the entire interface useless.

As a work-around, you can create the chart with some dummy data, and then attach new data using the data provider interface. However, a new interface, probably one that only gets the name and the rectangle would be more appropriate than the work-around.

Live-Preview when inserting a new Chart

In the old implementation, when a chart was inserted into Calc or Writer, you got a dialog that had its own preview in a little window. After pressing OK, the chart was created and inserted into the document.

In the new implementation, the container inserts a new chart first, then creates the wizard dialog (via UNO) and shows all changes directly in the newly inserted chart. When a user presses OK, everything is fine. But when a user presses Cancel, the inserted chart has to be removed again.

This approach is new to the applications. You insert an object (modifying the document), change it, and after pressing Cancel, you might get the unmodified document without the chart you had before. Currently, the implementations create Undo-Actions for inserting a chart. After pressing Cancel, you might still have an Undo or Redo action to get the chart back. That is not what you would expect at this place, although the undo-action might be the correct object to use when you want to make the chart insertion undone. Maybe, it is sufficient here to remove the undo/redo action from the stack of the undo-manager.

Graphic-Framework-Related Problems

The type of the com.sun.star.drawing.BitmapTable

For gradients, transparency-gradients, hatches, line-dashes and bitmaps there are tables in the chart model that contain those elements together with names. E.g., you may have a gradient with the name "My Gradient". When you set the "FillGradientName" Property of an object to "My Gradient", the object will display the corresponding gradient found in this table. The same holds for fill-bitmaps.

However, there is a problem as the table for bitmaps maps a name to a URL rather than to some real graphic object. So, when you add an element to this table, the graphic itself isn't used anywhere in the document at this time. As we have a graphic-manager that deals with all graphics, that keeps graphics only if they are used (if there is a refcount > 0), the grapghics are dropped in this case.

Solution: Change this map to a mapping from names (strings) to objects of type com.sun.star.graphic.XGraphic. As the existence of an XGraphic object ensures that the graphic is available in the graphic-manager, this will solve this problem. Only in the moment an element in this list is used in no model object and also removed from the list, the underlying graphic will be dropped by the graphic-manager.

Problem: This affects also the other applications that implement this table, namely Writer, Calc and Impress. This table is also used in xmloff for a generic facility to export and import graphics in XML.

Documentation

Some useful information

Personal tools