Javascript teechart - set min or max not working? - teechart

We have the following problem - no matter what we try, we can't set the minimum or maximum on our chart in javascript.
Chart1 = new Tee.Chart("canvas");
var a = new Tee.Area();
Chart1.addSeries(a);
a.data.values = values
a.data.x = times;
a.format.fill = "rgba(0,175,240,0.0)";
var aa = new Tee.Line();
Chart1.addSeries(aa);
aa.data.values = values
aa.data.x = times;
Chart1.getSeries(0).vertAxis = "right";
Chart1.getSeries(1).vertAxis = "right";
Chart1.axes.bottom.labels.dateFormat = "UTC:HH:MM:ss";
Chart1.axes.right.labels.decimals = 5;
Chart1.axes.right.grid.format.stroke.fill = "#191919";
Chart1.axes.right.labels.format.font.fill = "#ccc";
Chart1.axes.bottom.grid.format.stroke.fill = "#191919";
Chart1.axes.bottom.labels.format.font.fill = "#ccc";
Chart1.getSeries(0).format.gradient.visible = true;
Chart1.getSeries(0).format.gradient.colors = ["rgba(0,175,240,0.2)", "rgba(255,175,240,1)"];
Chart1.getSeries(0).format.gradient.stops = [0, 1];
Chart1.getSeries(0).format.stroke.fill = "rgba(0,175,240,0)";
Chart1.getSeries(1).format.stroke.fill = "rgba(0,175,240,1)";
Chart1.getSeries(0).format.stroke.size = 0;
Chart1.getSeries(1).format.stroke.size = 2;
Chart1.title.visible = false;
Chart1.walls.back.visible = false;
Chart1.panel.transparent = true;
Chart1.legend.visible = false;
var maxValue = data[data.length - 1][0];
var minValue = data[0][0];
maxValue = maxValue + 1000 * 60 * 10;
maxValue = new Date(maxValue);
//Chart1.axes.bottom.setMinMax(minValue, maxValue);
Chart1.axes.bottom.maximum = maxValue;
Chart1.axes.bottom.minimum = minValue;
Chart1.draw();
The bottom axes contains dates and we are trying to add 10 minutes to the last date value and the set it as maximum and remove 10 minutes from the first date value and set it as minimum. We can't achieve that no matter what we try.

This seems to work fine for me here:
var tenMinutes = 1000 * 60 * 10;
var minValue = series1.minXValue();
var maxValue = series1.maxXValue();
minValue = minValue - tenMinutes;
maxValue = maxValue + tenMinutes;
Chart1.axes.bottom.setMinMax(minValue, maxValue);

Related

I am writing an app in threes for a set of particles, I want to include collision between the particles. It seems it only check for collisions once

It seems it only check for collisions once and particles loose speed. If anyone has an advice...
function animate() {
var elapsedTime = clock.getElapsedTime();
particlesGeometry.attributes.position.needsUpdate = true;
const paso = 1.5;
for (let i = 0; i < count; i++) {
const i3 = i * 3;var k = 0;
const x = particlesGeometry.attributes.position.array[i3 + 0];
const y = particlesGeometry.attributes.position.array[i3 + 1];
const z = particlesGeometry.attributes.position.array[i3 + 2];
for (let j=k; j < (count); j++){
const l = 3 * j;
if (l==i3){continue;}
var posx = x - particlesGeometry.attributes.position.array[l + 0];
var posy = y - particlesGeometry.attributes.position.array[l + 1];
var posz = z - particlesGeometry.attributes.position.array[l + 2];
var dist2 = Math.pow(posx,2)+Math.pow(posy,2)+Math.pow(posz,2);
var velMod1 = Math.sqrt(Math.pow(vel[l+0],2)+Math.pow(vel[l+1],2)+Math.pow(vel[l+2],2));
var velMod2 = Math.sqrt(Math.pow(vel[i3+0],2)+Math.pow(vel[i3+1],2)+Math.pow(vel[i3+2],2));
var erre = [posx, posy, posz];
var doterre = erre[0]*erre[0] + erre[1]*erre[1] + erre[2]*erre[2];
var doterreN = Math.sqrt(doterre);
var erreMod = [erre[0]/doterreN, erre[1]/doterreN, erre[2]/doterreN];
if (dist2 <=(velMod1+velMod2)*.05){
var proy1 = erreMod[0]*vel[l+0]+erreMod[1]*vel[l+1]+erreMod[2]*vel[l+2];
var proy2 = erreMod[0]*vel[i3+0]+erreMod[1]*vel[i3+1]+erreMod[2]*vel[i3+2];
vel[l + 0] = vel[l + 0] - proy1*erreMod[0];
vel[l + 1] = vel[l + 1] - proy1*erreMod[1];
vel[l + 2] = vel[l + 2] - proy1*erreMod[2];
vel[i3 + 0] = vel[i3 + 0] - proy2*erreMod[0];
vel[i3 + 1] = vel[i3 + 1] - proy2*erreMod[1];
vel[i3 + 2] = vel[i3 + 2] - proy2*erreMod[2];
particlesGeometry.attributes.color.array[i3+0] = 1;
particlesGeometry.attributes.color.array[i3+1] = 1;
particlesGeometry.attributes.color.array[i3+2] = 1;
particlesGeometry.attributes.color.array[l+0] = 1;
particlesGeometry.attributes.color.array[l+1] = 1;
particlesGeometry.attributes.color.array[l+2] = 1;
}
}
k++;
if (x>=0 || x<=-5){vel[i3+0]=-vel[i3+0]}
if (y>=5 || y<=-5){vel[i3+1]=-vel[i3+1]}
if (z>=5 || z<=-5){vel[i3+2]=-vel[i3+2]}
particlesGeometry.attributes.position.array[i3 + 0] = x + vel[i3+0]*paso;
particlesGeometry.attributes.position.array[i3 + 1] = y + vel[i3+1]*paso;
particlesGeometry.attributes.position.array[i3 + 2] = z + vel[i3+2]*paso;
}
Paso is the step. What I did was to invert the velocity component of the colliding particles along the vector that joins the particles. First I've tried with the dot function for dot product from mathjs but it was too slow so I've coded the dot products, mainly for normalization. The idea is the collision condition is checked for every pair of particles once.
dist2 <=(velMod1+velMod2)*.05
That means the square of the distance between particles must be less than or equal to the sum of their velocities times the step. That latter is in order to avoid particles to oscillate in the collision zone.
In order to check for collision events I've painted the particles that collided on white. The number of white particles should rise as time elapses but that is not the case when running the program.
particlesGeometry.attributes.color.array[i3+0] = 1;
particlesGeometry.attributes.color.array[i3+1] = 1;
particlesGeometry.attributes.color.array[i3+2] = 1;
particlesGeometry.attributes.color.array[l+0] = 1;
particlesGeometry.attributes.color.array[l+1] = 1;
particlesGeometry.attributes.color.array[l+2] = 1;
Thank you.
I've tried to write the double iteration in different forms, the same for the vector operations but the results were funny.

How to use FF_CONSTANT for Force feedback for Linux?

I am not able to utilize FF_CONSTANT force effect. My try code is:
struct ff_effect joy_effect_, joy_effect_2;
if (iwantconstantforce)
{
joy_effect_.id = -1;
joy_effect_.type = FF_CONSTANT;
joy_effect_.direction = 0x0000; // down
joy_effect_.replay.length = 100;
joy_effect_.replay.delay = 0;
joy_effect_.trigger.button = 0;
joy_effect_.trigger.interval = 100;
joy_effect_.u.constant.level = 65535;
joy_effect_.u.constant.envelope.attack_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.fade_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.attack_level = joy_effect_.u.constant.level / 10;
joy_effect_.u.constant.envelope.fade_level = joy_effect_.u.constant.level / 10;
}
I am able to produce FF_SPRING and FF_DAMPER effects with following codes.
if (youwantdampereffect)
{
joy_effect_.id = -1;
joy_effect_.direction = 0; // down
joy_effect_.type = FF_DAMPER;
joy_effect_.replay.length = 20;
joy_effect_.replay.delay = 0;
joy_effect_.u.condition[0].right_saturation = 65535;
joy_effect_.u.condition[0].left_saturation = 65535;
joy_effect_.u.condition[0].right_coeff = 65535 / 2;
joy_effect_.u.condition[0].left_coeff = 65535 / 2;
joy_effect_.u.condition[0].deadband = 0;
joy_effect_.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_); // upload the effect
}
if (youwantspringeffect)
{
joy_effect_2.id = -1;
joy_effect_2.direction = 0; // down
joy_effect_2.type = FF_SPRING;
joy_effect_2.replay.length = 20;
joy_effect_2.replay.delay = 0;
joy_effect_2.u.condition[0].right_saturation = 65535 / 2;
joy_effect_2.u.condition[0].left_saturation = 65535 / 2;
joy_effect_2.u.condition[0].right_coeff = 32767;
joy_effect_2.u.condition[0].left_coeff = 32767;
joy_effect_2.u.condition[0].deadband = 0;
joy_effect_2.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_2); // upload the effect
}
I do not find any info about what is constant force effect feels like or when it makes sense to use it.
Can somebody brief its importance and usage?
Thanks :)

Slickgrid paging issue for search - page number is wrong when pagesize = search item count on second page

If I do a search on a page greater than 1 and if the number of items returned from the search are equal to the pagesize then the page does not flip back to the previous page and says the wrong page number.
For example if I have 5 items and the page size is set to 4. If I do a search on the second page that returns 4 items then the page won't flip back to page 1 and the grid says Page 2 of 1.
I also get the same error if I change example4 -
http://mleibman.github.io/SlickGrid/examples/example4-model.html
Replace this code -
for (var i = 0; i < 50000; i++) {
var d = (data[i] = {});
d["id"] = "id_" + i;
d["num"] = i;
d["title"] = "Task " + i;
d["duration"] = "5 days";
d["percentComplete"] = Math.round(Math.random() * 100);
d["start"] = "01/01/2009";
d["finish"] = "01/05/2009";
d["effortDriven"] = (i % 5 == 0);
}
with this -
var x;
for (var i = 0; i < 5; i++) {
var d = (data[i] = {});
if (i == 0)
x = "1";
if (i == 1)
x = "11";
if (i == 2)
x = "111";
if (i == 3)
x = "1111";
if (i == 4)
x = "2";
d["id"] = "id_" + i;
d["num"] = i;
d["title"] = "Task " + x;
d["duration"] = "5 days";
d["percentComplete"] = Math.round(Math.random() * 100);
d["start"] = "01/01/2009";
d["finish"] = "01/05/2009";
d["effortDriven"] = (i % 5 == 0);
}
Add this line -
dataView.setPagingOptions({pageSize: 4});
Go to page 2 and search for Task 1. It should say Showing Page 2 of 1.
I think your rowCount was not updated. Have you added this on your script?
dataView.onRowCountChanged.subscribe(function (e, args) {
grid.updateRowCount();
grid.render();
});
dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
Update: Add this code on your slick.dataview.js. Find this around line 750
var paged;
if (pagesize) {
if (filteredItems.length < pagenum * pagesize) {
pagenum = Math.floor(filteredItems.length / pagesize);
}
//.. add this code
// START
if (filteredItems.length == pagenum * pagesize && pagenum > 0)
pagenum --;
// END
paged = filteredItems.slice(pagesize * pagenum, pagesize * pagenum + pagesize);
} else {
paged = filteredItems;
}

actionscript 2: pick 3 random nummers from array

i need 3 random variables from array 0-36 (roulette).
i have this code. script return first 3 nummers from random array.
i need return 3 random nummers (from random position) from random array.
help me please.
onClipEvent (load) {
// field 0-36
var rands = [];
for (var i = 0; i < 36; ++i)
{
rands[i] = i;
}
// random sorting array
rands.sort(function(a,b) {return random(3)-1;});
// final variables 1,2,3
random1 = rands[0];
random2 = rands[1];
random3 = rands[2];
}
this is possible code for 1 variable, i need convert this to 3 variables in AS2
n = 3;
for (var i:Number = 0; i < n; i++) {
var randomSelection = Math.floor((Math.random() * rands.length));
trace("Selected: " + rands[randomSelection]);
}
It's not 100% clear from your question what you want, but this is my guess:
var n = 3;
var random = [];
for (var i:Number = 0; i < n; i++) {
// Store the random selections in an array
random.push(Math.floor(Math.random() * rands.length));
}
// You could assign them to variables or access directly via array
var random1 = random[0];
var random2 = random[1];
var random3 = random[2];

modifying the lengthY of some cubes is slow

I want to write a 3d version of a fft. (Like this:https://wiki.mozilla.org/File:Fft.png)
So I created a few bars and in an outside function, my first aproach was to set the lengthY to a value. Then I call bar.modified() to force it to be repainted.
If I now use more than 50 bars, it is horrible slow (on my 4 core CPU). I guess there's a better way to do it, right?
Source:
var elements = new Array();
create3d = function(len) {
var r = new X.renderer3D();
r.init();
if(a.length == 0){
for ( var y = 0; y < len; y++) {
var c = new X.cube();
a.push(c);
}
}
for ( var i = 0; i < len; i++) {
a[i].center = [i*2 , 0, 0];
a[i].lengthX = 1;
a[i].lengthY = 20;
a[i].lengthZ = 1;
a[i].color = [i%2,0,0];
r.add(a[i]);
}
r.render();
};
function setVal(index,val){
var element = a[index];
element.lengthY = val;
element.modified();
}
I created a JSFiddle on how to do that and it is pretty fast for 1000 cubes
http://jsfiddle.net/haehn/6fVRC/

Resources