HowTo empty a Vaadin 8.3.0 Chart? - vaadin8

i tried to empty a Vaadin 8 chart. I tried to overwrite it with an empty DataSeries. What am I doing wrong?
if i use:
DataSeries emtpySeries = new DataSeries("");
getUI().access(() -> junkPerMachineChart.setData(emtpySeries));
i get no error, but the chart is still there.

inspired by https://vaadin.com/forum/thread/4550466/vaadin-chart-how-to-remove-all-dataseriesitem-from-a-series
i found a solution how i could empty my chart named junkPerMachineChart.
private void emptyJunkPerMachineChart(){
List<Series> s = new ArrayList<Series>();
junkPerMachineChart.getConfiguration().setSeries(s);
junkPerMachineChart.drawChart();
}

Related

SXSSFSheet autoSizeColumn error on apache poi 4.1.2

My project using Spring Boot. I try to export data to excel file with org.apache.poi 4.1.2 , i use method autoSizeColumn to auto size column
headerRow.forEach(item -> {
sheet.autoSizeColumn(item.getColumnIndex());
});
but i get the error
java.lang.IllegalStateException: Could not auto-size column. Make sure the column was tracked prior to auto-sizing the column.
at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1591)
at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1545)
how to fix this error
I have fixed this issue following this link SXSSFSheet.autoSizeColumn is throwing IllegalStateException
i resolve this issue by using the method public void trackAllColumnsForAutoSizing() of class SXSSFSheet
public void trackAllColumnsForAutoSizing()
Tracks all columns in the sheet for auto-sizing. If this is called,
individual columns do not need to be tracked. Because determining the
best-fit width for a cell is expensive, this may affect the
performance.
Since:
3.14beta1
I have fixed the above issue with the following, do this only after you are done rendering everything on to the sheet
if you have list for columns then the following will work fine.
// autoSizing of the columns
for (int i = 0; i < columns.size(); i++) {
workbookSheet.trackAllColumnsForAutoSizing();
workbookSheet.autoSizeColumn(i);
}
For your case the below will work.
headerRow.forEach(item -> {
sheet.trackAllColumnsForAutoSizing();
sheet.autoSizeColumn(item.getColumnIndex());
});

How to Use nativescript-autocomplete plugin with nativescript angular?

I am not able to make plugin work with angular project template .GitHub shows only code in native and XML .Sample plugin code works but unfortunately no angular support or help given. I am not able show on angular template.
relevant code i am using
detail.component.ts
registerElement("AutoComplete", () => require("nativescript-autocomplete").AutoComplete);
public list :Array = ['1','2','3','4','567'] ;
public itemTapped(args){
console.log("tapped");
}
detail.component.html
<AutoComplete items=""{{list}}"" itemTap="itemTapped($event)"> </AutoComplete>
i am getting exception on console while page loads and autocompletion doesnt work
this.items.forEach is not a function inside plugin code .that line is with definition of AutoComplete.prototype.itemsUpdate inside autocomplete.android.js plugin source
Debugging into plugin source it breaks at initialization time :
'AutoComplete.prototype.itemsUpdate = function (items) {
var arr = Array.create(java.lang.String, this.items.length);
this.items.forEach(function (item, index) {
arr[index] = item;
});
var ad = new android.widget.ArrayAdapter(app.android.context, android.R.layout.simple_list_item_1, arr);
this._android.setAdapter(ad);
};'
In detail.component.html
<AutoComplete [items]="list" (itemTap)="itemTapped($event)"> </AutoComplete>
in details.component.ts add
public list:any= ['1','2','3','4','567'] ;
itemTapped(ev){
//console.log(ev); your code
}
Issue in npm version. Clone the repository.
Replace all the files in node_modules/nativescript-autocomplete ,expect screenshot, demo folders and git related files. And try the solution

How can I add an PdfFormField using IText 7 at the current page position

We have been able to add a PdfFormField at a specific location on the page using the following Scala code snippet.
val form = PdfAcroForm.getAcroForm(document.getPdfDocument(), true)
val nameField = PdfFormField.createText(document.getPdfDocument(), new Rectangle(data.x, data.y, data.width, data.height), data.formName, data.formText)
form.addField(nameField)
However, what we would like to be able to do is add it after the last Paragraph on the page that we inserted. (i.e. This field just comes directly after). Is there a way that we can derive the proper rectangle, or is there an easier way?
Thanks
There is currently no out-of-the-box way to add fields to layout, but iText team is considering implementing this functionality.
Meanwhile, there are easy ways to achieve your goal, and there are a few of them.
My examples will be in Java, but I assume you will easily be able to use them in Scala.
The first approach is just to get the bottom position of the paragraph you have added and add your field with respect to that position. The bottom position of the last paragraph happens to be the top position of the rest of available box of content on the page (area), which converts to the following code:
Document doc = new Document(pdfDoc);
doc.add(new Paragraph("This is a paragraph.\nForm field will be inserted after it"));
Rectangle freeBBox = doc.getRenderer().getCurrentArea().getBBox();
float top = freeBBox.getTop();
float fieldHeight = 20;
PdfTextFormField field = PdfFormField.createText(pdfDoc,
new Rectangle(freeBBox.getLeft(), top - fieldHeight, 100, fieldHeight), "myField", "Value");
form.addField(field);
The part you are interested in is
Rectangle freeBBox = doc.getRenderer().getCurrentArea().getBBox();
which gives you the rectangle where the content is not placed yet.
Note, however, that this approach will not affect the following paragraphs after you the one after which you want to add the form field, which means this form field and the content might overlap.
Do deal with this situation, you might want to take advantage of possibility to create custom layout elements in iText7.
Which, in turn, is converted to the following code:
private static class TextFieldRenderer extends DivRenderer {
public TextFieldRenderer(TextFieldLayoutElement modelElement) {
super(modelElement);
}
#Override
public void draw(DrawContext drawContext) {
super.draw(drawContext);
PdfAcroForm form = PdfAcroForm.getAcroForm(drawContext.getDocument(), true);
PdfTextFormField field = PdfFormField.createText(drawContext.getDocument(),
occupiedArea.getBBox(), "myField2", "Another Value");
form.addField(field);
}
}
private static class TextFieldLayoutElement extends Div {
#Override
public IRenderer getRenderer() {
return new TextFieldRenderer(this);
}
}
Then you will just need to add the elements in a fancy way:
doc.add(new Paragraph("This is another paragraph.\nForm field will be inserted right after it."));
doc.add(new TextFieldLayoutElement().setWidth(100).setHeight(20));
doc.add(new Paragraph("This paragraph follows the form field"));
In short, what we have done here is that we created a custom dummy Div element (which is an analogue of HTML's div), which will occupy area during laying out, but we defined custom #draw() operator for this element so that form field is inserted right when we know the exact position where we want to do it.
You can find the complete code of the sample here. Note, however, that the link may change as samples repository is under reorganization now.

Prefuse: Adding labels to edges?

In my prefuse visualization I want to add label to edges. I followed some examples proposed here on SO, but I can't bring it to work:
I use this Renderer for my edges:
private class CustomEdgeRenderer extends LabelRenderer {
private EdgeRenderer edgeRenderer = new EdgeRenderer();
#Override
public String getText(VisualItem item) {
System.out.println("edgerenderer");
return "test";
}
#Override
public void render(Graphics2D g, VisualItem item) {
edgeRenderer.render(g, item);
item.setTextColor(BLACK);
}
}
The problem now is, that the text isn't displayed, but the edges are drawn in a weird form. That is they aren't correctly drawn. If I don't overwrite render, then the text is drawn, but no edges. How can i make this work?
Following the architecture of prefuse you would create a separate group of visual items for the labels, so called DecoratorItem.
An example can be found in the TreeMap demo:
https://github.com/prefuse/Prefuse/blob/master/demos/prefuse/demos/TreeMap.java
Another more ad-hoc solution:
Extend EdgeRenderer.
Take care of drawing the label in the render method.
Call super.render to let prefuse draw the edge.
You could check this question:
Displaying edges labels in prefuse (java) graphs
Google send me here and the previous questions, and looking for some code, I recently found the following version and runs ok.
http://netgrok.googlecode.com/svn-history/r2/trunk/src/test/AggregateDecoratorDemo.java
Regards.

Populating a dropdown list in Flash Builder

I'm currently using the following code in Flash Builder to return a list of variables from an XML file:
[Bindable] private var I_Authors:ArrayCollection = new ArrayCollection ();
private function init():void {
var param:Object = new Object();
param.action = "getAuthorXML";
authorService.send(param);
}
protected function authorService_resultHandler(event:ResultEvent):void
{
I_Authors = event.result.authors.author;
}
My problem is making use of this data in a dropdown list.
I have no trouble putting it into a data grid using dataProvider="{I_Authors}" and dataField="ID" etc., but all the attempts I've made to put a specific field (ID) into a dropdown list have resulted in "object Object".
I'm just starting out with flash builder so its probably a basic question but all of the tutorials I've followed on Adobe's website don't seem to be any help.
Would appreciate any advice.
Turns out you use labelField="" , just incase anyone else is a bit confused about this.
<s:DropDownList id="dropdownList" dataProvider="{________}" labelField="________"></s:DropDownList>
The problem is "author" is an object.
When you get your results from authorService you receive an object
I_Authors = event.result.authors.author;
So you have an array of objects.
You probably want to get property of your object eg.: author.ID
I_Authors = event.result.authors.author.ID;
So you have an array of author ID.
dataProvider= I_Authors
Let me know if it wasn't clear and you need more explanation.

Resources