def testChart(self): """ Check chart doesn't allow 'Major' as class """ chart.Chart( width="8cm", height="7cm", attributes={'class':'chart:circle'}) self.assertRaises(ValueError, chart.Chart, attributes={'class':'Major'})
def __call__(self, doc): chartstyle = style.Style(name="chartstyle", family="chart") chartstyle.addElement( style.GraphicProperties(stroke="none", fillcolor="#ffffff")) doc.automaticstyles.addElement(chartstyle) mychart = chart.Chart( width="576pt", height="504pt", stylename=chartstyle, attributes={'class':self.charttype}) doc.chart.addElement(mychart) # Title if self.title: titlestyle = style.Style(name="titlestyle", family="chart") titlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) titlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt")) doc.automaticstyles.addElement(titlestyle) mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle) mytitle.addElement( text.P(text=self.title)) mychart.addElement(mytitle) # Subtitle if self.subtitle: subtitlestyle = style.Style(name="subtitlestyle", family="chart") subtitlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) subtitlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt")) doc.automaticstyles.addElement(subtitlestyle) subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle) subtitle.addElement( text.P(text= self.subtitle)) mychart.addElement(subtitle) # Legend legendstyle = style.Style(name="legendstyle", family="chart") legendstyle.addElement( style.GraphicProperties(fill="none")) legendstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="6pt")) doc.automaticstyles.addElement(legendstyle) mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle) mychart.addElement(mylegend) # Plot area plotstyle = style.Style(name="plotstyle", family="chart") if self.subtype == "stacked": percentage="false"; stacked="true" elif self.subtype == "percentage": percentage="true"; stacked="false" else: percentage="false"; stacked="false" plotstyle.addElement( style.ChartProperties(seriessource="columns", percentage=percentage, stacked=stacked, threedimensional=self.threedimensional)) doc.automaticstyles.addElement(plotstyle) plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels, stylename=plotstyle) mychart.addElement(plotarea) # Style for the X,Y axes axisstyle = style.Style(name="axisstyle", family="chart") axisstyle.addElement( style.ChartProperties(displaylabel="true")) doc.automaticstyles.addElement(axisstyle) # Title for the X axis xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle) plotarea.addElement(xaxis) xt = chart.Title() xaxis.addElement(xt) xt.addElement(text.P(text=self.x_axis)) # Title for the Y axis yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle) plotarea.addElement(yaxis) yt = chart.Title() yaxis.addElement(yt) yt.addElement(text.P(text=self.y_axis)) # Data area datatable = DataTable( self.values ) datatable.datasourcehaslabels = self.datasourcehaslabels mychart.addElement(datatable())
def test_chart_style(self): """ Test that chart:style-name reference is seen in content.xml """ doc = OpenDocumentChart() chartstyle = Style(name="chartstyle", family="chart") chartstyle.addElement( GraphicProperties(stroke="none", fillcolor="#ffffff")) doc.automaticstyles.addElement(chartstyle) mychart = chart.Chart(width="576pt", height="504pt", stylename=chartstyle, attributes={'class': 'chart:bar'}) doc.chart.addElement(mychart) # Add title titlestyle = Style(name="titlestyle", family="chart") titlestyle.addElement(GraphicProperties(stroke="none", fill="none")) titlestyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt")) doc.automaticstyles.addElement(titlestyle) mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle) mytitle.addElement(text.P(text="Title")) mychart.addElement(mytitle) # Add subtitle subtitlestyle = Style(name="subtitlestyle", family="chart") subtitlestyle.addElement(GraphicProperties(stroke="none", fill="none")) subtitlestyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt")) doc.automaticstyles.addElement(subtitlestyle) subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle) subtitle.addElement(text.P(text="my subtitle")) mychart.addElement(subtitle) # Legend legendstyle = Style(name="legendstyle", family="chart") legendstyle.addElement(GraphicProperties(fill="none")) legendstyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="6pt")) doc.automaticstyles.addElement(legendstyle) mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle) mychart.addElement(mylegend) # Plot area plotstyle = Style(name="plotstyle", family="chart") plotstyle.addElement( ChartProperties(seriessource="columns", percentage="false", stacked="false", threedimensional="true")) doc.automaticstyles.addElement(plotstyle) plotarea = chart.PlotArea(datasourcehaslabels="both", stylename=plotstyle) mychart.addElement(plotarea) # Style for the X,Y axes axisstyle = Style(name="axisstyle", family="chart") axisstyle.addElement(ChartProperties(displaylabel="true")) doc.automaticstyles.addElement(axisstyle) # Title for the X axis xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle) plotarea.addElement(xaxis) xt = chart.Title() xaxis.addElement(xt) xt.addElement(text.P(text="x_axis")) # Title for the Y axis yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle) plotarea.addElement(yaxis) yt = chart.Title() yaxis.addElement(yt) yt.addElement(text.P(text="y_axis")) result = doc.contentxml() # contentxml() is supposed to yeld a bytes self.assertNotEqual(-1, result.find(b'''style:family="chart"'''))
def __call__(self, doc): chartstyle = style.Style(name="chartstyle", family="chart") chartstyle.addElement( style.GraphicProperties(stroke="none", fillcolor="#ffffff")) doc.automaticstyles.addElement(chartstyle) mychart = chart.Chart(width=self.width, height=self.height, stylename=chartstyle, attributes={'class': self.charttype}) doc.chart.addElement(mychart) # Title if self.title: titlestyle = style.Style(name="titlestyle", family="chart") titlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) titlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt")) doc.automaticstyles.addElement(titlestyle) mytitle = chart.Title(x="185pt", y="27pt", stylename=titlestyle) mytitle.addElement(text.P(text=self.title)) mychart.addElement(mytitle) # Subtitle if self.subtitle: subtitlestyle = style.Style(name="subtitlestyle", family="chart") subtitlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) subtitlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt")) doc.automaticstyles.addElement(subtitlestyle) subtitle = chart.Subtitle(x="50pt", y="50pt", stylename=subtitlestyle) subtitle.addElement(text.P(text=self.subtitle)) mychart.addElement(subtitle) # Legend legendstyle = style.Style(name="legendstyle", family="chart") legendstyle.addElement(style.GraphicProperties(fill="none")) legendstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="8pt")) doc.automaticstyles.addElement(legendstyle) mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle) mychart.addElement(mylegend) # Plot area plotstyle = style.Style(name="plotstyle", family="chart") if self.subtype == "stacked": percentage = "false" stacked = "true" elif self.subtype == "percentage": percentage = "true" stacked = "false" else: percentage = "false" stacked = "false" plotstyle.addElement( style.ChartProperties(seriessource="columns", percentage=percentage, stacked=stacked, threedimensional=self.threedimensional)) doc.automaticstyles.addElement(plotstyle) plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels, stylename=plotstyle) mychart.addElement(plotarea) # Style for the X,Y axes axisstyle = style.Style(name="axisstyle", family="chart") axisstyle.addElement(style.ChartProperties(displaylabel="true")) axisstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="8pt")) doc.automaticstyles.addElement(axisstyle) # Title for the X axis xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle) plotarea.addElement(xaxis) xt = chart.Title() xaxis.addElement(xt) xt.addElement(text.P(text=self.x_axis)) # Title for the Y axis yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle) plotarea.addElement(yaxis) yt = chart.Title() yaxis.addElement(yt) yt.addElement(text.P(text=self.y_axis)) # chart colors piestyle = style.Style(name="series", family="chart") piestyle.addElement(style.GraphicProperties(fillcolor="#000000")) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.critical", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskCritical)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.high", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskHigh)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.medium", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskMedium)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.low", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskLow)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.none", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskNone)) doc.automaticstyles.addElement(piestyle) # Set up the data series. OOo doesn't show correctly without them. s = chart.Series(valuescellrangeaddress="local-table.$B$2:.$B$6", labelcelladdress="local-table.$B$1", attributes={'class': self.charttype}, stylename="series") s.addElement(chart.DataPoint(stylename="piestyle.critical")) s.addElement(chart.DataPoint(stylename="piestyle.high")) s.addElement(chart.DataPoint(stylename="piestyle.medium")) s.addElement(chart.DataPoint(stylename="piestyle.low")) s.addElement(chart.DataPoint(stylename="piestyle.none")) plotarea.addElement(s) # The data are placed in a table inside the chart object - but could also be a # table in the main document datatable = DataTable(self.values) datatable.datasourcehaslabels = self.datasourcehaslabels mychart.addElement(datatable())
def test_calls(self): """ Simple calls """ chart.Chart(attributes={'class': 'chart:bar'}, height="0cm") chart.Chart(attributes={'class': 'chart:bar'}, width="0cm") draw.AreaCircle(cy="1cm", cx="1cm", r="0cm") draw.AreaPolygon(height="1cm", points="0,0 1,1", y="1cm", x="1cm", viewbox="0 0 1000 1000", width="0cm") draw.AreaPolygon(height="1cm", width="1cm", points="0,0 1,1", x="1cm", viewbox="0 0 1000 1000", y="0cm") draw.AreaPolygon(height="1cm", width="1cm", points="0,0 1,1", y="1cm", viewbox="0 0 1000 1000", x="0cm") draw.AreaPolygon(width="1cm", points="0,0 1,1", y="1cm", x="1cm", viewbox="0 0 1000 1000", height="0cm") draw.AreaRectangle(x="1cm", height="1cm", width="1cm", y="0cm") draw.AreaRectangle(y="1cm", height="1cm", width="1cm", x="0cm") draw.AreaRectangle(y="1cm", x="1cm", height="1cm", width="0cm") draw.AreaRectangle(y="1cm", x="1cm", width="1cm", height="0cm") draw.ContourPath(recreateonedit="1cm", viewbox="0 0 1000 1000", d="1cm", height="0cm") draw.ContourPath(recreateonedit="1cm", viewbox="0 0 1000 1000", d="1cm", width="0cm") draw.ContourPolygon(points="0,0 1,1", recreateonedit="1cm", viewbox="0 0 1000 1000", height="0cm") draw.ContourPolygon(points="0,0 1,1", recreateonedit="1cm", viewbox="0 0 1000 1000", width="0cm") draw.Control(control="1cm", endx="0cm") draw.Control(control="1cm", endy="0cm") draw.Control(control="1cm", height="0cm") draw.Control(control="1cm", width="0cm") draw.Control(control="1cm", x="0cm") draw.Control(control="1cm", y="0cm") draw.FillImage(href="1cm", name="1cm", height="0cm") draw.FillImage(href="1cm", name="1cm", width="0cm") draw.GluePoint(x="1cm", align="1cm", id="1cm", y="0cm", escapedirection="right") draw.GluePoint(y="1cm", align="1cm", id="1cm", x="0cm", escapedirection="right") draw.Line(x2="1cm", x1="1cm", y2="1cm", y1="0cm") draw.Line(y1="1cm", x1="1cm", y2="1cm", x2="0cm") draw.Line(y1="1cm", x2="1cm", x1="1cm", y2="0cm") draw.Line(y1="1cm", x2="1cm", x1="1cm", y2="1cm", endx="0cm") draw.Line(y1="1cm", x2="1cm", x1="1cm", y2="1cm", endy="0cm") draw.Line(y1="1cm", x2="1cm", y2="1cm", x1="0cm") draw.Measure(x2="1cm", x1="1cm", y2="1cm", y1="0cm") draw.Measure(y1="1cm", x1="1cm", y2="1cm", x2="0cm") draw.Measure(y1="1cm", x2="1cm", x1="1cm", y2="0cm") draw.Measure(y1="1cm", x2="1cm", x1="1cm", y2="1cm", endx="0cm") draw.Measure(y1="1cm", x2="1cm", x1="1cm", y2="1cm", endy="0cm") draw.Measure(y1="1cm", x2="1cm", y2="1cm", x1="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", endx="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", endy="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", height="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", width="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", x="0cm") draw.Path(d="1cm", viewbox="0 0 1000 1000", y="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", endx="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", endy="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", height="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", width="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", x="0cm") draw.Polygon(points="0,0 1,1", viewbox="0 0 1000 1000", y="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", endx="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", endy="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", height="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", width="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", x="0cm") draw.Polyline(points="0,0 1,1", viewbox="0 0 1000 1000", y="0cm") draw.RegularPolygon(corners="1cm", endx="0cm") draw.RegularPolygon(corners="1cm", endy="0cm") draw.RegularPolygon(corners="1cm", height="0cm") draw.RegularPolygon(corners="1cm", width="0cm") draw.RegularPolygon(corners="1cm", x="0cm") draw.RegularPolygon(corners="1cm", y="0cm") draw.StrokeDash(name="1cm", dots1length="0cm") draw.StrokeDash(name="1cm", dots2length="0cm") presentation.Placeholder(x="1cm", height="1cm", object="1cm", width="1cm", y="0cm") presentation.Placeholder(y="1cm", height="1cm", object="1cm", width="1cm", x="0cm") presentation.Placeholder(y="1cm", x="1cm", height="1cm", object="1cm", width="0cm") presentation.Placeholder(y="1cm", x="1cm", object="1cm", width="1cm", height="0cm") style.Column(relwidth="1cm", endindent="0cm") style.Column(relwidth="1cm", spaceafter="0cm") style.Column(relwidth="1cm", spacebefore="0cm") style.Column(relwidth="1cm", startindent="0cm") style.Columns(columncount="1cm", columngap="0cm") style.TabStop(position="0cm") svg.Lineargradient(name="1cm", x1="0cm") svg.Lineargradient(name="1cm", x2="0cm") svg.Lineargradient(name="1cm", y1="0cm") svg.Lineargradient(name="1cm", y2="0cm") svg.Radialgradient(name="1cm", r="0cm")