I tried to make a default map parameter but it just goes errors for some reason,
var size = {
"width": 1920,
"height": 1080,
};
class MyClass {
myFunction([String MyParam = "Sup!", Map background_size = size]) async {
return background_size.width;
}
}
It only gives me an errors like this The default value of an optional parameter must be constant. Can someone tell me which lines I type wrong?
Solution 1
Define size as const
const size = {
"width": 1920,
"height": 1080,
};
class MyClass {
myFunction([String MyParam = "Sup!", Map background_size = size]) async {
return background_size.width;
}
}
Solution 2
Set value if background_size is not set
var size = {
"width": 1920,
"height": 1080,
};
class MyClass {
myFunction([String MyParam = "Sup!", Map? background_size]) async {
final _background_size = background_size ?? size;
return _background_size.width;
}
}
Related
Attempting to assign a click event to a scatter plot point through Highcharts.net wrapper. The event appears in the javascript output but never fires when a point is clicked. The chart renders well, it is interactive, zooms, hovers, etc. Everything works except the click event. I have tried the click event in both the PlotOptionsSeries location and in the ScatterSeries location.
var chartOptions = new Highsoft.Web.Mvc.Charts.Highcharts
{
Chart = new Highsoft.Web.Mvc.Charts.Chart
{
SpacingTop = 20,
SpacingBottom = 20,
SpacingLeft = 20,
SpacingRight = 20,
ZoomType = Highsoft.Web.Mvc.Charts.ChartZoomType.Xy
},
XAxis = new List<Highsoft.Web.Mvc.Charts.XAxis>
{
new Highsoft.Web.Mvc.Charts.XAxis
{ Max = 150, Min = -150,GridLineWidth = 1, TickInterval = 50,
PlotLines = new List<Highsoft.Web.Mvc.Charts.XAxisPlotLines> { new Highsoft.Web.Mvc.Charts.XAxisPlotLines { Value = 0, Width = 2, ZIndex = 5 } }
}
},
YAxis = new List<Highsoft.Web.Mvc.Charts.YAxis>
{
new Highsoft.Web.Mvc.Charts.YAxis
{
Title = new Highsoft.Web.Mvc.Charts.YAxisTitle { Text = "" },
Max = 150, Min = -150, GridLineWidth = 1, TickInterval = 50,
PlotLines = new List<Highsoft.Web.Mvc.Charts.YAxisPlotLines> { new Highsoft.Web.Mvc.Charts.YAxisPlotLines { Value = 0, Width = 2, ZIndex = 5 } }
}
},
PlotOptions = new Highsoft.Web.Mvc.Charts.PlotOptions
{
Series = new Highsoft.Web.Mvc.Charts.PlotOptionsSeries
{
AllowPointSelect = true,
},
Scatter = new Highsoft.Web.Mvc.Charts.PlotOptionsScatter
{
Marker = new Highsoft.Web.Mvc.Charts.PlotOptionsScatterMarker
{
Radius = 5,
States = new Highsoft.Web.Mvc.Charts.PlotOptionsScatterMarkerStates
{
Hover = new Highsoft.Web.Mvc.Charts.PlotOptionsScatterMarkerStatesHover
{
Enabled = true,
LineColor = "rgb(100,100,100)"
}
}
},
States = new Highsoft.Web.Mvc.Charts.PlotOptionsScatterStates
{
Hover = new Highsoft.Web.Mvc.Charts.PlotOptionsScatterStatesHover
{ }
}
}
},
Series = new List<Highsoft.Web.Mvc.Charts.Series>
{
new Highsoft.Web.Mvc.Charts.ScatterSeries
{
Name = "Dots",
Color = "rgba(223, 83, 83, .5)",
Data = pts3, // Here we put the dbase data into the chart
ZIndex = 6,
Events = new Highsoft.Web.Mvc.Charts.ScatterSeriesEvents
{
Click = "function () {alert('Clicked');console.log('Clicked');}"
},
Tooltip = new Highsoft.Web.Mvc.Charts.ScatterSeriesTooltip
{
HeaderFormat = "",
PointFormat = "<h5>{point.name}<br /></h5>"+"<b>Love It:</b>{point.x} " +
"<b>Challenge:</b>{point.y}",
FooterFormat = "",
FollowPointer = true
}
}
}
};
chartOptions.ID = "teachaggchart";
var renderer = new Highsoft.Web.Mvc.Charts.Rendering.HighchartsRenderer(chartOptions);
It seems that you have found a bug in the wrapper.
I already reported it and it is fixed in new version (8.0.0.2) which should be available now.
How to get the newest version you can find here: http://dotnet.highcharts.com/Highcharts/Demo/Docs?section=UpgradeToStandard
Let me know whether it works in the new version.
I recently began to learn Konva-JS... please help me :)
<script>
var width = window.innerWidth;
var height = window.innerHeight;
function loadImages(sources, callback) {
var assetDir = '/assets/';
var images = {};
var loadedImages = 0;
var numImages = 0;
for(var src in sources) {
numImages++;
}
for(var src in sources) {
images[src] = new Image();
images[src].onload = function() {
if(++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = assetDir + sources[src];
}
}
function isNearOutline(animal, outline) {
var a = animal;
var o = outline;
var ax = a.getX();
var ay = a.getY();
if(ax > o.x - 20 && ax < o.x + 20 && ay > o.y - 20 && ay < o.y + 20) {
return true;
}
else {
return false;
}
}
function drawBackground(background, beachImg, text) {
var context = background.getContext();
context.drawImage(beachImg, 0, 0);
context.setAttr('font', '20pt Calibri');
context.setAttr('textAlign', 'center');
context.setAttr('fillStyle', 'white');
context.fillText(text, background.getStage().getWidth() / 2, 40);
}
function initStage(images) {
var stage = new Konva.Stage({
container: 'container',
width: 578,
height: 530
});
var background = new Konva.Layer();
var animalLayer = new Konva.Layer();
var animalShapes = [];
var score = 0;
// image positions
var animals = {
snake: {
x: 10,
y: 70
},
giraffe: {
x: 90,
y: 70
},
monkey: {
x: 275,
y: 70
},
lion: {
x: 400,
y: 70
}
};
var outlines = {
snake_black: {
x: 275,
y: 350
},
giraffe_black: {
x: 390,
y: 250
},
monkey_black: {
x: 300,
y: 420
},
lion_black: {
x: 100,
y: 390
}
};
// create draggable animals
for(var key in animals) {
// anonymous function to induce scope
(function() {
var privKey = key;
var anim = animals[key];
var animal = new Konva.Image({
image: images[key],
x: anim.x,
y: anim.y,
draggable: true
});
animal.on('dragstart', function() {
this.moveToTop();
animalLayer.draw();
});
/*
* check if animal is in the right spot and
* snap into place if it is
*/
animal.on('dragend', function() {
var outline = outlines[privKey + '_black'];
if(!animal.inRightPlace && isNearOutline(animal, outline)) {
animal.position({
x : outline.x,
y : outline.y
});
animalLayer.draw();
animal.inRightPlace = true;
if(++score >= 4) {
var text = 'You win! Enjoy your booty!';
drawBackground(background, images.beach, text);
}
// disable drag and drop
setTimeout(function() {
animal.draggable(false);
}, 50);
}
});
// make animal glow on mouseover
animal.on('mouseover', function() {
animal.image(images[privKey + '_glow']);
animalLayer.draw();
document.body.style.cursor = 'pointer';
});
// return animal on mouseout
animal.on('mouseout', function() {
animal.image(images[privKey]);
animalLayer.draw();
document.body.style.cursor = 'default';
});
animal.on('dragmove', function() {
document.body.style.cursor = 'pointer';
});
animalLayer.add(animal);
animalShapes.push(animal);
})();
}
// create animal outlines
for(var key in outlines) {
// anonymous function to induce scope
(function() {
var imageObj = images[key];
var out = outlines[key];
var outline = new Konva.Image({
image: imageObj,
x: out.x,
y: out.y
});
animalLayer.add(outline);
})();
}
stage.add(background);
stage.add(animalLayer);
drawBackground(background, images.beach, 'Ahoy! Put the animals on the beach!');
}
var sources = {
beach: 'beach.png',
snake: 'snake.png',
snake_glow: 'snake-glow.png',
snake_black: 'snake-black.png',
lion: 'lion.png',
lion_glow: 'lion-glow.png',
lion_black: 'lion-black.png',
monkey: 'monkey.png',
monkey_glow: 'monkey-glow.png',
monkey_black: 'monkey-black.png',
giraffe: 'giraffe.png',
giraffe_glow: 'giraffe-glow.png',
giraffe_black: 'giraffe-black.png'
};
loadImages(sources, initStage);
</script>
as we can see in this example Animals_on_the_Beach_Game the animal's images are drag-able and can be drop ever where.... but I want to change it in the way that it just can drop on the specific place ... what can I do ?
thank you :)
This is more of a design question, as letting go of the mouse button isn't something you can prevent. It would also be non-intuitive to keep the image attached to the mouse position as you would then need a new mouse event to associate with dropping it. What I've done for a drag and drop UI was to either (1) destroy the dropped shape, or if that wasn't an option, (2) animate the shape back (i.e. snap back) to its original position. Alternatively, you might (3) find the closest likely valid drop target and snap to that location.
First you define lionOrigin, that maybe you already have.
You have to implement the call on the dragend event of the object dragged, so let's say the lion. You have to check position of the lion in relation to the end desired position, let's call it lionDestiny. That can be done with a simple grometry: calculate the distance between to point. We do that with distanceA2B() function.
Now you can establish an offset inside wich you can snap the object, as it is close enough. If the minimal offset is not achieved, then you place the lion back on lionOrigin.
Al last, in konvajs you can use .x() and .y() to easily get or set position to lion.
Something like this:
var lionOrigin = [50,50];
var lionDestiny = [200,200];
var offset = 20;
distanceA2B(a,b) {
return Math.sqrt( ((a[0]-b[0])*(a[0]-b[0])) + ((a[1]-b[1])*(a[1]-b[1])) );
}
lion.on('dragend', (e) => {
var d = distanceA2B([lion.x(),lion.y()],lionDestiny);
if(d<offset){
lion.x(lionDestiny[0]);
lion.y(lionDestiny[1]);
}else{
lion.x(lionOrigin[0]);
lion.y(lionOrigin[1]);
}
});
Hope this helps!
It would have been better if you could explain your question more when you say you want to move any shape to a specific position. Though konva.js provides you with various events through which you can do this. For example, suppose you want to interchange the location of two shapes when you drag and move the first shape to the second and drop it there. In this case, you can use dragend event of konva. So when you move the target element to another element and drop it there, check if they are intersecting each other or not and then interchange their coordinates with each other.
Here is the function to find the intersection between two elements:
haveIntersection(r1, r2) {
return !(
r2.x > r1.x + r1.width ||
r2.x + r2.width < r1.x ||
r2.y > r1.y + r1.height ||
r2.y + r2.height < r1.y
);
}
And from here, you can try to understand the functionality. Though it's in nuxt.js but the events and scripts would be almost same if you are using only javascript. You can find sample code with an explanation for replacing the location of two shapes with each other. So even if you don't want to replace the locations but you want to move your target element to any position this will make you understand how to do this.
i dont know how copyteximage2D works,
i would like a explanation in term of the webgl state machine :
thanks to gman i have this :
gl = {
activeTextureUnit: 0,
textureUnits: [],
};
gl.activeTexture = function(unit) {
this.activeTextureUnit = unit - this.TEXTURE_0;
};
gl.bindTexture = function(bindPoint, texture) {
var textureUnit = this.textureUnits[this.activeTextureUnit];
switch (bindPoint) {
case this.TEXTURE_2D:
textureUnit.texture2D = texture;
break;
case ....
}
};
gl.copyTexImage2D = function( target, level, iformat, x, y, w,h,b) {
.....
..... gman please your code here thanks very much!!!
.....
}
copyTexImage2D copies from the current framebuffer or canvas into the given target of the current texture unit
gl = {
activeTextureUnit: 0,
textureUnits: [
{ gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
{ gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
{ gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
{ gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
...
],
framebufferBindPoints: {
gl.FRAMEBUFFER: gl.canvas.internalFramebuffer,
},
};
gl.bindFramebuffer = function(bindPoint, framebuffer) {
this.framebufferBindPoints[bindPoint] =
framebuffer ? framebuffer : gl.canvas.internalFramebuffer;
};
gl.copyTexImage2D = function( target, level, iformat, x, y, w,h,b) {
var textureUnit = this.textureUnits[this.activeTextureUnit];
var texture = textureUnit[target];
var framebuffer = this.framebufferBindPoints[gl.FRAMEBUFFER];
// copy from framebuffer into texture
}
My question is related to Filipe Figueiredo's query (see: Blackberry 10 Cascades - Images inside Text Area)
My Cascades BB10 App requires a search-ahead drop-down with the ability to have multiple items selected and displayed as Tag Fields. Look & feel and behavior same as BB10 email composer's "To" address field - but with different data (e.g. country names).
Questions:
Is there a way to do this using Cascades components / controls?
(FlowListLayout does not meet exact requirements)
Can we achieve this using QML + javascript?
Or is there a way using C++ and QML for achieving this?
Is there a Component market Place for procuring custom controls for Cascades?
My development is stalled. Please help.
It should be possible. This is a prototype. It doesn't work well, but it's an idea. This is how it looks:
Code (yeah, it's bad. but it should work out of the box):
import bb.cascades 1.2
Page {
Container {
ListView {
id: tagList
dataModel: tagModel
layout: FlowListLayout {
headerMode: ListHeaderMode.None
}
preferredHeight: 200
function itemType(data, indexPath) {
return (data.add == 1 ? 'add' : '');
}
function mload(text) {
myList.load(text);
}
function showDropDown() {
myList.visible = true;
}
listItemComponents: [
ListItemComponent {
type: "add"
Container {
id: myAdd
TextField {
id: searchBox
preferredWidth: 300
onTextChanging: {
myAdd.ListItem.view.mload(searchBox.text);
}
onFocusedChanged: {
if (focused)
myAdd.ListItem.view.showDropDown();
}
}
}
},
ListItemComponent {
Container {
background: Color.create("#660000FF")
leftPadding: 10
rightPadding: 10
topPadding: 10
bottomPadding: 10
leftMargin: 10
bottomMargin: 10
Label {
id: country
textStyle.fontSize: FontSize.Medium
text: ListItemData.country
}
}
}
]
onTriggered: {
//todo: make it possible to remove a tag
console.log("item touched.. yay!")
}
attachedObjects: [
ArrayDataModel {
id: tagModel
}
]
}
ListView {
id: myList
visible: false
dataModel: mdataModel
preferredHeight: 400
attachedObjects: [
ArrayDataModel {
id: mdataModel
}
]
onTriggered: {
var selected = dataModel.data(indexPath);
var tmp = new Object();
tmp.country = selected;
tagModel.insert(tagModel.size() - 1, tmp);
console.log("removing: " + (tagModel.size() - 1 ) + " at size " + tagModel.size())
visible = false;
}
function load(text) {
var cities = [ "Slovenia", "Italy", "Slovakia", "Croatia", "Sweden", "Norway", "Poland", "Finland", "Spain",
"Indonesia", "Ireland" ]
var tmp = [];
for (var i = 0; i < cities.length; i ++)
if (cities[i].toLowerCase().indexOf(text.toLowerCase()) >= 0)
tmp.push(cities[i]);
mdataModel.clear();
mdataModel.insert(0, tmp);
}
function insertEdit() {
var edit = new Object();
edit["add"] = "1";
tagModel.insert(tagModel.size(), edit);
}
}
}
onCreationCompleted: {
myList.load("");
myList.insertEdit(); // insert item with TextField
}
}
Trying to get the space bar to do an action in ActionScript.
Here is bits of the code that are relative.
var space:Boolean = false;
.
stage.addEventListener(KeyboardEvent.SPACE, kSpace);
.
function kSpace(e:KeyboardEvent)
{
if (e.keyCode == 40)
{
down = false;
}
if (e.keyCode == 38)
{
up = false;
}
if (e.keyCode == 32)
{
shoot = true;
}
}
function shootBullet()
{
var bullet1:bullet = new bullet();
bullet1.x = ship.x + ship.height / 2;
bullet1.y = ship.y;
bulletContainer.addChild(bullet1);
}
Getting the error Scene 1, Layer 'Actions', Frame 2, Line 17 1119: Access of possibly undefined property SPACE through a reference with static type Class.
Line 17 being stage.addEventListener(KeyboardEvent.SPACE, kSpace);
Would love to get this sorted :)
KeyboardEvent.SPACE is not an event. Try listening to either KeyboardEvent.KEY_DOWN or KeyboardEvent.KEY_UP