Pygal not rendering Legend properly in PNG - png

I am trying to render a chart in PNG format, because this image is going to be embed in a email template and SVG are not supported on every email client, when I render the chart in SVG format it looks quite fine but when I render on PNG, the chart is fine but the legend looks wicked
The code I am using is pretty straightforward. I've installed PyCairo tinycss and cssselect
...
pie_chart = pygal.Pie()
pie_chart.title = 'Email usage on %s ' % month_str
for k, v in data.items():
if k in EMAIL_STATUS:
pie_chart.add(k, float(v))
if settings.DEBUG == True:
path = os.path.join(settings.APP_ROOT, 'static')
else:
path = settings.STATIC_ROOT
path = '%s/images/chart.png' % path
pie_chart.render_to_png(path)
Any idea what am I missing here?
Thanks

Related

Set text box as filename

I have audiowrite where I want the value of a text box to be the filename.
My current code does not work, an error says the value of filename is invalid. Anyone know how I fix this?
audiowrite(handles.edit4,'String',y,Fs);
You need to retrieve the String property of the text box using either get(handles.edit4,'String') or if you have R2014b or newer you can use handles.edit4.String
filename = get(handles.edit4, 'String');
% In case "String" is a cell array
if iscell(filename)
filename = filename{1};
end
audiowrite(filename, y, Fs)
Update
If you want to add an extension such as .mp3 you can simply use strcat to append the extension
audiowrite(strcat(filename, '.mp3'), y, Fs)

jasperreports html split text without whitespaces

String example:
"fooTextExmaple" x 100
So, it looks like one large word without whitespaces.
I have no problems with same strings in pdf, however,
I have problems dealing with large text without whispaces while exporting to HTML.
It looks like long row which does not fit any fixed width. The row's width would change dynamically by adding new chars without whitespaces to this string:
Is there any way to deal with this problem?
EDIT:
The way like it does not work:
PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
req.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
exporter = new HtmlExporter();
SimpleHtmlReportConfiguration configuration = new SimpleHtmlReportConfiguration();
configuration.setWrapBreakWord(true);
exporter.setConfiguration(configuration);
exporter.setExporterInput(new SimpleExporterInput(print));
SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(out);
String[] uriParts = req.getRequestURI().split("/");
output.setImageHandler(new WebHtmlResourceHandler("/" + uriParts[1] + "/image?image={0}"));
exporter.setExporterOutput(output);
exporter.exportReport();
Set the net.sf.jasperreports.text.save.line.breaks property to true.
Read more about it at http://jasperreports.sourceforge.net/config.reference.html
The net.sf.jasperreports.export.html.wrap.break.word property is supposed to help as well, but it only works in some browsers.

How to properly display text with tabs in listbox in MATLAB

I'm inserting text from a file into my listbox and it ignores the tabs that are between the strings. How can I make it so that it doesn't ignore the tabs and prints it as it is?
My text file:
05-WD-3052 19:56:07 03-Apr-2016
06-C-874414 19:57:03 03-Apr-2016
10-G-11 19:58:03 03-Apr-2016
What it comes out as in the listbox
my code:
fileID = fopen('Output/LicenseLog.txt','rt');
tScan = textscan(fileID, '%s','Delimiter','');
newScan = tScan{:};
set(handles.listbox1,'String',newScan);
fclose(fileID);
The listbox is respecting the tabs in your input, but you are using a variable-width font so the text isn't lining up like you would expect. You can change the FontName property of your listbox to 'FixedWidth' to use the default fixed-width font or you can set it to any fixed-width/monospaced font of your choosing to get the expected result:
data = {'05-WD-3052 19:56:07 03-Apr-2016', ...
'06-C-874414 19:57:03 03-Apr-2016', ...
'10-G-11 19:58:03 03-Apr-2016'};
u = uicontrol('Style', 'list', ...
'FontName', 'FixedWidth', ...
'String', data);
Update
After looking at your data a little closer, the issue is that tabs aren't displayed the same way across multiple systems, programs, etc. Some of your rows would actually require two tabs to properly align everything when viewing them in your GUI. Because of this, you will probably want to convert your tab-separated lists into lists with explicit spaces using sprintf.
%// Split the string into groups based on the tabs
pieces = regexp(tScans{1}, '\t+', 'split');
for k = 1:numel(pieces)
%// Create a 20-character wide padded string for each element
data{k} = sprintf('%-20s', pieces{k}{:})
end
set(handles.listbox, 'String', data)
Or if you want a one-liner:
data = cellfun(#(x)sprintf('%-20s', x{:}), regexp(tScan{1}, '\t+', 'split'), 'uni', 0);
set(handles.listbox, 'String', data)
When combining this with the fixed-width fonts mentioned above you should get the behavior your want.

Writing image files to folder in matlab

Below is some code which is showing error
imgIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
rgbBlock=ca{r,c};
imagename=strcat(int2str(imgIndex), '.jpg');
name=strcat((int2str(our_images)),'\',imagename);
imwrite(rgbBlock,'name');
I am trying to write some image file to folder using imwrite. But the last 3 lines is showing error. I need to save all the images which I have created.
I imagine that our_images is the name of the folder when you want your images, so instead of this:
name=strcat((int2str(our_images)),'\',imagename);
you need this:
name=strcat(our_images,'/',imagename);
Also look out for the backslash in there.
Also your name variable should not be quoted here:
imwrite(rgbBlock,'name');
So instead it should be:
imwrite(rgbBlock, name);

Translate VBA syntax to Matlab for Activex control of Word document

I am a newbie to using activex controls in matlab. Am trying to control a word document. I need help translating between VBA syntax and Matlab, I think. How would one code the following in matlab?
Sub macro()
With CaptionLabels("Table")
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 1
.Separator = wdSeparatorHyphen
End With
Selection.InsertCaption Label:="Table", TitleAutoText:="", Title:="", _
Position:=wdCaptionPositionAbove, ExcludeLabel:=0
End Sub
Thanks, I looked at the help and the source but I am still feeling dense. I want to be able to control caption numbering and caption text in an automated report. Am using Tables and figures. I just can't quite get my head around how to code the addition of the captions.
The following code gets me part way there. But I don't have control over numbering style, etc,. I have tried to figure out the activex structure but I can't make sense of it. In particular, In particular the first bit the VB subroutine above.
% Start an ActiveX session with Word
hdlActiveX = actxserver('Word.Application');
hdlActiveX.Visible = true;
hdlWordDoc = invoke(hdlActiveX.Documents, 'Add');
hdlActiveX.Selection.InsertCaption('Table',captiontext);
After some fiddling, I think I got it to work:
%# open Word
Word = actxserver('Word.Application');
Word.Visible = true;
%# create new document
doc = Word.Documents.Add;
%# set caption style for tables
t = Word.CaptionLabels.Item(2); %# 1:Figure, 2:Table, 3:Equation
t.NumberStyle = 0; %# wdCaptionNumberStyleArabic
t.IncludeChapterNumber = false;
t.ChapterStyleLevel = 1;
t.Separator = 0; %# wdSeparatorHyphen
%# insert table caption for current selection
Word.Selection.InsertCaption('Table', '', '', 0, false) %# wdCaptionPositionAbove
%# save document, then close
doc.SaveAs2( fullfile(pwd,'file.docx') )
doc.Close(false)
%# quit and cleanup
Word.Quit
Word.delete
Refer to the MSDN documentation to learn how to use this API. For example, the order of arguments of the InsertCaption function used above.
Note that I had to set IncludeChapterNumber to false, otherwise Word was printing "Error! No text of specified style in document" inside the caption text...
Finally, to find out the integer values of the wd* enums, I am using the ILDASM tool to disassemble the Office Interop assemblies (as this solution suggested). Simply dump the whole thing to text file, and search for the strings you are looking for.
Have a look at the help for actxserver and the source code for xlsread.m in the base MATLAB toolbox. If you're still stuck, then update your question with your progress.
EDIT:
You'll need to check the VBA help, but the first part ought to be possible via something like:
o = hdlWordDoc.CaptionLabels('Table');
o.NumberStyle = <some number corresponding to wdCaptionNumberStyleArabic>;
o.IncludeChapterNumber = true;
o.ChapterStyleLevel = 1;
o.Separator = <some number corresponding to wdSeparatorHyphen>;
In my experience, you have to get the values from the enumerations, such as wdCaptionNumberStyleArabic and wdSeparatorHyphen from a VBA script then hard-code them. You can try the following, but I don't think it works:
o.NumberStyle = 'wdCaptionNumberStyleArabic';
o.Separator = 'wdSeparatorHyphen';
Instead of hard-coding the text values into the code, you can use the enum constants. This will help when a different language of Word is installed.
A list of the Enums can be found here: https://learn.microsoft.com/en-us/office/vba/api/word(enumerations)
So instead of:
Word.Selection.InsertCaption('Table', '', '', 0, false) %# wdCaptionPositionAbove
you can use this:
NET.addAssembly('Microsoft.Office.Interop.Word')
Word.Selection.InsertCaption(...
Microsoft.Office.Interop.Word.WdCaptionLabelID.wdCaptionTable.GetHashCode,...
' My custom table caption text', '', ...
Microsoft.Office.Interop.Word.WdCaptionPosition.wdCaptionPositionAbove.GetHashCode, false)