Difference between revisions of "Resources/ChartStorageNode"
Line 59: | Line 59: | ||
<label> blood </label> | <label> blood </label> | ||
</set> | </set> | ||
− | </lookuptable> | + | </lookuptable></nowiki> |
− | |||
Each set contains a separate color. For Bar charts both color and label tags matter, for the line, scatter, and box plots, only color is relevant. The value tag shows the index of the value that was taken from lookup table. It is irrelevant to plotting. For default color, if there are index values, they can be printed there; otherwise any positive integer can be printed there. | Each set contains a separate color. For Bar charts both color and label tags matter, for the line, scatter, and box plots, only color is relevant. The value tag shows the index of the value that was taken from lookup table. It is irrelevant to plotting. For default color, if there are index values, they can be printed there; otherwise any positive integer can be printed there. | ||
Line 97: | Line 96: | ||
</xs:sequence> | </xs:sequence> | ||
</xs:complexType> | </xs:complexType> | ||
− | </xs:element> | + | </xs:element></nowiki> |
− | </nowiki> | ||
Line 124: | Line 122: | ||
</xs:complexType> | </xs:complexType> | ||
− | </xs:element> | + | </xs:element></nowiki> |
− | </nowiki> | ||
Latest revision as of 23:56, 23 December 2013
Home < Resources < ChartStorageNodeThis documentation is for the Slicer Chart Storage Node that exports the chart data from Slicer to an XML file. This chart data can then be imported into other external tools such as R and Matlab for plotting and further analysis. There is an XML schema that validates the chart once it is read in R. The chart storage node can be tested using the chart storage test built-into slicer. Currently, the chart storage node code comes with:
- C++ vtkMRMLChartStorageNode class under: Slicer\Libs\MRML\Core
- A python self-test ChartStorage.py stored under: Slicer\Applications\SlicerApp\Testing\Python
- An XML schema for validating the extracted chart data stored under: Slicer\Libs\MRML\Core\Interfaces\Schema
- And a sample R code used for reading the XML scripts, validating the XML using the schema and replicating the charts: Slicer\Libs\MRML\Core\Interfaces\R
Contents
Running the R code
The function importSlicerChart takes two arguments:
- xmlSchemaPath: is the full path to the xml schema (.xsd)
- chartPath: is the full path to the xml containing the chart
Example of running the code:
xmlSchemaPath = "C:\\Test\\SlicerSchema.xsd" chartPath = "C:\\Test\\Test_Chart.xml" importSlicerChart(xmlSchemaPath, chartPath)
Load the function importSlicerChart into the R workspace before calling it.
R code is dependent on R XML package which can be obtained from here: http://cran.r-project.org/web/packages/XML/index.html
This package is compatible only with R Version 3.0.1.
R XML package only supports XML version 1.0.
Slicer Chart Storage Test
The slicer ChartStorage test generates test charts and exports them to XMLs in a temporary directory and deletes them at the end of the test by default. To prevent the test from deleting the XML files, check the box called ‘Keep Temporary Files’ in the ChartStorage test case. The temporary directory location where the charts were exported is printed to the slicer python interactor.
Changes to be made
Color Information extracted in C++
The default color information still has to be extracted.
The default colors can be printed in the form of lookup table in the XML. To make these changes, simply print out the following line to the XML in the chart properties:
<property name = "lookupTable" value = "default"/>
Then print out the default colors in the lookup table format to XML which should look as follows:
<lookuptable name = "default"> <set> <color> #dd8265 </color> <value> 6 </value> <label> organ </label> </set> <set> <color> #b17a65 </color> <value> 3 </value> <label> skin </label> </set> <set> …. <set> <color> #d8654f </color> <value> 5 </value> <label> blood </label> </set> </lookuptable>
Each set contains a separate color. For Bar charts both color and label tags matter, for the line, scatter, and box plots, only color is relevant. The value tag shows the index of the value that was taken from lookup table. It is irrelevant to plotting. For default color, if there are index values, they can be printed there; otherwise any positive integer can be printed there.
There are TODO comments in C++ (vtkMRMLChartStorageNode.cxx) showing where changes should be made to C++ code to print these changes to XML.
XML Schema
The Chart and Array properties validation was kept generic as discussed so additional properties can be added without having to make too many changes to the XML schema. However, if changes need to be made to allow only certain names and value for properties, modify the code in the XML schema for validating properties as follows:
<xs:element name="properties"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="property"> <xs:complexType> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="xAxisType" /> <xs:enumeration value="showGrid" /> … </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="value" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="date" /> <xs:enumeration value="on" /> … </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>
The above code, however, does not match property names with values but just restricts which values can be in property names and values regardless of matching. To restrict property names to certain values in XML version 1.0, schematron can be used.
To add restriction to match certain values with specific property names, XSD version 1.1 can also be used. Assertions can be added in version 1.1 to match them like this:
<xs:element name="properties"> <xs:complexType> <xs:sequence> <xs:element name="property" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="value" type="xs:string" use="required"/> </xs:complexType> </xs:element> </xs:sequence> <xs:assert test="( (@name = xAxisType') and @value = (‘quantitative’, ‘categorical’, ‘date’) or (@name = 'showGrid') and @value = ('on', ‘off’) or (@name = 'showLegend') and @value = ('on', ‘off’) …. )"></xs:assert> </xs:complexType> </xs:element>
However, please note that R XML package does not currently support XML version 1.1. If the future versions of the package supports XML version 1.1, then use the XML schema modifications suggested for validating properties.
Assumptions
The following assumptions were made when creating the chart storage node
- Bar Charts will only have one array and each tuple includes values for one bar
- Each Array in the boxplots is a separate box plot
- Default color for bar and box charts is red for now since no color information was available. The default colors for lines is hardcoded into R
- It is assumed that box plots have no fill color, just the outside boundaries
- There is no padding in bar or box plots
- The x-axis and y-axis padding is added as a percent value in text format. For example, to pad the x-axis value by 20%, the XML will show <property name = "xAxisPad" value = "0.2"/>