Angular-nvd3 change animation transitions - angularjs

I'm using angular-nvd3 and I'm having a lot of trouble figuring out how to change the way things animate.
Below is what currently happens when you toggle a dataset on. As you can see the Expenses animate in from the upper right and the Distances animate in directly from the right. What I would like them both to do is one of two things. Either animate with a basic fade in, or grow upward.
Here is my controller. Interestingly when I added yDomain1: [1, 200] it caused the Distance chart to animate directly from the right, prior to that it was also animating in from the upper right.
controllers.controller("DashboardController", ['$scope','MileageRestService',
($scope,MileageRestService)->
$scope.vehicle_log_data = {}
MileageRestService.dashboard(
(result)->
console.log('dashboard result', result)
$scope.vehicle_log_data = result
distances = result.current_year.chart_data.distances
expenses = result.current_year.chart_data.expenses
$scope.data = [
{
key: "Distances",
color: '#ff7f0e',
area: true,
type: "line",
yAxis: 1,
values: distances
},
{
key: "Expenses",
color: '#7777ff',
area: true,
type: "line",
yAxis: 2,
values: expenses
}
]
$scope.options = {
chart: {
type: 'multiChart',
height: 256,
margin : {
top: 20,
left: 50
},
x: (d)-> d.x,
y: (d)-> (d.y),
showValues: true,
lines1: {
duration: 500
},
lines2: {
duration: 500
},
yDomain1: [1, 200],
transitions: true,
useInteractiveGuideline: true,
clipEdge: false
}
}
(error)->
console.log('dashboard error', error)
)
])
The Distance and Expense data is:
distance = [
{x: 1, y: 100},
{x: 2, y: 25},
{x: 3, y: 150},
{x: 4, y: 110},
{x: 5, y: 0},
{x: 6, y: 175},
{x: 7, y: 0},
{x: 8, y: 0},
{x: 9, y: 0},
{x: 10, y: 0},
{x: 11, y: 0},
{x: 12, y: 0}
]
expenses = [
{x: 1, y: 10},
{x: 2, y: 5},
{x: 3, y: 15},
{x: 4, y: 7.75},
{x: 5, y: 0},
{x: 6, y: 20},
{x: 7, y: 0},
{x: 8, y: 0},
{x: 9, y: 0},
{x: 10, y: 0},
{x: 11, y: 0},
{x: 12, y: 0}
]

Related

How to draw two independent lines with recharts

Here is my data
const DATA = [
{
name: '0',
data: [
{x: "07/16/20 01:50", y: "0.397"},
{x: "07/16/20 02:51", y: "0.480"},
{x: "07/16/20 02:52", y: "0.416"},
{x: "07/16/20 02:53", y: "0.396"},
{x: "07/16/20 02:54", y: "0.418"},
{x: "07/16/20 02:55", y: "0.390"}
]
},
{
name: '1',
data: [
{x: "07/16/20 04:54", y: "0.384"},
{x: "07/16/20 05:57", y: "0.432"}
],
}
]
I am trying to plot these points but failing.
In your data structure, you need to have the general array of data objects only. Here, you are trying to have sub data arrays, that's probably why the graphs won't display.
I assumed you wanted to have a simple line graph, so tweaking your data array, it could result into this:
const customData = [
{x: "07/16/20 01:50", y: "0.397"},
{x: "07/16/20 02:51", y: "0.480"},
{x: "07/16/20 02:52", y: "0.416"},
{x: "07/16/20 02:53", y: "0.396"},
{x: "07/16/20 02:54", y: "0.418"},
{x: "07/16/20 02:55", y: "0.390"},
{x: "07/16/20 04:54", y2: "0.384"},
{x: "07/16/20 05:57", y2: "0.432"}
]
Where x is the label to use on the XAxis, y the data for name: '0' in your data structure, and y2 for name: '1'.
The resulted graph would look like this in the code, where there would be two distinct lines; one for the y1 values, and the other for the y2 values.
export default function App() {
return (
<LineChart
width={500}
height={300}
data={customData}
>
<XAxis dataKey="x" />
<YAxis />
<Line
type="monotone"
dataKey="y"
stroke="#8884d8"
activeDot={{ r: 8 }}
/>
<Line
type="monotone"
dataKey="y2"
stroke="#8884d8"
activeDot={{ r: 8 }}
/>
</LineChart>
);
}

Plotly React keep zoom and rotation between re-rendering

I'm using the React version of plot.ly to render a 3D scatter plot, but every time I re-render my component, the plot gets reset to its default configuration.
How can I prevent this, and keep the zoom/rotation configuration?
Below is a minimal code example. To re-iterate, how can I save the zoom and rotation, and how can I set it on the plot?
setPlotData() {
const points = {
1: {x: 1, y: 1, z: 1},
2: {x: 2, y: 1, z: 1},
3: {x: 3, y: 2, z: 1}
}
const x=[], y=[], z=[]
Object.keys(points).forEach((key, index) => {
x.push(points[key].x); y.push(points[key].y); z.push(points[key].z)
})
const data1 = {
x: x, y: y, z: z,
mode: "markers",
marker: {
color: "rgb(16, 52, 166)",
size: 4,
symbol: "circle",
opacity: 1
},
type: "scatter3d"
}
this.setState({
scatterPlotData: [data1]
})
}
render() {
return(
<Plot
data={this.state.scatterPlotData}
layout={{
autosize: true,
l: 0, r: 0, b: 0, t: 0, pad: 0,
showlegend: false,
margin:{l:0,r:0,b:0,t:0}
}}
style={{ width: '100%', height: '100%' }}
/>
)
}
Update the layout to add uirevision parameter
layout={{
autosize: true,
l: 0, r: 0, b: 0, t: 0, pad: 0,
showlegend: false,
margin:{l:0,r:0,b:0,t:0},
xaxis: {
uirevision: 'time',
},
yaxis: {
uirevision: 'time',
},
}}
you can change the uirevision: "time" to whatever x,y axis parameters you use

React Grid Layout - Grid Item shown on screen even though not within layout

I am using react-grid-layout to try to make a resizable grid. I also tried adding the functionality to remove grid items. However, upon removal of grid item (which in actual fact just removes that item from the layout object passed in, the grid item would then change to the smallest size possible, but still stay on the screen. Is there any reason for this? enter image description here
Before removing from layout
After removing from layout
Here is the layout object:
before
{ i: 'card', x: 0, y: 0, w: 5, h: 8, minH: 8, },
{ i: 'calendar', x: 0, y: 8, w: 5, h: 25 },
{ i: 'forecast', x: 5, y: 0, w: 5, h: 18 },
{ i: 'workflow', x: 5, y: 18, w: 2, h: 15 },
{ i: 'activities', x: 7, y: 18, w: 3, h: 15 },
after removing
{ i: 'calendar', x: 0, y: 8, w: 5, h: 25 },
{ i: 'forecast', x: 5, y: 0, w: 5, h: 18 },
{ i: 'workflow', x: 5, y: 18, w: 2, h: 15 },
{ i: 'activities', x: 7, y: 18, w: 3, h: 15 },
after removing and when onLayoutChange is called
{ i: 'card', x: 0, y: 0, w: 1, h: 1 },
{ i: 'calendar', x: 0, y: 1, w: 5, h: 25 },
{ i: 'forecast', x: 5, y: 0, w: 5, h: 18 },
{ i: 'workflow', x: 5, y: 18, w: 2, h: 15 },
{ i: 'activities', x: 7, y: 18, w: 3, h: 15 },
Why is it that the removed grid item still appears on the screen? I removed it onClick of the 'X' button, by removing that grid item from the layout object, however, right after it is removed, the onLayoutChange method is called, and it adds that 'card' back into the layout object, just with the smallest size. Is there any reason for this? I am new to using react-grid-layout, do let me know if I did anything wrong!
Here is my code for the grid
const layout = useSelector(state => state.layout.project.pre_layout)
// this layout is the layout object shown above, taken from redux store
const onLayoutChange = (layout, layouts) => {
console.log(layout);
console.log(layouts);
dispatch({ type: "LAYOUT_ONCHANGE", layout: layouts, page: 'project' })
// this dispatch updates the redux store with the new layout
}
<ResponsiveGridLayout className="layout" layouts={layout}
onLayoutChange={(layout, layouts) =>
onLayoutChange(layout, layouts)
}
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
rowHeight={row_height}
compactType={'vertical'}
preventCollision={false}>
/* content here */
</ResponsiveGridLayout>
Thanks all
Bit late but I've just encountered this myself so figured I'd put my findings!
If you just remove the layout details for an item but leave it in the content - it'll stay on the grid but reset back to default position and dimension.
To remove an item completely you'll need to remove it from both the layout and the content. Content being whatever you're displaying in /* content here */

Rendering vector-tiles using Mapbox using react-mapbox-gl

I have a geoJSON file that I convert into vector.tiles using this npm package.
I use const tileIndex = geojsonvt(geoJSON). The geoJSON file has the following format and it gets converted without any error.
const geoJSON = {
type: 'FeatureCollection',
crs: {
type: 'name',
properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84' }
},
features: [
{
properties: [Object],
geometry: [Object],
type: 'Feature',
_id: '5ed7b221a61a4b2970433932'
},
... 1840 more items
]
}
The result (geoJSON vector-tiles) that I get after conversion is following -
const tiles = {
options: {},
tiles: {
'0': {
features: [Array],
numPoints: 540529,
numSimplified: 3,
numFeatures: 1940,
source: null,
x: 0,
y: 0,
z: 0,
transformed: false,
minX: 0.5162953202777778,
minY: 0.316725863688461,
maxX: 0.5338655772222223,
maxY: 0.34955196703359503
},
'1': { ... }
},
tileCoords: [
{ z: 0, x: 0, y: 0 }, { z: 1, x: 1, y: 1 },
{ z: 1, x: 1, y: 0 }, { z: 2, x: 3, y: 1 },
{ z: 2, x: 3, y: 0 }, { z: 2, x: 2, y: 1 },
{ z: 3, x: 5, y: 3 }, { z: 3, x: 5, y: 2 },
{ z: 3, x: 4, y: 3 }, { z: 3, x: 4, y: 2 },
{ z: 4, x: 9, y: 5 }, { z: 4, x: 9, y: 4 },
{ z: 4, x: 8, y: 5 }, { z: 5, x: 17, y: 11 },
{ z: 5, x: 17, y: 10 }, { z: 5, x: 16, y: 11 },
{ z: 5, x: 16, y: 10 }, { z: 4, x: 8, y: 4 },
{ z: 2, x: 2, y: 0 }, { z: 1, x: 0, y: 1 },
{ z: 1, x: 0, y: 0 }
]
}
After converting a huge geoJSON file with 5000 layers into vector tiles, I am sending this data to the client-side wherein I render Map using React.js and Mapbox*. I use following to render the map but I have not been able to figure out what I am doing wrong. The error that I get says error: layers.jsx-layer-0: layer "jsx-layer-0" must specify a "source-layer"
<Source type="vector" tiles={data.tiles} >
<Layer {...dataLayer}/>
</Source>
I went through the documentation of Mapbox for the same but I'm unable to find what I am doing wrong. Any help would be of great help. Thank you very much.
react-mapbox-gl is in many places just a wrapper around mapbox-gl, and if you look at the documentation there:
https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#tiled-sources
You will see that the "tiles" property is only for url sources, where as the "url" property can be used to load a file with tiles:
"url": "http://api.example.com/tilejson.json"
The docs indicate that the source-layer is required field for vector layers.
That said, it certainly opaque as to how this works in a declarative api. Based on example, you might try this to see if it works -
...
const url = 'mapbox://mapbox.mapbox-terrain-v2'
const source = 'my-source';
<Source id={{source}} name={{source}} type="vector" url={url} tiles={data.tiles} >
<Layer source={{source}} {...dataLayer}/>
</Source>
...
rendering a layer with it source so you need to referrer to source id in layer + you need to add a source-layer prop like this:
<Source id='contours' type='vector' url='mapbox://mapbox.mapbox-terrain-v2' tileJsonSource={data.tiles}/>
<Layer
id='contours'
type='line'
source='contours'
source-layer='contour'
paint={{
'line-color': '#877b59',
'line-width': 1
}}
/>
</MapGL>;

myArray doesnt exist?

I am trying to initialise an array that holds 3 values, the x and y coordinates of a rectangle and whether or not it is visible on screen to do this i have written this code:
void rupee() {
int [] [] myArray = { {200, 110, 1}, {290, 110, 1}, {380, 200, 1}, {470, 110, 1}, {560, 110, 1}, {650, 200, 1}, {110, 200, 1}, {110, 290, 1}, {110, 380, 1}, {200, 470, 1}, {290, 560, 1}, {380, 650, 1}, {470, 560, 1}, {560, 470, 1}, {560, 470, 1}, {650, 380, 1}, {650, 290, 1} };
fill(0, 255, 0);
for (int i = 0; i<16; i++) {
for (int j = 0; j<3; j++) {
rect(myArray(i,i), myArray(j,j),50,50);
}
}
}
i am getting this error under both myArray"The function "myArray(int,int)" does not exist.
You are trying to access myArray with a wrong syntax. try myArray[i][j] ...

Resources