I have a pie chart and I need to change the size of the symbols in the legend, but there's only setSymbolWidth. How do I change the height of the symbol?
I'm using Moxie Group's GWT highchart, but if there's a way in solving this with the javascript highcharts I'm probably able to do it in the GWT version.
I tried this solution http://jsfiddle.net/MEr2n/ but the series property is returning null (don't know why) even after I add a series to the chart. I'm also not sure this would work because it seems this solution gets the SVG element of the legend from the serie and set its property directly, in my case there is one serie and a symbol for each point in the serie.
I solved it. Unfortunately I needed to create a very ugly workaround for this. At least it worked.
My solution was:
NodeList<Element> gElements = chart.getElement().getElementsByTagName('g');
for (int i = 0; i < gElements.getLength(); i++) {
Element gel = gElements.getItem(i);
if (gel.getAttribute("class").equals("highcharts-legend")) {
NodeList<Element> elements = gel.getElementsByTagName("rect");
for (int j = 0; j < elements.getLength(); j++) {
elements.getItem(j).setAttribute("height", "8");
}
break;
}
}
I guess I could have used gwt-jquery to get the g element with the highcharts-legend class, but I don't want to add another API just for this.
Related
I am currently having a bit of trouble making objects in my world wrap. It sort of works, but very often objets appear to get stuck on the boundaries. My wrap code is as follows:
// Wrap our position if we are outside of the world bounds
if (this.state.pos.get(0) > 860) {
this.state.pos.set(0, this.state.pos.get(1));
}
else if (this.state.pos.get(0) < 0) {
this.state.pos.set(860, this.state.pos.get(1));
}
if (this.state.pos.get(1) > 640) {
this.state.pos.set(this.state.pos.get(0), 0);
}
else if (this.state.pos.get(1) < 0) {
this.state.pos.set(this.state.pos.get(0), 640);
}
Is there a better way of doing this? Should I use a translation on the object's position vector rather than simply setting it?
Without a jsfiddle it's a bit hard to diagnose, however this might be due to the this.state.old.pos not being set too. If the position (only) is set, then the velocity will be calculated as the difference between the current and the previous positions (in accordance with verlet integration). In that case, you're implicitly giving the body a huge velocity.
I'd recommend adding/subtracting an amount rather than setting, then you can do the same with the old position.
Here's a working example: http://labs.minutelabs.io/Relativistic-Space-Sheep/
With the relevant line of code: https://github.com/minutelabsio/Relativistic-Space-Sheep/blob/master/library/js/mediators/boilerplate.js#L743
How do I add a rectangle (or other graphical elements) as inline-elements to an iText PDF?
Example code of what I'm trying to achieve:
foreach (Row r in entrylist)
{
p = new Paragraph();
p.IndentationLeft = 10;
p.SpacingBefore = 10;
p.SpacingAfter = 10;
p.Add(new Rectangle(0, 0, 10, 10)); <<<<<<<<< THAT ONE FAILS
p.Add(new Paragraph(r.GetString("caption"), tahoma12b));
p.Add(new Paragraph(r.GetString("description"), tahoma12));
((Paragraph)p[1]).IndentationLeft = 10;
doc.Add(p);
}
It's something like a column of text-blocks, of which each of them have (only a printed) checkbox.
I've tried various things with DirectContent, but it requires me to provide absolute X and Y values. Which I simply don't have. The elements should be printed at the current position, wherever that may be.
Any clues?
You need a Chunk for which you've defined a generic tag. For instance, in this example listing a number of movies, a snippet of pellicule is drawn around the year a movie was produced and an ellipse was drawn in the background of the link to IMDB.
If you look at the MovieYears example, you'll find out how to use the PdfPageEvent interface and its onGenericTag() method. You're right that you can't add a Rectangle to a Paragraph (IMHO that wouldn't make much sense). As you indicate, you need to draw the rectangle to the direct content, and you get the coordinates of a Chunk by using the setGenericTag() method. As soon as the Chunk is drawn on the page, its coordinates will be passed to the onGenericTag() method.
I want to change the border bottom color for the tr tag in html table, which convert the pdf using Itextsharp. it is not working properly. By default black color is coming up as a result. Can any one suggest me how to achieve this uanig Itextsharp.
Thanks in Advance.
Kalai.
Try this out.
StyleSheet style = new StyleSheet();
style.LoadTagStyle("tr", "border-bottom-color", "Yellow");
objects = HTMLWorker.ParseToList(new StringReader("YOUR HTML"), style);
for (int k = 0; k < objects.Count; ++k)
{
document.AddElement((IElement)objects[k]);
}
I will create the pdf from the contents of UIViewController.
When UIViewController has a table region(the same as Excel), I didn't find the method for drawing an table in pdf document.
Does anyone know to solve this problem? Please help me.
There is no easy method of creating a table I know of if you're using a Quartz graphics context (CGContextRef type). I was able to create a table programmatically by drawing lines on the PDF in nested for loops, and by paying careful attention to spacing to make it look right.
Psuedo-code:
for (int i=0; i < numberOfRows; i++)
{
// display each row
// Draw row line
CGPoint horizontalRowDivider[2] = {CGPointMake(x_startPoint, y_startPoint + (i * row_width)), CGPointMake(x_endPoint, y_endPoint + (i * row_width))};
CGContextStrokeLineSegments(pdfContext, newlineItemDivider, 2);
for(int j = 0; j < numberOfColumns; j++)
{
//Draw each column cell
const char *desc_text = "Table value"
CGContextShowTextAtPoint (pdfContext, x_cellDataLoc, y_cellDataLoc, desc_text, strlen(desc_text));
CGPoint verticalLineCellDivider[2] = {CGPointMake(x_startPoint + (j * col_width), y_startPoint), CGPointMake(x_endPoint + (j * col_width), y_endPoint)};
CGContextStrokeLineSegments(pdfContext, verticalLineCellDivider, 2);
}
}
This is a rough example of the kind of logic you might use to draw a table. You'll probably want a rectangle, or a border, around your table to make it look right, among any other kinds of tweaks to make it how you want. You can find the list of methods on how to do that and more through the below link. I know this probably isn't what you had in mind, but I hope this gives you some direction to take if you were totally stuck. Good luck!
You can find the full library of functions available for drawing PDFs in Apple's documentation: http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
I am calling com.google.gwt.user.client.ui.TextArea.setText(myText) to set the content. After that I call setCursorPosition(myText.length()) to get the cursor to the end. This works well.
When myText has more lines then the text area can display at once, it shows a scroll bar. But it does not scroll to the cursor position. Even worse - it scrolls to the top.
How can I scroll the GWT TextArea to the cursor position? I realy need the cursor position, not the bottom of the TextArea. A JSNI workaround would be ok too.
Try adding this after setting the cursor position:
textAreaToScroll.getElement().setScrollTop(textAreaToScroll.getElement().getScrollHeight());
This will scroll the element to the bottom.
EDIT:
To scroll to the any cursor position there is (as far as I know) no easy way to do so. I don't think there is any way to ask the browser wich line the cursor is on.
I just got an idea for something that may work (haven't actually tested it) to guess a rough estimate of how long to scroll.
int cursorPos = textAreaToScroll.getCursorPos();
long offsetRatio = cursorPos / textAreaToScroll.getText().length();
//gives 0.0 to 1.0
offsetRatio += someMagicNumber; // -0.1 maybe?
// Depending on the font you may need to adjust the magic number
// to adjust the ratio if it scrolls to far or to short.
offsetRatio = offsetRatio>0.0 ? offsetRatio : 0; //make sure
//we don't get negative ratios
//(negative values may crash some browsers while others ignore it)
textAreaToScroll.getElement().setScrollTop(
textAreaToScroll.getElement().getScrollHeight() * offsetRatio );
This may scroll the roughly the desired distance. Note, this assumes each line is filled about the same amount since it uses the cursor position divided by the length of the text and not the number of lines (wich is hard to calculate). Manual newlines will skew this estimate, and proportional fonts will allso make it less accurate.
You'll probably need to adjust the ratio so that it scrolls sligtly too short rather than too far since the cursor will still be visible if it's slightly below the top of the text area.
As I said I haven't actually tested this, I may have inverted the logic and other subtle bugs.
I had a scenario where the textarea will already have something and when a new command is submitted it will add the data to it and scroll to the start of the newly added data. this is what I did
// Hold the previous height to set the scroll.
final int prevHeight = document.get().getElementById(textareadid).getScrollHeight();
// Hold the prev position if output area already has some data.
final int prevPos = this.textArea.getValue() != null ?
this.textArea.getValue().length() : 0;
after processing and setting the new data
int posCount = 0;
if (previousResponse != null && !previousResponse.isEmpty())
{
final String dataStr = "new data from process";
// add 15 lines for the cursor position
posCount = getRelativeCount(dataStr);
}
this.textArea.getElement().setScrollTop(prevHeight);
this.textArea.setCursorPos(prevPos + posCount);
private int getRelativeCount(final String str)
{
int charCount = 0;
if (str != null)
{
int NUM_ROWS = 15;
if (getUserAgent().contains("msie"))
{
NUM_ROWS = 16;
}
final String[] splitArr = str.split("\n"); // split on the new line
// char
for (int index = 0; index < splitArr.length && index < NUM_ROWS; index++)
{
charCount += splitArr[index].length();
}
}
return charCount;
}
To improve on Stein's answer, you can count the number of lines in the text, and then set the top position based on the desired line over the total lines, rather than using characters.
While you are counting lines, you will also have to determine which line the cursor is in.
String text = textArea.getText();
int lines = 1;
int pos = 0;
int cursorPos = ...;
int cursorLine = -1;
while((pos = 1+text.indexOf("\n", pos)) > 0)
{
if (cursorLine == -1 && pos > cursorPos)
cursorLine = lines;
lines++;
}
if (lines > 0 && cursorLine > 0 && cursorLine < lines)
{
int scroll = textArea.getElement().getScrollHeight();
scroll *= cursorLine;
scroll /= lines;
scroll -= 30; // Back up a bit so it's not right at the top
if (scroll < 0)
scroll = 0;
textArea.getElement().setScrollTop(scroll);
}
this worked for me:
GWT textArea Scroll issue
http://www.gwtplayground.com/2012/08/gwt-textarea-scroll-issue_21.html