how to add button to tree menu heading, i have a requirement of adding button (expand/Collapse button to all menu headings) - treeview

HEADING 1- (expand/collapse - button)
a) sub item-1.1
b) sub item-1.2
HEADING -2 (expand/collapse - button)
a) sub item -2.1
b) sub item -2.2
3)HEADING -3
4)HEADING -4
I tried below code and achieved till tree view ,
but unable to add Expand/Collapse button on/to menu heading ,
like above , and to achieve button click functionality to expand tree menu(when tree
menu Heading expanded the button text be changed to collapse other wise it was
Expand).
import React from 'react';
import logo from './logo.svg';
import './App.css';
import TreeMenu from 'react-simple-tree-menu'
function App() {
const treeData = {
'first-level-node-1': {
label: 'Node 1 ',
index: 0,
nodes: {
'second-level-node-1': {
label: 'Node 1.1',
index: 0,
nodes: {
'third-level-node-1': {
label: 'Node 1.1.1',
index: 0,
nodes: {}
},
},
},
},
},
'secondt-level-node-1': {
label: 'Node 1 ',
index: 0,
nodes: {
'second-level-node-1': {
label: 'Node 1.1',
index: 0,
nodes: {
'third-level-node-1': {
label: 'Node 1.1.1',
index: 0,
nodes: {}
},
},
},
},
},
'third-level-node-2': {
label: 'Node 2 ',
index: 1,
nodes: {
'second-level-node-1': {
label: 'Node 2.1',
index: 0,
nodes: {}
},
},
},
};
return (
<div className="App">
<button></button>
<TreeMenu data={treeData} />
</div>
);
}
export default App;

Related

Need help in ngx-graph links layout

I am trying to use ngx-graph in my project to draw a hierarchical graph. I have issue with links that connecting two nodes. I have tried all curve types, but not getting expected result.
Here is some code snippets:
HTML
[links]="links"
[nodes]="nodes"
[layoutSettings]="layoutSettings"
[curve]="curve"
[draggingEnabled]="false"
[panningEnabled]="true"
[enableZoom]="false"
[autoZoom]="true"
[autoCenter]="false"
<ng-template #nodeTemplate let-node>
<svg:g class="node">
<svg:rect [attr.width]="100" [attr.height]="50" fill ="#fff" stroke-width ="1" stroke = "#000" />
<svg:text alignment-baseline="central" [attr.x]="10" [attr.y]="node.dimension.height / 2">{{node.label}}</svg:text>
</svg:g>
</ng-template>
</ngx-graph>
TS
layoutSettings = {
orientation: 'TB'
};
nodes: Node[] = [
{
id: 'first',
label: 'Parent'
}, {
id: 'c1',
label: 'Child 1'
}, {
id: 'c2',
label: 'Child 2'
}, {
id: 'c3',
label: 'Child 3'
}
];
links: Edge[] = [
{
id: 'a',
source: 'first',
target: 'c1',
label: 'is parent of'
}, {
id: 'b',
source: 'first',
target: 'c2',
label: 'custom label'
}, {
id: 'c',
source: 'first',
target: 'c3',
label: 'custom label'
}
];
Output that I am getting is:
Expected output is:
Any help or suggestions would be appreciated Thank you.
I found answer for my own question. This can be achieved by custom layouts.
Here you can found a custom layout, which resolves my issue.

How to jump from one tab's stack navigator to the screen of the tab's parent navigator in react navigation ( v1 )

MainNavigator
const MainNavigator = StackNavigator(
{
Start:{ screen:Start },
Login:{ screen:Login },
mainFlow:{
screen: TabNavigator({
Profile: { screen: Profile },
List: { screen: List },
MenuStack: { screen: StackNavigator({
Menu: {screen: Menu},
OpenChannel: { screen: OpenChannel },
OpenChannelCreate: { screen: OpenChannelCreate },
Chat: { screen: Chat },
Member: { screen: Member },
BlockUser: { screen: BlockUser },
GroupChannel: { screen: GroupChannel },
GroupChannelInvite: { screen: GroupChannelInvite },
},{
initialRouteName: 'Menu',
headerMode: 'none',
})}
},{
initialRouteName: 'Profile'
})
}
},{
initialRouteName: 'Start',
}
);
How can I jump from Menu of mainFlow's menuStack to Login Screen of MainNavigator .
I've tried some ways like passing parents navigation to child navigation as params but I failed to pass navigation from tabNavigation to child StackNavigation...
I really need your help!

Highcharts-ng with multiple series draw chart incorrectly

I have two fiddles: no angular, and using angular. The one with the angular doesn't work correctly. It doesn't show dates in xAxis, and doesn't use percent for yAxis.
Is there something specific need to be done, to have that work with angular?
No angular html
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>
Angular html
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div ng-app="myApp">
<div ng-controller="myctrl">
<highchart id="chart1" config="ipo" class="span9"></highchart>
</div>
</div>
Not angular javascript
$(function () {
function createChart() {
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: [{
name: 'IPO',
data: [[1381881600000, 20.34], [1381968000000, 20.43], [1382054400000, 20.72]]
}, {
name: 'SPX',
data: [[1381881600000, 1721.54], [1381968000000, 1733.15], [1382054400000, 1744.5]]
}]
});
}
createChart();
});
Angular javascript
var myApp = angular.module('myApp', ['highcharts-ng']);
myApp.controller('myctrl', BindingCode);
myApp.factory("Factory", Factory);
function ipo() {
this.chartConfig = {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: [{
name: 'IPO',
data: [[1381881600000, 20.34], [1381968000000, 20.43], [1382054400000, 20.72]]
}, {
name: 'SPX',
data: [[1381881600000, 1721.54], [1381968000000, 1733.15], [1382054400000, 1744.5]]
}]
}
}
function BindingCode($scope,Factory) {
$scope.ipo = Factory.CreateChart();
$scope.ipo = $scope.ipo.chartConfig;
}
function Factory() {
return {
CreateChart: function () {
return new ipo();
}
}
}
Not angular screenshot
Angular screenshot
The problem is that not all the highchart options go into the top-level JSON configuration.
From the FAQ:
Why doesn't my plot options/tooltip/drilldown/other feature work?
At least half of all issues filed are due to this. Before you file an
issue read this! A common error is to put other Highcharts options
directly into the chartConfig. In general if the Highcharts option you
want isn't listed above you probably want to put it in
chartConfig.options.
In your case, you need to move pretty everything except 'series' into an options object.
chartConfig = {
options : {
rangeSelector: {
selected: 4
},
type: "line",
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}],
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
}
},
series: [{
name: 'IPO',
data: [[1381881600000, 20.34], [1381968000000, 20.43], [1382054400000, 20.72]]
}, {
name: 'SPX',
data: [[1381881600000, 1721.54], [1381968000000, 1733.15], [1382054400000, 1744.5]]
}]
}
Updated fiddle
https://jsfiddle.net/mgwkzob3/1/

ExtJs 5 how add item to dashboard programmatically?

I need some help. When creating dashboard I know that it need to fill parts object
parts: {
portlet: {
viewTemplate: {
layout: 'fit',
html: 'messafe from portlet'
}
},
portlet2: {
viewTemplate: {
layout: 'fit',
html: 'message from portlet2'
}
}
}
also I know that I can use them below to render parts
defaultContent: [{
type: 'portlet',
title: 'Test1',
columnIndex: 0,
height: 500
}, {
type: 'portlet2',
title: 'Test2',
columnIndex: 1,
height: 300
}, {
type: 'portlet',
title: 'Test3',
columnIndex: 1,
height: 300
}, {
type: 'portlet',
title: 'Test4',
columnIndex: 2,
height: 350
}, {
type: 'portlet',
title: 'Test5',
columnIndex: 3,
height: 350
}]
now my question is now add(do all this job) programmatically? for example I want to create new component on button click

Initializing cytoscape

being new to cytoscapeweb 2, i am following one of the provided example in order to learn how to use the API.
i cant make it work and firebug reports the following message:
Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
var n = this.nodesGroup.getBBox();
in my html document, the cytoscapeweb div is embedded in a jquery tab widget (just to provide context)
somewhere in my.html
<div id="tabs">
<ul>
<li>Interactors Selection</li>
<li>Interactome Builder</li>
</ul>
<div id="tabs-1">
<p>Tab 1 content</p>
</div>
<div id="tabs-2">
<p>Tab 2 content</p>
<div id="cy"></div>
</div>
</div>
and in foo.js
function cytoscapeInit() {
alert ("intializing cytoscape");
// create a mapper for node size
var nodeSizeMapper = {
continuousMapper: {
attr: {
name: "weight",
min: 0,
max: 100
},
mapped: {
min: 15,
max: 30
}
}
};
// call cytoscape web on the `cy` div
$("#cy").cytoscapeweb({
// define the elements in the graph
elements: {
nodes: [
{ data: { id: "a", weight: 43 }, classes: "foo" },
{ data: { id: "b", weight: 2 }, classes: "bar" },
{ data: { id: "c", weight: 88 }, classes: "foo bar" }
],
edges: [
{ data: { id: "ab", source: "a", target: "b", weight: 32 }, classes: "foo" },
{ data: { id: "bc", source: "b", target: "c", weight: 12 }, classes: "bar baz" },
{ data: { id: "ca", source: "c", target: "a", weight: 96 }, classes: "baz foo" },
{ data: { id: "ac", source: "a", target: "c", weight: 65 }, classes: "bar" }
]
},
// define the layout to use
layout: {
name: "preset",
positions: {
"a": { x: 30, y: 30 },
"b": { x: 125, y: 131 },
"c": { x: 200, y: 50 }
},
fit: false,
stop: function(){
cy.reset();
cy.center();
}
},
// define the visual style (like css) of the graph
style: {
selectors: {
"node":{
shape: "ellipse",
fillColor: "#888",
height: nodeSizeMapper,
width: nodeSizeMapper,
labelText: {
passthroughMapper: "id"
}
},
".yay": {
fillColor: "red",
lineColor: "red",
targetArrowColor: "red"
},
"edge": {
lineColor: "#ccc",
targetArrowColor: "#ccc",
width: {
continuousMapper: {
attr: {
name: "weight"
},
mapped: {
min: 2,
max: 5
}
}
},
targetArrowShape: "triangle"
},
"node:selected": {
fillColor: "#333"
},
"edge:selected":{
lineColor: "#666",
targetArrowColor: "#666"
}
}
},
// define the callback for when cytoscape web is ready
ready: function( cy ){
window.cy = cy;
}
});
Did i miss something obvious?
If so, all apologies.
(1) Don't put alerts in your code like that even when you're testing. It can break asynchronous code, like initialising Cytoscape Web or doing an AJAX call. Use console.log() instead.
(2) You're probably hiding the Cytoscape Web div, cy, with the tabs. You shouldn't be using display: none;, because the Cytoscape Web viewport will then be 0x0 px. Try something like position: absolute; left: -9999px; or similiar for hiding. This entails modifying whatever class name jQuery uses for hidden tabs (probably .ui-state-hidden or something similar).
(3) I'll look into making the renderer code more tolerant of hidden Cytoscape Web divs.
I have a better solution to this problem:
Execute jquery tab just after all of the graphs are loaded.
http://cytoscape.github.io/cytoscape.js/#core/events/cy.ready
for(var t = 0, tot=pageList.length; t<tot; t++) //draw graph for all pages
{
var currPage = pageList[t];
getData(currPage);
}
function getData(currPage)
{
//initiate graph, do stuff...
//graph ready
window[currPage + "Container"].ready(function(e)
{
if (currPage.indexOf(lastPage) != -1)//executetabsafterlastgraphisdrawn
{
setTabs();
}
});
}

Resources