How to separate out display and data mxgraph ports example - mxgraph

I am working with mxgraph and using the mxgraph ports example as a starting point for my application. https://jgraph.github.io/mxgraph/javascript/examples/ports.html
The example passes the content of each cell through the value property of an mxcell object. The display content is an html label which is then rendered inside the cell. Example code below shows the creation of an draggable icon on the sidebar the parameters are graph, sidebar, label, image.
addSidebarIcon(graph, sidebar,
'<h1 style="margin:0px;">Website</h1><br>'+
'<img src="images/icons48/earth.png" width="48" height="48">'+
'<br>'+
'Browse',
'images/icons48/earth.png');
The addSideBarIcon function then creates the vertex by passing it's label argument as the value property of the MxCell.
v1 = graph.insertVertex(parent, null, label, x, y, 120, 120);
I would like to be able to add a JSON object to store non display data along with the html label for display purposes in the value property of each cell. I would like to do this without modifying the underlying prototypes.
addSidebarIcon(graph,
sidebar, {
display: '<h1 style="margin:0px;">Process</h1><br>' +
'<img src="images/icons48/gear.png" width="48" height="48">' +
'<br><select><option>Value1</option><option>Value2</option></select><br>',
data: {
key1: val1
},
}
When I do this he code is interpreting the value as an html label. where as I would like it to interpret only value.display as the label. I'm not sure how to go about combining the html label and json data together and would love some suggestions.

You have the implementation of the addSidebarIcon in the same file...
When you find the:
v1 = graph.insertVertex(parent, null, label, x, y, 120, 120);
You have to use there not the "label", but extract the display value from your JSON.

Related

Additional legend or text box window in a plot in octave

I would like to add to my plot a text or a legend box with comments.
At the moment my legend is plot at northeastoutside and i would like to add the new legend (or textbox) to the position southeastoutside.
Thanks!
Lacking more information about your case:
To the best of my knowledge one axes object can only have a single legend object. You can create a second legend with a second axes object. Each legend will only list data elements associated with each axes. Adapted from Matlab Newsgroup thread
a = [1:0.01:2*pi]; %create sample data
b = sin(a);
linehandle1 = line(a,b); %creates a line plot with handle object
axeshandle1 = gca; % gets the handle for the axes object just created
legendhandle1 = legend('y = sin(x)', 'location', 'northeastoutside'); %makes first legend
axeshandle2 = axes('Position',get(axeshandle1,'Position'),'xlim',get(axeshandle1,'xlim'),'ylim',get(axeshandle1,'ylim'),'Visible','off','Color','none'); %makes invisible axes with same position and scaling
linehandle2 = line(pi/2,1,'Color','r','Marker','o','Parent',axeshandle2); %puts data set on 2nd axes
linehandle3 = line(pi,0,'Color','b','Marker','x','Parent',axeshandle2);
legend_handle2 = legend('peak','zero','location','southeastoutside'); %creates legend to go with 2nd axes
If you just want text in that 2nd box, not necessarily legend info or data labels, you can play around with annotation as described above. This has the advantage of being simpler to call, but maybe harder to get the exact position/result you want. There are a large number of property options that can be adjusted to get the desired appearance. A few are shown in the example. It may be there are easier ways to set the size/position based on the legendhandle.
a = [1:0.01:2*pi]; %create sample data
b = sin(a);
plot(a,b);
legendhandle = legend('y = sin(x)','location','northeastoutside');
annotation('textbox',[0.875 0.1 0.1 0.1],'string','my text','edgecolor','k','linewidth',1,'fitboxtotext','off');

add value to current value of text input in flash AS3?

I'm trying to add value to the current value of an input text field in AS3.
EXAMPLE: I have a few buttons and each button has a value, when i click on each button, the value of that button gets copied/inserted into a text input field on the stage.
further explanation:
button 1 value is (BALL)
button 2 value is (Book)
button 3 value is (Pen)
button 4 value is (cup)
etc etc ....
I have an empty input field on the stage called rest_Text.text.
so when I click on any of the buttons above, the value of that button gets copied inot the rest_Text.text...
and the final result would be something like this in the rest_Text.text:
BALL, Book, Pen
my current code is this:
function clipClick(e:Event):void {
MovieClip(root).main.loginHolder.rest_Text.text = e.target.clickTitle;
}
the code above will delete the current value and replaces it with a new one! but i need to add each value to the current one without deleting the old value.
any help would be appreciated.
Thanks in advance.
You can concatenate strings using the addition operator (+). For example:
trace(btn1.clickTitle + btn2.clickTitle + btn3.clickTitle);
//traces "BALLBookPen"
Adding on to an existing string is done with addition assignment (+=). Since you want a comma and space between each string, this is how you'd rewrite your function:
function clipClick(e:Event):void {
MovieClip(root).main.loginHolder.rest_Text.text += ", " + e.target.clickTitle;
}

How to provide multiple links in one cell of a QTableView

I have a QTableView in my project, in which several columns display data that includes a hyperlink. I use a delegate class for these to set it up so that when the cell in the column is clicked, it opens the linked page in the browser. This works great... when it's only one value being linked to one page. For example, I may have a list of search values for mysite.com where the columns have values A, B, C, etc.. If the user clicks on the cell in this column with A, it will open a hyperlink for mysite.com/A (again, this part works fine). However, I now need to add a column that may have something like "A,B", where it needs to support links to search for A AND B in the same cell depending on which they click. I've been searching around online for a while now and it seems like this probably can't be done with a delegate. I have a line in a QTextBrowser elsewhere in my code where I can do this via HTML, like this:
QString toShow;
for(int i = 0; i < searchValueList.size(); i++)
{
toShow.append("`<a href=\"www.mysite.com/" + searchValueList.at(i) + "\"`>" +
searchValueList.at(i) + "`</a`>";
}
However I can't find any way to set the cells in a QTableView to recognize HTML formatting or Rich Text, and alas I'm not even sure that's possible. Is there any way at all to do what I'm trying to accomplish?
You can create a custom QItemDelegate for the specific column in which you can display rich text. The delegate could be like :
class RichTextDelegate: public QItemDelegate
{
public:
RichTextDelegate(QObject *parent = 0);
void paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
};
RichTextDelegate::RichTextDelegate(QObject *parent):QItemDelegate(parent)
{
}
void RichTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if( option.state & QStyle::State_Selected )
painter->fillRect( option.rect, option.palette.highlight() );
painter->save();
QTextDocument document;
document.setTextWidth(option.rect.width());
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull())
{
document.setHtml(value.toString());
painter->translate(option.rect.topLeft());
document.drawContents(painter);
}
painter->restore();
}
You should set the item delegate for the specific column :
ui->tableView->setItemDelegateForColumn(colIndex, new RichTextDelegate(ui->tableView));
Now if you set the model text for the specific column in a row to a rich text, it will be shown properly :
model->item(rowIndex, colIndex)->setText(someRichText);

Hide labels in googleVis Bubble Charts

I want to hide the labels. I believe it is something to do with the option bubble.textStyle and setting the color to none but I can't figure it out.
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
colorvar="Year", sizevar="Profit",
options=list(hAxis='{minValue:75, maxValue:125}',
width=500, height=300))
plot(Bubble)
Thanks..
The tricky thing is that it's a JSON object inside a JSON object. First you use bubble="{} to create the first JSON object and then textStyle:{} to create the next JSON object inside bubble="{}.
Here is my code and a screenshot,
# install.packages("googleVis", dependencies = TRUE)
require(googleVis)
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
colorvar="Year", sizevar="Profit",
options=list(hAxis='{minValue:75, maxValue:125}',
width=500, height=300),
bubble="{textStyle:{color: 'none', fontName:
<global-font-name>, fontSize:
<global-font-size>}}")
plot(Bubble)

I am trying to populate a DOJO pie chart from a json array created by a url

I am trying to populate a dojo pie chart from a json array created by a url.
the url returns an array that looks like this
{"pieItems":[["IPv4 TCP",475919493840],["IPv6 TCP",37443255432],["IPv4 UDP",34595392128],["IPv6 ICMP",14496],["IPv4 ICMP",46560],["IP Other",12385112]]}
I have attempted to redo the format of the array changing it to one that looks like this
{"IPv4 TCP":[475919493840],"IPv6 TCP":[37443255432],"IPv4 UDP":[34595392128],"IPv6 ICMP":[14496],"IPv4 ICMP":[46560],"IP Other":[12385112]} .
the code I used to change the format is:
var len = responseObj.pieItems.length, i, hash = {};
for (i = 0; i < len; i++) {
hash[responseObj.pieItems[i][0]] = responseObj.pieItems[i][1];
}
After changing the format I can only populate the chart with on item by adding the series and specifying the name.
chart1.addSeries("IP Other", hash["IPv6 ICMP"])
This populates the chart with that one item but if i try to add another series for example
chart1.addSeries("IP Other", hash["IPv4 Other"])
It overwrites the chart and shows the data for IP Other instead of adding another slice.
How can I add all the items in the array into the pie chart?
Pie chart supports just one series object by definition. You should add different data points for different slices. A sketch:
chart.addSeries("IP", dojo.map(responseObj, function(p){
return {
y: p[1], // value
text: p[0] // label
};
});