-
Data: 2014-08-04 11:38:41
Temat: Re: HTM5 - po co komu kanwa, jezeli nie dziala?
Od: "slawek" <h...@s...pl> szukaj wiadomości tego autora
[ pokaż wszystkie nagłówki ]Użytkownik "Pszemol" napisał w wiadomości grup
dyskusyjnych:lrm3c7$vkl$...@d...me...
>Podajcie link do witryny www - chetnie potestuje na Safari/iPhone4.
Na razie "NDA" odnośnie całości - za parę miesięcy będzie publikacja nt.
"Bardzo Poważnego Problemu" (nie-informatycznego) w jakimś peer reviewed coś
tam.
Jak ktoś chce, to może spróbować z samą grafiką: powinno (i na PC nawet to
robi) rysować wykresy XY nieco podobnie jak robi to Matlab. Jest tylko
rysowanie kolorowych linii (ciągłe, przerwane, ...), ale akurat to mi
wystarcza aż nadto. Kolejność ma znaczenie - wywołanie plot musi być po
axes.
vector1, vector2, ... to po prostu tablice liczb.
/**
* var plt = new Plot(canvas);
* plt.range('x',vector1,'y',vector2,'y',vector3, ... );
* plt.axes();
* plt.plot(vector1,vector2,'r-', vector1,vector2,'g-.', ... );
*/
function Plot(canvas) {
this.canvas = canvas;
this.xmin = null;
this.xmax = null;
this.xtic = null;
this.xmtic = null;
this.ymin = null;
this.ymax = null;
this.ytic = null;
this.ymtic = null;
this.fontSize = 12;
this.insetSize = 12;
this.font = this.fontSize + "px sans-serif";
this.text_extend =
this.canvas.getContext("2d").measureText("-1.23456")
.width;
this.margin_left = this.insetSize + this.text_extend;
this.margin_right = this.insetSize;
this.margin_top = this.insetSize;
this.margin_bottom = this.insetSize + this.fontSize;
this.ticSize = this.fontSize / 6;
this.width = this.canvas.width - this.margin_left - this.margin_right;
this.height = this.canvas.height - this.margin_top - this.margin_bottom;
this.fx = function (x) {
return ((x - this.xmin) / (this.xmax - this.xmin) * this.width);
}
this.fy = function (y) {
return ( - (y - this.ymin) / (this.ymax - this.ymin) * this.height);
}
this.prepareContext = function () {
var dc = this.canvas.getContext("2d");
dc.save();
dc.font = this.font;
dc.translate(0.5, 0.5);
dc.translate(this.margin_left, this.canvas.height - this.margin_bottom);
return dc;
}
this.releaseContext = function (dc) {
dc.restore();
}
}
Plot.prototype.axisStroke = function (dc) {
dc.strokeStyle = "#000";
dc.setLineDash([1, 0]);
dc.stroke();
}
Plot.prototype.gridStroke = function (dc, isNotMajorGrid) {
if (isNotMajorGrid) {
dc.strokeStyle = "#111";
dc.setLineDash([1, 2]);
} else {
dc.strokeStyle = "#222";
dc.setLineDash([2, 2]);
}
dc.stroke();
}
Plot.prototype.plotStroke = function (dc, lineStyle) {
if (lineStyle.search("r") != (-1))
dc.strokeStyle = "#f00";
else if (lineStyle.search("g") != (-1))
dc.strokeStyle = "#070";
else if (lineStyle.search("b") != (-1))
dc.strokeStyle = "#007";
else
dc.strokeStyle = "#000";
if (lineStyle.search("--") != (-1))
dc.setLineDash([12, 4]);
else if (lineStyle.search("-.") != (-1))
dc.setLineDash([12, 4, 4, 4]);
else if (lineStyle.search("-") != (-1))
dc.setLineDash([16, 0]);
else if (lineStyle.search(":") != (-1))
dc.setLineDash([4, 4]);
dc.stroke();
}
Plot.prototype.binsize = function (min_value, max_value, sections) {
var bin;
var factors = [1.0, 2.0, 2.5, 4.0, 5.0, 10.0];
var mtictab = [5, 4, 5, 4, 5, 5];
var delta = (max_value - min_value) / sections;
var magnitude = Math.floor(Math.log(delta) / Math.LN10);
var base = Math.exp(magnitude * Math.LN10);
var i = 0;
do {
bin = base * factors[i];
mtic = mtictab[i];
i++;
} while (i < factors.length && bin < delta)
var lo = Math.floor(min_value / bin) * bin;
var hi = Math.ceil(max_value / bin) * bin;
return {
bin : bin,
lo : lo,
hi : hi,
mtic : mtic
};
}
Plot.prototype.range = function (name1, vector1) {
var i = 0;
while (i < arguments.length) {
var name = arguments[i++];
var vector = arguments[i++];
var vector_min = Math.min.apply(Math, vector);
var vector_max = Math.max.apply(Math, vector);
switch (name) {
case 'x':
case 'X':
this.xmin = (this.xmin !== null) ? Math.min(this.xmin, vector_min) :
vector_min;
this.xmax = (this.xmax !== null) ? Math.max(this.xmax, vector_max) :
vector_max;
break;
case 'y':
case 'Y':
this.ymin = (this.ymin !== null) ? Math.min(this.ymin, vector_min) :
vector_min;
this.ymax = (this.ymax !== null) ? Math.max(this.ymax, vector_max) :
vector_max;
break;
}
}
}
Plot.prototype.axes = function (xBins, yBins) {
xBins = xBins || 9;
yBins = yBins || 7;
var bx = this.binsize(this.xmin, this.xmax, xBins);
this.xtic = bx.bin;
this.xmin = bx.lo;
this.xmax = bx.hi;
this.xmtic = bx.mtic;
var by = this.binsize(this.ymin, this.ymax, yBins);
this.ytic = by.bin;
this.ymin = by.lo;
this.ymax = by.hi;
this.ymtic = by.mtic;
var dc = this.prepareContext();
dc.textBaseline = "top";
for (var k = 0, x = this.xmin; x <= this.xmax; k++, x += this.xtic /
this.xmtic) {
var i = this.fx(x);
if ((k % this.xmtic) == 0) {
if (x != this.xmin)
dc.textAlign = "center";
else
dc.textAlign = "left";
if (this.width - i < this.text_extend / 2)
dc.textAlign = "right";
if (Math.abs(x) < Number.EPSILON * Math.abs(this.xmax - this.xmin))
dc.fillText(Number(0).toExponential(2), i, this.ticSize);
else
dc.fillText(x.toExponential(2), i, this.ticSize);
}
dc.beginPath();
dc.moveTo(i, 0);
dc.lineTo(i, -this.height);
this.gridStroke(dc, k % this.xmtic);
dc.beginPath();
dc.moveTo(i, 0);
dc.lineTo(i, this.ticSize);
this.axisStroke(dc);
}
dc.textAlign = "right";
dc.textBaseline = "middle";
for (var k = 0, y = this.ymin; y <= this.ymax; k++, y += this.ytic /
this.ymtic) {
var j = this.fy(y);
if (k % this.ymtic == 0) {
if (Math.abs(y) < Number.EPSILON * Math.abs(this.ymax - this.ymin))
dc.fillText(Number(0).toExponential(2), -2 * this.ticSize, j);
else
dc.fillText(y.toExponential(2), -2 * this.ticSize, j);
}
dc.beginPath();
dc.moveTo(0, j);
dc.lineTo(this.width, j);
this.gridStroke(dc, k % this.ymtic);
dc.beginPath();
dc.moveTo(0, j);
dc.lineTo(-this.ticSize, j);
this.axisStroke(dc);
}
dc.beginPath();
dc.moveTo(0, 0);
dc.lineTo(0, -this.height);
this.axisStroke(dc);
dc.beginPath();
dc.moveTo(0, 0);
dc.lineTo(this.width, 0);
this.axisStroke(dc);
this.releaseContext(dc);
}
Plot.prototype.plot = function (xvector, yvector, lineStyle) {
var iargin = 0;
var nargin = arguments.length;
while (iargin < nargin) {
xvector = arguments[iargin++];
yvector = arguments[iargin++];
if (iargin < nargin && typeof(arguments[iargin]) == typeof(""))
lineStyle = arguments[iargin++];
else
lineStyle = "r-";
if (this.xmin === null || this.xmax === null)
this.range('x', xvector);
if (this.ymin === null || this.ymax === null)
this.range('y', yvector);
var dc = this.prepareContext();
dc.beginPath();
var i = this.fx(xvector[0]);
var j = this.fy(yvector[0]);
dc.moveTo(i, j);
for (k = 0; k < xvector.length; k++) {
i = this.fx(xvector[k]);
j = this.fy(yvector[k]);
dc.lineTo(i, j);
}
this.plotStroke(dc, lineStyle);
this.releaseContext(dc);
}
}
//EOF
Następne wpisy z tego wątku
- 04.08.14 12:15 firr
- 04.08.14 19:42 slawek
- 04.08.14 19:48 slawek
- 04.08.14 19:56 slawek
- 05.08.14 06:19 firr
- 05.08.14 07:42 slawek
- 05.08.14 11:26 firr
- 05.08.14 12:16 slawek
- 05.08.14 12:28 firr
- 05.08.14 13:12 slawek
- 05.08.14 13:33 R.e.m.e.K
- 05.08.14 15:05 firr
- 05.08.14 15:12 R.e.m.e.K
- 08.08.14 13:24 firr
- 08.08.14 13:46 R.e.m.e.K
Najnowsze wątki z tej grupy
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
- Ada 2022 Language Reference Manual to be Published by Springer
- Press Release - AEiC 2023, Ada-Europe Reliable Softw. Technol.
- Ada-Europe - AEiC 2023 early registration deadline approaching
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2023
- Ile cykli zajmuje mnożenie liczb 64-bitowych?
Najnowsze wątki
- 2024-06-10 wyobrazcie sobie ze
- 2024-06-10 malowanie samochodu
- 2024-06-10 News from Poland
- 2024-06-10 Czy na pewno będą CŁA na chińskie samochody?
- 2024-06-09 Dlaczego w Polsce sie nic nie udaje, na przykładzie niebieskiego lasera a teraz perskowitów
- 2024-06-09 Dlaczego w Polsce sie nic nie udaje, na przykładzie niebieskiego lasera a teraz perskowitów
- 2024-06-09 Wykrywanie przerwy w długim przewodzie zakopanym w ziemi.
- 2024-06-09 Czemu news.chmurka.nwt jest taki wolny?
- 2024-06-11 Funbox 3.0 zakres adresów DHCP
- 2024-06-11 Re: Funbox 3.0 zakres adresów DHCP
- 2024-06-09 Miernik szybkości netu
- 2024-06-11 Panele PV w pionie (prawie).
- 2024-06-11 czy ta grupa żyje?
- 2024-06-11 Warszawa => Senior React Native Developer <=
- 2024-06-11 Gdańsk => Kierownik Działu Spedycji Międzynarodowej <=