Dojox chart number of Y axis labels - dojo

When I create a DojoX vertical bar chart, it automatically calculates the labels on the Y axis to cover the largest value. In this case, it created 3 Y-axis labels, 100, 200 300.
How do I increase the number of labels, to say intervals of 50 rather than intervals of 100?

When you add an axis, there are several options you can use for the tick marks. Example:
chart.addAxis("y", {
majorTicks : true, // default
majorLabels : true, // default
majorTick : {length: 4, color: "#FFF"},
majorTickStep : 10,
minorTicks : true,
minorLabels : true,
minorTick : { length: 2, color: "#CCC"},
minorTickStep : 5,
...
vertical: true
});
Check the API docs for more: http://dojotoolkit.org/api/1.8/dojox/charting/axis2d/Default

Related

GSAP with MotionPath and autoRotate not working

Im using GSAP with MotionPathPlugin and the PixiPlugin to make my square follow a path. I have set autoRotate to true but there seems to be a bug, as you can see in the GIF. Seems like my sprite is over rotating a little bit.
The path is an array of {x, y} values.
I also tried using the array method for autoRotate as such autoRotate: ['x', 'y', 'angle', 90, true], // 4th param is angle in rad
motionPath: {
autoRotate: ['x', 'y', 'angle', 90, true], // 4th param is angle in rad
alignOrigin: [0.5, 0.5],
// autoRotate: true,
align: values,
path: values,
curviness: 0,
},
Thank you for any input.
After a lot of searching I found I need to useRadians: true, in the MotionPath vars option.
gsap.to(sprite, {
motionPath: {
autoRotate: 1.5708,//in radians, offset rotation by 90 degree
path: values,
curviness: 0,
useRadians: true,
},
}

Adjust plotly-Dash table column width

I want to adjust the width of columns in Dash table (created from Pandas Dataframe). There are 3 columns in table :
Path
Scenario
Step
I want to set the column width of first column (Path) to 10% and the second column (Scenario) to 40% and the last column (Step) to 50%.
I am running below code, but the column width changes are not working as expected. "Path" column is taking more than 50% of width and "Steps" column around 20%.
Dataframe name is dfSteps
columns=[{"name": i, "id": i} for i in dfSteps.columns],
data=dfSteps.to_dict('records'),
style_header={
'backgroundColor': 'rgb(230, 230, 230)',
'fontWeight': 'bold'
},
style_table={
'maxWidth': '2000px',
'overflowX': 'scroll',
'border': 'thin lightgrey solid'
},
style_cell={
'font_family': 'cursive',
'font_size': '16px',
'border': '1px solid grey',
'minWidth': '1px', 'width': 'fixed', 'maxWidth': '1000px',
'textAlign': 'left', 'whiteSpace': 'normal'
},
style_cell_conditional=[
{'if': {'column_id': 'Path'},
'width': '10%'},
{'if': {'column_id': 'Scenario'},
'width': '40%'},
{'if': {'column_id': 'Path'},
'width': '50%'},
],
),
Just redefine your table as they suggest in the documentation
https://plotly.com/python/table/
fig = go.Figure(data=[go.Table(
columnorder = [1,2],
columnwidth = [80,400],
header = dict(
values = [['<b>EXPENSES</b><br>as of July 2017'],
['<b>DESCRIPTION</b>']],
line_color='darkslategray',
fill_color='royalblue',
align=['left','center'],
font=dict(color='white', size=12),
height=40
),
cells=dict(
values=values,
line_color='darkslategray',
fill=dict(color=['paleturquoise', 'white']),
align=['left', 'center'],
font_size=12,
height=30)
)
])
fig.show()

c3 charts dynamic bubble size in scatter plot, wrong index

I'm trying to make a chart like with c3.js.
For the bubble size I create an array for each "continent" holding the population as a factor to increase the bubble size. Also the country name is stored in the same manner.
When adding the data points to the chart as well as when adding the bubble sizes/country names to the array, the indices are the same. E.g. col_2[0] in the bubbleInfo array is "China". Also in the data columns col_2[0] and col_2_x[0] are 76 and 12000 which are the values for China.
However, in the section where I dynamically get the bubble radius/country name, the index I get from the function parameter is not the one of the col_2 arrays. Instead I get the index in the order in which the dots are spead along the x-Axis.
E.g. I add for x-Axis China (12000), India(5800), Indonesia(9000) in this order.
I'd expect to get index 1 for India, but I get index 0, because 5800 is the lowest of the x values.
Because of that I cannot properly map the indices on the bubble sizes/country names, since the indices are wrong.
Is this a bug and if so, how can I properly map the bubble sizes/country names then?
Here is the JSFiddle:
var chart_3_bubbleSize = {
"col_2": [10.0, 9.0, 3.9, 2.5, ],
"col_1": [3.0, 2.5, ],
"col_3": [2.5, 5.5, ],
};
...
var chart_3_bubbleInfo = {
"col_2": ["China", "India", "Indonesia", "Japan", ],
"col_1": ["Russia", "Germany", ],
"col_3": ["Mexico", "USA", ],
};
...
columns: [
['col_2', 76, 66, 71, 86],
['col_2_x', 12000, 5800, 9000, 36000],
['col_1', 72, 80.4],
['col_1_x', 25000, 40000],
['col_3', 76, 78],
['col_3_x', 16000, 50000],
],
...
point:
{
r: function(d)
{
/*d.index gives the index according to the order along the x-axis, which leads to wrong result, when trying to map to country names/bubble sizes*/
return 2 * chart_3_bubbleSize[d.id][d.index];
}
},
https://jsfiddle.net/51oLxqyt/1/
The first green bubble in the lower left corner should be India, but it has the label "China" and the bubble size of China, because China is at index 0 in the bubbleInfo and bubbleSize arrays.
There is an not documented attribute data.xSort = false, which keeps the original index, which makes it possible to map more dimension e.g. for scatter charts.
More info here: https://github.com/c3js/c3/issues/547#issuecomment-56292971

Cytoscape.js layout edge length

Hi I'm trying to build a web-crawler visualization tool for a school project. I decided to use Cytoscape.js and it's been really nice to use. The problem i'm having is the edge lengths for some of the layouts (circle, breadth first, concentric) seem too large and the graph looks odd.
When I first start the application, I manually make and load a graph(it's a tree) with 100 nodes and that looks good in Circle layout:
However after I perform a web-crawl the new graph( this one has 44 nodes) doesn't fit in the view for circle:
Is there a way to get this to work so that the edges are not so long and the nodes look larger?
Edit:
Here's the code I use to change the layout:
changeLayout = function(layoutName, title, root){
var numOfNodes = cy.filter('node').length;
//extent changes when I repeatedly change the layout to circle, (don't understand this behavior)
var extent = cy.extent();
var rect = document.getElementById("cy-container").getBoundingClientRect();
var x1 = rect.left;
var x2 = rect.right;
var y1 = rect.top;
var y2 = rect.bottom;
var height = (y2 - y1);
var width = (x2 - x1);
var fact = (height < width) ? (height/numOfNodes) : (width/numOfNodes);
fact *= 5;
var myRadius = height < width ? (height-fact) : (width-fact);
switch(layoutName){
case 'circle':
myLayout = cy.makeLayout(
{ name: layoutName,
radius: myRadius,
boundingBox: {x1: x1, x2: x2, y1: y1, y2: y2},
fit: true,
avoidOverlap: false
});
break;
case 'concentric':
myLayout = cy.makeLayout(
{ name: layoutName,
height: height,
width: width,
fit: false,
avoidOverlap: true
});
break;
case 'breadthfirst':
myLayout = cy.makeLayout(
{ name: layoutName,
boundingBox: {x1: x1, x2: x2, y1: y1, y2: y2},
fit: true,
roots: root,
avoidOverlap: false
});
break;
default :
myLayout = cy.makeLayout(
{
name: layoutName
});
}
myLayout.run();
$('#graphTitle').text(title + " Layout");
};
The length of an edge is a function of the positions of the nodes. The layout sets the positions, so you have to set the layout options to make the nodes closer together.
For force-directed (physics simulation) layouts, you adjust the forces. In other layouts, you can adjust spacing values or enforce a bounding box to affect how spread out the nodes are.

Setting a max axis value or range step for a Morris Bar Chart?

I was wondering if it is possible to set a max axis value (say, I want the highest point of my data to be the top end of the y-axis) on a bar chart? I see there are options for ymin and ymax on line charts but I can't seem to find any information about the bar charts.
Also, it would be helpful if anyone knew how to force the range between axis lanes to be a certain amount (say step up by 250 each line instead of the generated amount which in my case is too high for my liking).
Set a maximum value for the y axis
You can, indeed, set the ymax for bar charts also (even though this is not documented).
Morris.Bar({
element: 'bar-example',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
xkey: 'y',
ymax: 300, // set this value according to your liking
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B']
});
And have your y axis set to this maximum value:
Set a range value for the y axis
It seems that it's not possible to set a range value for the y axis. This value appears to be computed according to the values of the data passed to Morris.Bar.
Not documented, but you can set maximum y by applying ymax. You can manipulate the range by setting numLines (also not documented).
E.g.
var chart = new Morris.Bar({
...
ymin: 0,
ymax: 7,
numLines: 8,
...
});
The above defined chart will display values from 0 to 7 and display a grid line for each integer between 0 and 7 (therefore 8 as a parameter)
To change to ymax call this
chart.options["ymax"] = 300;
Where chart is your chart variable
I want the highest point of my data to be the top end of the y-axis
The documentation is very sparse and confusing but this is possible using the ymin variable which is only documented in the Lines & Area Charts. The default value for that variable seems to be auto 0 and changing it to just auto seems to produce the desired result as you can see below.
how to force the range between axis lanes to be a certain amount
This does not seem to be possible, natively. However, you can kind of hack the axis label with the following function. It will round the value to multiples of 250 BUT the grid lines won't be at the number shown. E.g. say a grid line is at 570. The function below will change the label to 500 but the line will still show at 570 mark.
yLabelFormat: function(d) {
return Math.round(d) - (Math.round(d) % 250);
},
As others have mentioned, you can set ymax to a value that you want your upper bound to be but since you want the highest data point to be the upper bound, set ymax to auto. You can also try changing numLines to different values for a better aesthetic.