Can i use source item values in radListView.itemTemplates - nativescript

I am creating an array of radListView im my page and for each radList, i implement one "radListView.itemTemplates" as follow:
radListView.itemTemplates = [
{
key: "notaBaixa",
createView: () => {
const gridLayout = new GridLayout();
gridLayout.addColumn(new ItemSpec(1, GridUnitType.STAR));
gridLayout.addColumn(new ItemSpec(1, GridUnitType.AUTO));
gridLayout.addColumn(new ItemSpec(1, GridUnitType.AUTO));
gridLayout.verticalAlignment = "middle";
gridLayout.css = "border-bottom-width:1px; border-bottom-color:black;";
const lblDisciplina = new Label();
lblDisciplina.col = 0;
lblDisciplina.setInlineStyle("padding:10px 0 0 10px; height:60px;");
lblDisciplina.verticalAlignment = "middle";
lblDisciplina.text = "{{disciplina}}";
const lblnotaTotal = new Label();
lblnotaTotal.col = 1;
lblnotaTotal.setInlineStyle("padding:10px 0 0 10px; height:60px; color: red;");
lblnotaTotal.verticalAlignment = "middle";
lblnotaTotal.text = "{{nota_total}}";
const lblFaltasTotal = new Label();
lblFaltasTotal.col = 2;
lblFaltasTotal.setInlineStyle("padding:10px 0 0 10px; height:60px;");
lblFaltasTotal.verticalAlignment = "middle";
lblFaltasTotal.text = "{{faltas_total}}";
gridLayout.addChild(lblDisciplina);
gridLayout.addChild(lblnotaTotal);
gridLayout.addChild(lblFaltasTotal);
return gridLayout;
}
},
{
key: "notaAlta",
createView: () => {
const gridLayout = new GridLayout();
gridLayout.addColumn(new ItemSpec(1, GridUnitType.STAR));
gridLayout.addColumn(new ItemSpec(1, GridUnitType.AUTO));
gridLayout.addColumn(new ItemSpec(1, GridUnitType.AUTO));
gridLayout.verticalAlignment = "middle";
gridLayout.css = "border-bottom-width:1px; border-bottom-color:black;";
const lblDisciplina = new Label();
lblDisciplina.col = 0;
lblDisciplina.setInlineStyle("padding:10px 0 0 10px; height:60px;");
lblDisciplina.verticalAlignment = "middle";
lblDisciplina.text = "{{disciplina}}";
const lblnotaTotal = new Label();
lblnotaTotal.col = 1;
lblnotaTotal.setInlineStyle("padding:10px 0 0 10px; height:60px; color: blue;");
lblnotaTotal.verticalAlignment = "middle";
lblnotaTotal.text = "{{nota_total}}";
const lblFaltasTotal = new Label();
lblFaltasTotal.col = 2;
lblFaltasTotal.setInlineStyle("padding:10px 0 0 10px; height:60px;");
lblFaltasTotal.verticalAlignment = "middle";
lblFaltasTotal.text = "{{faltas_total}}";
gridLayout.addChild(lblDisciplina);
gridLayout.addChild(lblnotaTotal);
gridLayout.addChild(lblFaltasTotal);
return gridLayout;
}
}
];
As you can see, in my label i am trying get some property of source item but the label does not understand as property. how can i set the label text value as item source property ?

Please refer the data binding docs. The syntax you are using, is only valid on XML, the XML parser will interpret the syntax and initiate binding between the element and data model.
You have to call bind method on the target element and pass the source & target property to do the same programatically.
For example,
lblDisciplina.text = "{{disciplina}}";
Should be
lblDisciplina.bind({
sourceProperty: "disciplina",
targetProperty: "text",
twoWay: false
});

Related

Amcharts V4 mark values on series with known value

I have a amChart4 XYChart loaded from a CSV external file.
How to mark the max values on a serie, max values are known when writing the file. So just need to mark the data points with a bullet.
var maxNm = 404.24;
var maxHP = 327.7;
Se code with working chart loaded from CSV.
https://codepen.io/lasse-kofoed/pen/WNbNXxe
// Themes begin
am4core.useTheme(am4themes_material);
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.responsive.enabled = true;
// Set up data source
chart.dataSource.url = "https://master.tus.io/files/a6bfda6a8051313c0c0b1d7129a75786+DB7aQwWVBca.GAK4H6FLamUT58549Asv6vLoR9kEJySMEVOsFlCSi9eqzgMYLhqXdMJDZoTE0C90HuVUUKD7KoKdFjlM0f1IRkkQ0L5X6iykr8kSsyNWTtPkcmzIFwDp";
chart.dataSource.parser = new am4core.CSVParser();
chart.dataSource.parser.options.useColumnNames = true;
// Increase contrast by taking evey second color
chart.colors.step = 2;
chart.dataSource.events.on("error", function (ev) {
console.log("Oopsy! Something went wrong");
});
// Create value axis
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.title.text = "Power & Torque";
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Rpm";
// Create serie Nm
var nm = chart.series.push(new am4charts.LineSeries());
var maxNm = 404.24;
nm.dataFields.valueY = "Nm";
nm.dataFields.categoryX = "Rpm";
nm.yAxis = valueAxis;
nm.name = "Nm";
nm.strokeWidth = 1;
//nm.tensionX = 0.7;
nm.tooltipText = "{valueY.value} Nm";
var hp = chart.series.push(new am4charts.LineSeries());
var maxHP = 327.7;
hp.dataFields.valueY = "Hp";
hp.dataFields.categoryX = "Rpm";
hp.yAxis = valueAxis;
hp.name = "Hp";
hp.strokeWidth = 1;
//hp.tensionX = 0.7;
hp.tooltipText = "{valueY.value} Hp";
// Add legend
chart.legend = new am4charts.Legend();
// Add cursor
chart.cursor = new am4charts.XYCursor();
Updated a CodePen with the result.
https://codepen.io/lasse-kofoed/pen/eYmprPR
Found that using the event beforedatavalidated you can alter the data and set a field to false.
And then set propertyFields.disabled = true on a bullet object ( hides all bullets )
and .propertyFields.disabled to the field name that was added to the data list item ( show on bullets on values that have the field set to false )
chart.series.values[0].dataItem.values.valueY
Also found that the max and min values can be found here, but is not using that information in the example
// Add max Torque bullet
var maxTorque = nm.bullets.push(new am4charts.CircleBullet());
maxTorque.disabled = true;
maxTorque.propertyFields.disabled = "maxTorque";
maxTorque.radius = 8;
maxTorque.strokeWidth = 2;
maxTorque.stroke = am4core.color("#fff");
var maxTorqueLabel = nm.bullets.push(new am4charts.LabelBullet());
maxTorqueLabel.label.text = "Max torque\n[bold]{valueY} {name}#{categoryX}[/]";
maxTorqueLabel.disabled = true;
maxTorqueLabel.propertyFields.disabled = "maxTorque";
maxTorqueLabel.label.dy = -30;
// Add max Power bullet
var maxPower = hp.bullets.push(new am4charts.CircleBullet());
maxPower.disabled = true;
maxPower.propertyFields.disabled = "maxPower";
var maxPowerLabel = hp.bullets.push(new am4charts.LabelBullet());
maxPowerLabel.label.text = "Max power\n[bold]{valueY} {name}#{categoryX}[/]";
maxPowerLabel.disabled = true;
maxPowerLabel.propertyFields.disabled = "maxPower";
maxPowerLabel.label.dy = -30;
chart.events.on("beforedatavalidated", function(ev) {
var maxT = chart.data.find(x => x.Rpm === "5221");
var maxP = chart.data.find(x=> x.Rpm === "5888");
if(typeof maxT !== "undefined")
{
maxT.maxTorque = false;
}
if(typeof maxP !== "undefined")
{
maxP.maxPower = false;
}
});

ListView prevent auto scroll on item tapped?

Trying to figure out if I can disable the auto scroll that occurs when a user taps on a cell in a ListView (I'm using a Recycle List View if it matters). I'm already setting the sender.SelectedItem to null to disable the cell highlight.
gridList.ItemSelected += (s, e) => {
((Xamarin.Forms.ListView)s).SelectedItem = null;
};
UPDATE ItemTemplate Layout
headline = new Xamarin.Forms.Label();
cellImage = new Xamarin.Forms.Image();
LoadingText = new Xamarin.Forms.Label();
LoadingText.Text = "Loading...";
layout = new Xamarin.Forms.Grid();
layout.RowDefinitions.Add(new Xamarin.Forms.RowDefinition { Height = new Xamarin.Forms.GridLength(1, Xamarin.Forms.GridUnitType.Star) });
layout.ColumnDefinitions.Add(new Xamarin.Forms.ColumnDefinition { Width = new Xamarin.Forms.GridLength(1, Xamarin.Forms.GridUnitType.Star) });
layout.Children.Add(LoadingText, 0, 0);
layout.Children.Add(headline, 0, 0);
layout.Children.Add(cellImage, 0, 0);
layout.Children.Add(activityIndicator, 0, 0);
LoadingText.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
LoadingText.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
layout.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
layout.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
cellImage.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
cellImage.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
if(!hasLoadedAdAtLeastOnce)
{
AdView.Content.TranslationY = 5;
AdView.Content.TranslationX = -20;
hasLoadedAdAtLeastOnce = true;
}
cellImage.WidthRequest = 260;
cellImage.HeightRequest = 173;
_ad = (Controls.Ad)AdView.Content;
View = layout;

Trying to move a dynamic body in box2dweb on keypress

I have created a dynamic_body and I want to move that body using an EventListener.
But, I can't access the body and there is an issue with ApplyImpulse() or the ApplyForce() function in my code. But I can't see it. What am I missing?
function init() {
var b2Vec2 = Box2D.Common.Math.b2Vec2
, b2AABB = Box2D.Collision.b2AABB
, b2BodyDef = Box2D.Dynamics.b2BodyDef
, b2Body = Box2D.Dynamics.b2Body
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
, b2Fixture = Box2D.Dynamics.b2Fixture
, b2World = Box2D.Dynamics.b2World
, b2MassData = Box2D.Collision.Shapes.b2MassData
, b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
, b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
, b2DebugDraw = Box2D.Dynamics.b2DebugDraw
, b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef
;
var world = new b2World(
new b2Vec2(0, 0) //gravity
, true //allow sleep
);
var fixDef = new b2FixtureDef;
fixDef.density = 1.0;
fixDef.friction = 0.5;
fixDef.restitution = 0.2;
var bodyDef = new b2BodyDef;
//creating ground
bodyDef.type = b2Body.b2_staticBody;
fixDef.shape = new b2PolygonShape;
fixDef.shape.SetAsBox(20, 2);
bodyDef.position.Set(10, 500 / 30 + 1.8);
world.CreateBody(bodyDef).CreateFixture(fixDef);
bodyDef.position.Set(10, -1.8);
world.CreateBody(bodyDef).CreateFixture(fixDef);
fixDef.shape.SetAsBox(2, 14);
bodyDef.position.Set(-1.8, 13);
world.CreateBody(bodyDef).CreateFixture(fixDef);
bodyDef.position.Set(25, 13);
world.CreateBody(bodyDef).CreateFixture(fixDef);
// creating body
playerbody = new b2BodyDef;
playerbody.type = b2Body.b2_dynamicBody;
bodyfix = new b2FixtureDef;
bodyfix.shape = new b2PolygonShape;
bodyfix.shape.SetAsBox(
0.4 //half width
, 0.6 //half height
);
playerbody.position.x = 3.2;
playerbody.position.y = 14;
bodyfix.body = playerbody;
bodyA = world.CreateBody(playerbody).CreateFixture(bodyfix);
function aPressed() {
var direction = new b2Vec2(-5,0);
bodyA.ApplyImpulse( direction , bodyA.GetWorldCenter());
}
function dPressed() {
var direction = new b2Vec2(5,0);
bodyA.ApplyImpulse( direction , bodyA.GetWorldCenter());
}
function spacePressed() {
var direction = new b2Vec2(0,5);
bodyA.ApplyImpulse( direction , bodyA.GetWorldCenter());
}
function ctrlPressed(){
var direction = new b2Vec2(0,-2);
bodyA.ApplyImpulse( direction , bodyA.GetWorldCenter());
}
// keyboard controls
document.addEventListener('keypress',function(event) {
var keycode = event.keyCode;
switch (keycode){
case 65:
aPressed();
break;
case 68:
dPressed();
break;
case 32:
spacePressed();
break;
case 17:
ctrlPressed();
break;
}
},false);

Amchart with two lines

i have an amchart with two lines:
<script type="text/javascript">
var chart;
var graph;
var chartData2 = [
{"year":"2014-10-04 23:30:03", "v1":9.1, "v2":0},
{"year":"2014-10-04 23:45:02", "v1":8.8, "v2":86.2},
...
{"year":"2014-10-05 23:30:02", "v1":8.7, "v2":98.7},
{"year":"2014-10-05 23:45:02", "v1":8.5, "v2":98.7},
{"year":"2014-10-06 00:00:01", "v1":8.4, "v2":98.5},
{"year":"2014-10-06 00:15:02", "v1":8.5, "v2":98.3},
{"year":"2014-10-06 00:30:01", "v1":8.4, "v2":97.9}
];
AmCharts.ready(function () {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "../amcharts/images/";
chart.dataProvider = chartData2;
chart.marginLeft = 10;
chart.categoryField = "year";
chart.dataDateFormat = "JJ:NN:SS";
//chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true;
categoryAxis.minPeriod = "100";
categoryAxis.dashLength = 3;
categoryAxis.minorGridEnabled = true;
categoryAxis.minorGridAlpha = 0.1;
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.id = "ax1";
valueAxis.axisAlpha = 0;
valueAxis.inside = true;
valueAxis.dashLength = 3;
valueAxis.position = "right";
chart.addValueAxis(valueAxis);
var valueAxis2 = new AmCharts.ValueAxis();
valueAxis2.id = "ax2";
valueAxis2.axisAlpha = 0;
valueAxis2.inside = true;
valueAxis2.dashLength = 3;
valueAxis2.baseValue = -20;
valueAxis2.position = "left";
chart.addValueAxis(valueAxis2);
// GRAPH
graph = new AmCharts.AmGraph();
graph.valueaxis = "ax1";
graph.type = "smoothedLine";
graph.lineColor = "#d1655d";
graph.negativeLineColor = "#637bb6";
graph.bullet = "square";
graph.bulletSize = 8;
graph.bulletBorderColor = "#FFFFFF";
graph.bulletBorderAlpha = 1;
graph.bulletBorderThickness = 2;
graph.lineThickness = 2;
graph.valueField = "v1";
graph.title = "title v1";
graph.balloonText = "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>";
chart.addGraph(graph);
graph2 = new AmCharts.AmGraph();
graph2.valueAxis = "ax2";
graph2.type = "smoothedLine";
graph2.lineColor = "#d1655d";
graph2.negativeLineColor = "#637bb6";
graph2.bullet = "round";
graph2.bulletSize = 8;
graph2.bulletBorderColor = "#FFFFFF";
graph2.bulletBorderAlpha = 1;
graph2.bulletBorderThickness = 2;
graph2.lineThickness = 2;
graph2.valueField = "v2";
graph2.title = "title v2";
graph2.balloonText = "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>";
chart.addGraph(graph2);
// CURSOR
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorAlpha = 0;
chartCursor.cursorPosition = "mouse";
chartCursor.categoryBalloonDateFormat = "JJ:NN:SS";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chart.addChartScrollbar(chartScrollbar);
chart.creditsPosition = "bottom-right";
// WRITE
chart.write("chartdiv2");
});
I can see the x-and y-axis, but no lines with values. Can anyone please help me?
Two problems:
dataDateFormat is incorrect, should be: chart.dataDateFormat = "YYYY-MM-DD JJ:NN:SS";
minPeriod is incorrect, should be: categoryAxis.minPeriod = "ss";

Visifire.Charts How to disable vertical lines. WP

Chart is created by code. But I can't disable vertical lines in chart.
It is a code of creating chart:
public void CreateChart() {
CleanChart();
visiChart = new Chart()
{
ToolTipEnabled = true,
Width = 400,
Height = 200,
Padding = new Thickness(0),
Margin = new Thickness(0, 6, 0, -12),
Background = new SolidColorBrush(Colors.White),
};
ChartGrid grid = new ChartGrid()
{
Enabled = false
};
DataSeries dataSeries = new DataSeries();
DataPoint dataPoint;
Axis yAx = new Axis()
{
AxisLabels = new AxisLabels() { Enabled = false },
Grids = new ChartGridCollection() {grid}
};
int i = 0;
var deps = App.CurrentAgreement.Deposits.Deposit.Where(x => x.DepositIliv + x.DepositLink > 0).ToList();
foreach (var dep in deps) {
dataPoint = new DataPoint();
dataPoint.YValue = dep.DepositIliv + dep.DepositLink + dep.UValue + dep.WarrantyValue;
dataPoint.XValue = i;
i++;
dataPoint.LabelText = dataPoint.YValue.Out();
dataPoint.AxisXLabel = DateTime.Parse(dep.DepositDate).ToString("MMM yyyy");
dataPoint.MouseLeftButtonUp += dataPoint_MouseLeftButtonUp;
dataSeries.DataPoints.Add(dataPoint);
}
dataSeries.LabelEnabled = true;
dataSeries.RenderAs = RenderAs.Column;
dataSeries.Color = new SolidColorBrush(Colors.Green);
visiChart.Series.Add(dataSeries);
visiChart.AxesY.Add(yAx);
ChartPlaceHolder.Children.Add(visiChart);
}
But i dont need vertical lines visible. It is a screen of chart.
How i can disable lines??
Help me, please.
You have to disable the Grid lines from AxisX also.
Example:
ChartGrid grid = new ChartGrid()
{
Enabled = false
};
Axis xAx = new Axis();
xAx.Grids.Add(grid);
visiChart.AxesX.Add(xAx);

Resources