Highcharts Animation - animation

Is there anyway to animate each and every bubble in bubble charts one by one, from left to right and the size of the bubbles will initially be either smaller or larger and then it should grow to the actual size. Any ideas to proceed further with this requirement is highly appreciated.
/**
* A Highcharts plugin to display the tooltip in a separate container outside the chart's
* bounding box, so that it can utilize all space available in the page.
*/
(function(H) {
H.wrap(H.Tooltip.prototype, 'getLabel', function(proceed) {
var chart = this.chart,
options = this.options,
chartRenderer = chart.renderer,
box;
if (!this.label) {
this.renderer = new H.Renderer(document.body, 400, 500);
box = this.renderer.boxWrapper;
box.css({
position: 'absolute',
top: '-9999px'
});
chart.renderer = this.renderer;
proceed.call(this, chart, options);
chart.renderer = chartRenderer;
this.label.attr({
x: 0,
y: 0
});
this.label.xSetter = function(value) {
box.element.style.left = value + 'px';
};
this.label.ySetter = function(value) {
box.element.style.top = value + 'px';
};
}
return this.label;
});
H.wrap(H.Tooltip.prototype, 'getPosition', function(proceed, boxWidth, boxHeight, point) {
var chart = this.chart,
chartWidth = chart.chartWidth,
chartHeight = chart.chartHeight,
pos;
point.plotX += this.chart.pointer.chartPosition.left;
point.plotY += this.chart.pointer.chartPosition.top;
// Temporary set the chart size to the full document, so that the tooltip positioner picks it up
chart.chartWidth = $(document).width();
chart.chartHeight = $(document).height();
// Compute the tooltip position
pos = proceed.call(this, boxWidth, boxHeight, point);
// Reset chart size
chart.chartWidth = chartWidth;
chart.chartHeight = chartHeight;
return pos;
});
/**
* Find the new position and perform the move. This override is identical
* to the core function, except the anchorX and anchorY arguments to move().
*/
H.Tooltip.prototype.updatePosition = function(point) {
var chart = this.chart,
label = this.label,
pos = (this.options.positioner || this.getPosition).call(
this,
label.width,
label.height,
point
);
// do the move
this.move(
Math.round(pos.x),
Math.round(pos.y || 0), // can be undefined (#3977)
point.plotX + chart.plotLeft - pos.x,
point.plotY + chart.plotTop - pos.y
);
};
}(Highcharts));
var chart = new Highcharts.Chart({
chart: {
height: 500,
renderTo: 'container',
type: 'pie'
},
tooltip: {
formatter: function() {
return '<div class="MyChartTooltip">test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> </div>';
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});

You can add point with small z values and then update them one by one asynchronously (after the one point is updated, update the next one)
You can also override bubble.prototype.animate function and change default animation-like this:
Highcharts.seriesTypes.bubble.prototype.animate = function(init) {
var H = Highcharts
var each = H.each
var animation = this.options.animation;
var points = this.points
var animatePoint = i => {
var point = points[i]
var graphic = point && point.graphic
var animationTarget
if (graphic && graphic.width) {
animationTarget = {
x: graphic.targetX,
y: graphic.targetY,
width: graphic.targetWidth,
height: graphic.targetHeight
}
graphic.animate(animationTarget, animation, () => {
animatePoint(i + 1)
});
} else {
this.update({ dataLabels: { enabled: true }})
}
}
if (!init) { // run the animation
each(points, function(point) {
var graphic = point.graphic,
animationTarget;
if (graphic && graphic.width) { // URL symbols don't have width
graphic.targetWidth = graphic.width
graphic.targetHeight = graphic.height
graphic.targetX = graphic.x
graphic.targetY = graphic.y
// Start values
graphic.attr({
x: point.plotX,
y: point.plotY,
width: 1,
height: 1
});
}
});
animatePoint(0)
// delete this function to allow it only once
this.animate = null;
}
}
example: http://jsfiddle.net/hpk497hb/

Related

react-three, unable to get mouse position for html content

I'm trying to to get current mouse position on the canvas when html contents are clicked. With useFrame, I can successfully print out mouse position on any parts of canvas except when mouse is on html contents (it just shows the last mouse position before it enters html part and just stops there).
Are there any ways I can get mouse position when it hovers on html content?
Here are my codes:
#app.js
import React, {useRef, useState } from 'react';
import {Canvas, useFrame, useThree } from '#react-three/fiber';
import { Stars, Html } from '#react-three/drei'
function Sphere(props){
const mesh = useRef(null);
const { viewport, mouse } = useThree()
useFrame(({ mouse }) => {
const x_viewport = (mouse.x * viewport.height) / 2
console.log(x_viewport)
});
return(
<mesh
ref={mesh}
<sphereGeometry args={[1, 16, 16]} />
<meshStandardMaterial />
</mesh>
);
};
function Blocks (props) {
const {handlePost } = props;
let rows = [];
for (let i = 0; i < 30; i++) {
rows.push(<div onClick={handlePost} key={i} ></div>);
}
return (
<>
<div> { rows } </div>
</>
)
}
export default function Meshes() {
const [ hasRender, setRender ] = useState(false);
const handlePost = (e) => {
setRender(true);
}
return (
<>
<Canvas
orthographic
dpr={[1, 1.5]}
mode="concurrent"
camera={{ zoom: 10, position: [0, 0, 500] }}
style={{ width: c_width, color: "black" }}
>
<color attach="background" args={["black"]} />
<Html >
<Blocks handlePost={handlePost} />
</Html>
<ambientLight intensity={0.1} />
<directionalLight position={[0, 1, 1]} />
<Sphere days={days}/>
</Canvas>
{ hasRender && ( <PostItems /> )}
</>
);
}
function App() {
return (
<>
<Meshes />
</>
)
}

Create transparent background image from text input

i just trying to do create image from text input value which i want to transparent background, but somehow somewhere there is a mistake which i couldn't find. http://jsfiddle.net/e4f3Lc6n/
When i change the var backgroundColor = "transparent"; to any color it works like a charm. but you can see in jsfiddle link it is writing over the previous text when it is transparent. For my project there should be no color background. Where am i making a mistake?
Thanks for any help...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Text Arranger</title>
<link rel="stylesheet" href="../poetry/poetry_stylesheet.css" type="text/css"/>
<link rel="stylesheet" href="../index_stylesheet.css" type="text/css"/>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46245008-1', 'peteymac.com');
ga('send', 'pageview');
</script>
<script type="text/javascript">
window.addEventListener("load", eventWindowLoaded, false);
var Debugger = function() {};
Debugger.log = function(message) {
try {
console.log(message);
} catch (exception) {
return;
}
}
function eventWindowLoaded () {
canvasApp();
}
function canvasSupport () {
return !!document.createElement("canvas").getContext;
}
function canvasApp () {
Debugger.log("Drawing Canvas");
if(!canvasSupport()) {
return;
}
var theCanvas = document.getElementById('canvasOne');
var context = theCanvas.getContext('2d');
WIDTH = theCanvas.width;
HEIGHT = theCanvas.height;
var message = "canberk";
var fontSize = "50";
var fontFace = "serif";
var fontWeight = "normal"
var fontStyle = "normal";
var textFillColor = "#ff0000";
var backgroundColor = "transparent";
var textStrokeColor = "#000000";
var fillOrStroke = "fill";
var textBaseline = "middle";
var textAlign = "center";
var fillType = "colorFill";
// This is the event handler for listening for a key up event in the text box form
// It will call the textBoxChanged function to update the text in the canvas
var formElement = document.getElementById("textBox");
formElement.addEventListener("keyup", textBoxChanged, false);
formElement = document.getElementById("textSize");
formElement.addEventListener("change", textSizeChanged, false);
formElement = document.getElementById("textFont");
formElement.addEventListener("change", textFontChanged, false);
formElement = document.getElementById("fontWeight");
formElement.addEventListener("change", fontWeightChanged, false);
formElement = document.getElementById("fontStyle");
formElement.addEventListener("change", fontStyleChanged, false);
formElement = document.getElementById("fillType");
formElement.addEventListener("change", fillTypeChanged, false);
formElement = document.getElementById("textFillColor");
formElement.addEventListener("change", textFillColorChanged, false);
formElement = document.getElementById("createImageData");
formElement.addEventListener("click", createImageDataPressed, false);
drawScreen();
function drawScreen() {
var metrics = context.measureText(message);
var textWidth = metrics.width;
var xPosition = WIDTH / 2
var yPosition = HEIGHT / 2;
// Draws the Text Box
context.globalAlpha = 1.0;
context.fillStyle = backgroundColor;
context.fillRect(0,0,WIDTH,HEIGHT);
// Draws the actual text
context.font = fontWeight + " " + fontStyle + " " + fontSize + "px " + fontFace;
context.textBaseline = textBaseline;
context.textAlign = textAlign;
var tempColor;
switch(fillType) {
case "colorFill":
Debugger.log("Color Fill");
tempColor = textFillColor;
break;
case "linearGradient":
Debugger.log("Linear Gradient");
var linGradient = context.createLinearGradient(xPosition-textWidth/2, yPosition, xPosition+textWidth/2, yPosition);
linGradient.addColorStop(0, textFillColor);
tempColor = linGradient;
break;
case "radialGradient":
Debugger.log("Radial Gradient");
var radGradient = context.createRadialGradient(xPosition, yPosition, 1, xPosition, yPosition, textWidth/2);
radGradient.addColorStop(0, textFillColor);
tempColor = radGradient;
break;
}
switch(fillOrStroke) {
case "fill":
context.fillStyle = tempColor;
context.fillText(message, xPosition, yPosition);
break;
case "stroke":
context.strokeStyle = textStrokeColor;
context.strokeText(message, xPosition, yPosition);
break;
case "both":
context.fillStyle = tempColor;
context.fillText(message, xPosition, yPosition);
context.strokeStyle = textStrokeColor;
context.strokeText(message, xPosition, yPosition);
break;
}
}
function textBoxChanged(e) {
var target = e.target;
message = target.value;
drawScreen();
}
function textSizeChanged(e) {
var target = e.target;
fontSize = target.value;
drawScreen();
}
function textFontChanged(e) {
var target = e.target;
fontFace = target.value;
drawScreen();
}
function fontWeightChanged(e) {
var target = e.target;
fontWeight = target.value;
drawScreen();
}
function fontStyleChanged(e) {
var target = e.target;
fontStyle = target.value;
drawScreen();
}
function fillTypeChanged(e) {
var target = e.target;
fillType = target.value;
drawScreen();
}
function textFillColorChanged(e) {
var target = e.target;
textFillColor = "#" + target.value;
drawScreen();
}
function createImageDataPressed(e) {
var imageDataDisplay = document.getElementById("imageDataDisplay");
imageDataDisplay.value = theCanvas.toDataURL();
}
}
</script>
<style>
#canvasOne {
box-shadow: -4px -4px 5px #aaaaaa;
display: block;
margin-left: -60px;
}
form {
margin-top: 40px;
}
</style>
</head>
<body>
<canvas id="canvasOne" width="1000" height="250">
Your browser does not support Canvas.
</canvas>
<form>
Text: <input id="textBox" value="canberk"/>
<br/>
Text Font: <select id="textFont">
<option value = "serif">Serif</option>
<option value = "sans-serif">Sans-Serif</option>
<option value = "cursive">Cursive</option>
<option value = "fantasy">Fanatasy</option>
<option value = "monospace">Monospace</option>
</select>
Font Weight: <select id="fontWeight">
<option value="normal">Normal</option>
<option value="bold">Bold</option>
<option value="bolder">Bolder</option>
<option value="lighter">Lighter</option>
</select>
Font Style: <select id="fontStyle">
<option value="normal">Normal</option>
<option value="italic">Italic</option>
<option value="oblique">Oblique</option>
</select>
<br/>
Text Size: <input type="range" id="textSize"
min="0"
max="200"
step="1"
value="50"/>
<br/>
Fill Type: <select id="fillType">
<option value="colorFill">Color Fill</option>
<option value="linearGradient">Linear Gradient</option>
<option value="radialGradient">Radial Gradient</option>
</select>
<br/>
Text Fill Color: <input id="textFillColor" value="ff0000"/>
<input type="button" id="createImageData" value="Create Data Image">
<br/>
<textarea id="imageDataDisplay" rows=5 cols=100></textarea>
</form>
</div>
</body>
</html>
I think the solution you need is:
function drawScreen() {
context.clearRect(0, 0, WIDTH, HEIGHT);
...
...
}

how can I add a button next print button on a tree view?

I could add buttons on forms but I wanna know how can I add a button just next the print or create button on a tree view. Is it possible?
in Odoo 10. My code to add a dropdown list:
You can do this: static/xml/my_btn_temp.xml
<?xml version="1.0" encoding="utf-8" ?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_discard" t-operation="after">
<t t-if="widget.model=='product.template'">
<select class="oe_my_priceliste_button btn btn-sm btn-primary" name="oe_my_priceliste_button" id="oe_my_priceliste_button"
style="margin-left:7%;width:45%;display:inline-block;border: 1px solid #CCCCCC; border-radius: 3px; background: orange;color:white;">
</select>
</t>
</t>
</t>
</templates>
And add this qweb to __manifest__.py:
'data': [....],
'qweb': ['static/xml/my_btn_temp.xml',],
And to add actions to this button, you can do it with JS:
odoo.define('my_module.btn_price_list_tree', function(require) {
"use strict";
var core = require('web.core');
var utils = require('web.utils');
var Model = require('web.Model');
var Widget = require('web.Widget');
var ViewManager = require('web.ViewManager');
var ControlPanel = require('web.ControlPanel');
var ListView = require('web.ListView');
var dataset = require('web.data');
var Dialog = require('web.Dialog');
var list_widget_registry = core.list_widget_registry;
var QWeb = core.qweb;
var _t = core._t;
ListView.include({
load_list: function(data) {
var self = this;
var result = this._super.apply(this, arguments);
var CHOICE = _t("Choose a price list");
var op_tions = "<option value='-1'>"+CHOICE+"</option>";
if (this.$el) {
new Model("product.pricelist").query().all().then(function(ret){
if(ret){
for(var ind=0; ind< ret.length; ind++){
var res = ret[ind];
op_tions += "<option value='"+res.id+"'>"+res.name+"</option>";
}
$('#oe_my_priceliste_button').html(op_tions);
}
});
}
return result;
},
render_buttons: function() {
var self = this;
var add_button = false;
if (!this.$buttons) { // Ensures that this is only done once
add_button = true;
}
this._super.apply(this, arguments); // Sets this.$buttons
if(add_button) {
this.$buttons.on('change', '.oe_my_priceliste_button', this.proxy('do_price_list_dropdown_change'));
}
},
do_price_list_dropdown_change: function(){
var price_list_id = $('#oe_my_priceliste_button').val();
new Model("product.template").call("do_price_list_dropdown_change",[[],price_list_id], {}, {async: true}).done(function(data) {
window.location.reload(true);
});
},
});
});
And you add your js with: /views/assets.js
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="project assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/plw_core/static/src/js/add_pricelist_dropdown.js"></script>
</xpath>
</template>
</data>
</odoo>
Thanks.

x3dom rotation not working when using toAxisAngle(). Element follows mouse correctly, but does not rotate correctly

I have a page that I am creating that is similar to a game with a bird's eye view. I am trying to move a x3dom element on the x and z axis based on a mouse move event. It works except it isn't rotated correctly. The element called placeholder is the one that I am moving based on the mouse coordinates. Under the function squaremousemove(), you'll notice the rotation of rot[1]. I tried replacing this with rotateIncrement which is how I rotate all the other elements, but this didn't work. The place holder is suppose to have the same rotation as the square. Any ideas?
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="style/x3dom.css">
<script type="text/javascript" charset="utf-8" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/x3dom.js"></script>
<style>
body {margin: 0; padding: 0;}
#debugtext {position: absolute; top: 30px; left: 15px;}
</style>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var screenW = $(document).width();
var screenH = $(document).height();
var rotateIncrement = 0.78;
var groundlevel = 0.1;
var isMouseDown = false;
var isShiftPressed = false;
var isCtrlPressed = false;
var lastrotatevalueX = 0;
var lastpanvalueX = 0;
var lastpanvalueZ = 0;
var panincrementX = 0;
var panincrementZ = 200;
var x3d = document.getElementById('x3darea');
// set the height and width of the x3d area
$("#x3darea").css({width: screenW + "px", height: screenH + "px", border: "0"});
// set viewpoint attributes
viewpoint.setAttribute("position", "0 65 200");
viewpoint.setAttribute("orientation", "1 0 0 -0.5");
// set initial rotation
rotateshapes();
// disable selection for all elements
$(document).disableSelection();
$(document).keydown(function(e) {
if (e.shiftKey)
isShiftPressed = true;
if (e.ctrlKey)
isCtrlPressed = true;
});
$(document).keyup(function(e) {
isShiftPressed = false;
isCtrlPressed = false;
});
x3d.addEventListener("mousedown", function() {
isMouseDown = true;
}, false);
x3d.addEventListener("mouseup", function() {
isMouseDown = false;
}, false);
x3d.addEventListener("mousemove", function(e) {
if (isMouseDown) {
if (isShiftPressed)
rotatesetup(e);
if (isCtrlPressed) {
panviewbox(e);
}
// not sure what these two lines do except that they disable the built-in rotation and panning
e.cancelBubble = true;
e.stopPropagation();
}
}, true);
function panviewbox(e) {
var increment = 0.4;
if (lastpanvalueX > e.layerX)
panincrementX += increment;
else
panincrementX -= increment;
if (lastpanvalueZ > e.layerY)
panincrementZ += increment;
else
panincrementZ -= increment;
lastpanvalueX = e.layerX;
lastpanvalueZ = e.layerY;
viewpoint.setAttribute("position", panincrementX + " 65 " + panincrementZ);
}
function rotatesetup(e) {
var increment = 0.06;
if (lastrotatevalueX > e.layerX)
rotateIncrement += increment;
else
rotateIncrement -= increment;
lastrotatevalueX = e.layerX;
rotateshapes(e);
}
function rotateshapes() {
$(".rotatable").each(function() {
gridline = document.getElementById($(this).attr('id'));
gridline.setAttribute('rotation', '0 1 0 ' + rotateIncrement);
});
}
});
function squaremousemove(event) {
var posX = event.worldX;
var posZ = event.worldZ;
var placeholder = document.getElementById('placeholder');
var norm = new x3dom.fields.SFVec3f(event.normalX, event.normalY, event.normalZ);
var qDir = x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0, 1, 0), norm);
var rot = qDir.toAxisAngle();
$("#debugtext").html(rot[1]);
// $("#debugtext").html(posX.toFixed(4) + ", " + posZ.toFixed(4));
placeholder.setAttribute('rotation', rot[0].x + ' 1 ' + rot[0].z + ' ' + rot[1]);
placeholder.setAttribute('translation', event.worldX + ' 0.1 ' + event.worldZ);
placeholder.setAttribute('center', (event.worldX*-1) + ' 0 ' + (event.worldZ*-1));
// placeholder.setAttribute('translation', posX + ' 1 ' + posZ);
// placeholder.setAttribute('rotation', '0 1 0 ' + rotateIncrement);
}
</script>
</head>
<body>
<div id="devcontent">
<span id="debugtext"></span>
<x3d id="x3darea">
<scene>
<transform id="square" class="rotatable" onmousemove="squaremousemove(event);" translation="0 0 0">
<shape>
<appearance>
<material diffuseColor='green'></material>
</appearance>
<box size="200 0.01 200" />
</shape>
</transform>
<transform id="placeholder" class="rotatable" translation="-95 0.1 91" center="95 0 -91">
<shape>
<appearance>
<material diffuseColor='#ff8787'></material>
</appearance>
<box size="6 0.1 6" />
</shape>
</transform>
<transform id="building1" class="rotatable" translation="-40 2 20" center="40 0 -20">
<shape>
<appearance>
<material diffuseColor='blue'></material>
</appearance>
<box size="2 4 2" />
</shape>
</transform>
<transform id="building2" class="rotatable" translation="5 2.5 18" center="-5 0 -18">
<shape>
<appearance>
<material diffuseColor='yellow'></material>
</appearance>
<box size="4 5 4" />
</shape>
</transform>
<transform id="road1" class="rotatable" translation="0 0.1 0" center="0 0 0">
<shape>
<appearance>
<material diffuseColor='gray'></material>
</appearance>
<box size="200 0.001 2" />
</shape>
<Viewpoint id="viewpoint" />
</scene>
</x3d>
</div>
</body>
</html>

html5 kineticjs with free transform save image to web service

I need to use kinetic in order to transform one image using the anchors. I found this example:
http://www.html5canvastutorials.com/labs/html5-canvas-drag-and-drop-resize-and-invert-images/
I then need to save just one image - the yoda image (id: myImg) and send off to a web service. I'm having trouble with the saving portion.
Can anyone help? I'm not sure everything is correct, as I'm getting this error on when btnsave - Object #Class has no method 'replace' index.html:187
code
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
canvas {
border: 1px solid #9C9898;
}
</style>
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.0.0.js"></script>
<script>
function update(group, activeAnchor) {
var topLeft = group.get(".topLeft")[0];
var topRight = group.get(".topRight")[0];
var bottomRight = group.get(".bottomRight")[0];
var bottomLeft = group.get(".bottomLeft")[0];
var image = group.get(".image")[0];
// update anchor positions
switch (activeAnchor.getName()) {
case "topLeft":
topRight.attrs.y = activeAnchor.attrs.y;
bottomLeft.attrs.x = activeAnchor.attrs.x;
break;
case "topRight":
topLeft.attrs.y = activeAnchor.attrs.y;
bottomRight.attrs.x = activeAnchor.attrs.x;
break;
case "bottomRight":
bottomLeft.attrs.y = activeAnchor.attrs.y;
topRight.attrs.x = activeAnchor.attrs.x;
break;
case "bottomLeft":
bottomRight.attrs.y = activeAnchor.attrs.y;
topLeft.attrs.x = activeAnchor.attrs.x;
break;
}
image.setPosition(topLeft.attrs.x, topLeft.attrs.y);
var width = topRight.attrs.x - topLeft.attrs.x;
var height = bottomLeft.attrs.y - topLeft.attrs.y;
if(width && height) {
image.setSize(width, height);
}
}
function addAnchor(group, x, y, name) {
var stage = group.getStage();
var layer = group.getLayer();
var anchor = new Kinetic.Circle({
x: x,
y: y,
stroke: "#666",
fill: "#ddd",
strokeWidth: 2,
radius: 8,
name: name,
draggable: true
});
anchor.on("dragmove", function() {
update(group, this);
layer.draw();
});
anchor.on("mousedown touchstart", function() {
group.setDraggable(false);
this.moveToTop();
});
anchor.on("dragend", function() {
group.setDraggable(true);
layer.draw();
});
// add hover styling
anchor.on("mouseover", function() {
var layer = this.getLayer();
document.body.style.cursor = "pointer";
this.setStrokeWidth(4);
layer.draw();
});
anchor.on("mouseout", function() {
var layer = this.getLayer();
document.body.style.cursor = "default";
this.setStrokeWidth(2);
layer.draw();
});
group.add(anchor);
}
function loadImages(sources, callback) {
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 = sources[src];
}
}
function initStage(images) {
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 400
});
var darthVaderGroup = new Kinetic.Group({
x: 270,
y: 100,
draggable: true
});
var yodaGroup = new Kinetic.Group({
x: 100,
y: 110,
draggable: true
});
var layer = new Kinetic.Layer();
/*
* go ahead and add the groups
* to the layer and the layer to the
* stage so that the groups have knowledge
* of its layer and stage
*/
layer.add(darthVaderGroup);
layer.add(yodaGroup);
stage.add(layer);
// darth vader
var darthVaderImg = new Kinetic.Image({
x: 0,
y: 0,
image: images.darthVader,
width: 200,
height: 138,
name: "image"
});
darthVaderGroup.add(darthVaderImg);
addAnchor(darthVaderGroup, 0, 0, "topLeft");
addAnchor(darthVaderGroup, 200, 0, "topRight");
addAnchor(darthVaderGroup, 200, 138, "bottomRight");
addAnchor(darthVaderGroup, 0, 138, "bottomLeft");
darthVaderGroup.on("dragstart", function() {
this.moveToTop();
});
// yoda
var yodaImg = new Kinetic.Image({
x: 0,
y: 0,
image: images.yoda,
width: 93,
height: 104,
name: "image",
id: "myImg"
});
yodaGroup.add(yodaImg);
addAnchor(yodaGroup, 0, 0, "topLeft");
addAnchor(yodaGroup, 93, 0, "topRight");
addAnchor(yodaGroup, 93, 104, "bottomRight");
addAnchor(yodaGroup, 0, 104, "bottomLeft");
yodaGroup.on("dragstart", function() {
this.moveToTop();
});
stage.draw();
$("#btnSave").click(function () {
var image = stage.get("#myImg")[0];
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: domain + '/Services/WS.asmx/UploadImage',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert(msg.d);
}
});
});
}
window.onload = function() {
var sources = {
darthVader: "http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg",
yoda: "http://www.html5canvastutorials.com/demos/assets/yoda.jpg"
};
loadImages(sources, initStage);
};
</script>
</head>
<body onmousedown="return false;">
<div id="container"></div>
<input type="button" id="btnSave" name="btnSave" value="Save the canvas to server" />
</body>
</html>
You might need to stringify everything,
For example:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WS/SaveObject.asmx/fSaveToDB"),
data: JSON.stringify({ _obj: this }),
dataType: "json"
});
I had a huge problem before myself, started to work after i stringified it

Resources