I am trying to animate an object with snap.svg, it's showing but not scaling.
Here's my code.
It works only if I generate the object with code but not working with loaded svg objects.
Why it's not being animated on hover?
<html>
<head>
<title></title>
<script type="text/javascript" src="snap.svg.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#svg {
width : 600px;
height : 600px;
}
</style>
</head>
<body>
<svg id="svg"> </svg>
</body>
<script type="text/javascript">
var paper = Snap("#svg");
Snap.load("balls.svg" , function(d){
var icon = d.select('#round_ball');
var back = d.select('#background');
paper.append(d);
back.attr({
fill : '#000000'
});
icon.hover(function(event) {
this.animate({
transform : "t110,150",
filter: f
}, 200, mina.easeout);
}, function(event) {
this.animate({
transform : "t0,0"
}, 200, mina.easeout);
});
});
</script>
</html>
Related
I have to load Libre Barcode 128 font family in to fabric canvas. But Barcode doesn't view on canvas. How to set Libre Barcode 128 font family in fabric js canvas?
var text;
var canvas;
document.addEventListener("DOMContentLoaded", function() {
canvas = new fabric.Canvas('c');
setTimeout(function() {
text = new fabric.Text("Text", {
fontSize: 70,
left: 100,
top: 0,
fill: '#sew3435'
});
canvas.add(text).setActiveObject(text);
canvas.getActiveObject().set("fontFamily", 'Libre Barcode 128');
canvas.renderAll();
}, 1000)
});
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Text" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.19/fabric.js"></script>
<script src="html2canvas.js"></script>
<style>
.ss {
font-family: 'Libre Barcode 39 Text';
font-size: 48px;
}
</style>
</head>
<body>
<div class="ss">Making the Web Beautiful!</div>
<canvas id="c" width=500 height=250></canvas>
</body>
</html>
The actual font is a 3-of-9 font, not 128 (though they are treated the same way) and the name should be (as defined in the CSS):
.set("fontFamily", "'Libre Barcode 39 Text'");
You might have to "preuse" the font on an DOM element before it will be picked up by the canvas.
Update: seems as FabricJS uses incoming string as-is so the inner quotes must be added also there due to the spaces in the font family name (included here for completeness).
Fiddle example
var text;
var canvas;
document.addEventListener("DOMContentLoaded", function() {
canvas = new fabric.Canvas('c');
setTimeout(function() {
text = new fabric.Text("Text", {
fontSize: 70,
left: 100,
top: 0,
fill: '#f00'
});
canvas.add(text).setActiveObject(text);
canvas.getActiveObject().set("fontFamily", "'Libre Barcode 39 Text'");
canvas.renderAll();
}, 500)
});
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Text"
rel="stylesheet">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.19/fabric.js"></script>
</head>
<body>
<canvas id="c" width=500 height=250></canvas>
</body>
</html>
We have to set font family name with in single quotes like " 'Libre Barcode 39 Text' ", Finally it works for me.
I am trying to do a very simple example of datepicker field.
{ name: 'p_ManagerDateApproved', width: 80, editable: true, editoptions: { dataInit: function(el) { setTimeout(function() { $(el).datepicker(); }, 200); } } },
Firebug says "TypeError: $(...).datepicker is not a function
...Init: function(el) { setTimeout(function() { $(el).datepicker(); }, 200); } } }
Everything else in my grid seems to work ok. Can anyone give me an idea of how to go about solving this, I am not sure where to start.
I wasnt able to post this in a comment so here is my code I probably should have posted this first sorry
<head>
<style>
#gbox_grid{display:none;}
a:link {color:blue;}
a:visited {color:blue;}
a:hover {color:blue;}
a:active {color:yellow;}
.readonly {background-color: WhiteSmoke !important;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQgrid - ASPX</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script>
<!--<script src="http://asp2d:1138/jquery-1.8.3.js"></script>-->
<!--<script src="http://asp2d:1138/jquery-ui-1.9.2.custom.js"></script>-->
<script type="text/javascript" src="http://asp2d:1138/grid.locale-en.js"></script>
<script type="text/javascript" src="http://asp2d:1138/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://asp2d:1138/jquery-ui-1.9.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="http://asp2d:1138/ui.jqgrid.css" />
<script>
$(function () {
I have been making some graphs using dc.js and i am plotting some manufacturers in a row-chart against their count. when manufacturer increase in number the row width becomes really small and hard to distinguish.
I tried to use overflow : scroll in css but it also scrolls the scale with the graph.
There is a way to do this. I have 4 files, index.html, iframe.html, iframe.css, and iframe.js. Here is my setup. In index.html I had:
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
<script type="text/javascript" src="d3.v3.min.js"></script>
<script type="text/javascript" src="crossfilter.js"></script>
<script type="text/javascript" src="dc.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<link type="text/css" rel="stylesheet" href="dc.css">
<link type="text/css" rel="stylesheet" href="iframe.css">
</head>
<body>
<iframe class="iframe" src="iframe.html"></iframe>
<script type="text/javascript" src="iframe.js"></script>
</body>
</html>
in iframe.html I had:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="d3.v3.min.js"></script>
<script type="text/javascript" src="crossfilter.js"></script>
<script type="text/javascript" src="dc.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<link type="text/css" rel="stylesheet" href="dc.css">
</head>
<body>
<div id="rowChart"></div>
<script type="text/javascript" src="iframe.js"></script>
</body>
</html>
in iframe.css I had:
.iframe {
width: 800px;
height: 200px;
border: none;
}
in iframe.js I had:
var data = [];
for (var i = 1; i < 10; i++) {
data.push({
val: i
});
}
var ndx = crossfilter(data);
var dim = ndx.dimension(function(d) {
return d.val;
});
var group = dim.group().reduceSum(function(d) {
return d.val;
});
rowChart = dc.rowChart("#rowChart");
rowChart.width(800)
.height(400)
.margins({top: 10, right: 40, bottom: 30, left: 40})
.dimension(dim)
.group(group)
.elasticX(true)
.gap(1)
.x(d3.scale.linear().domain([-1, 10]))
.transitionDuration(700);
dc.renderAll();
In this setup I had all 4 files in the same level in my directory.
New to html/css/js and nvd3 so this may be a noob question.
I have an html doc that loads fine with a nvd3 chart that is drawn with a function drawChart(). However when I try to use jquery and I put drawChart() into $(document).ready, the chart does not load?
Why is this happening?
Here is the HTML code:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Multi Bar Chart</title>
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css">
<style>
body {
overflow-y:scroll;
}
text {
font: 12px sans-serif;
}
#chart1 {
height: 500px;
margin: 10px;
min-width: 100px;
min-height: 100px;
}
</style>
</head>
<body>
<div>
<h1 style="text-align: center;">Title</h1>
</div>
<div id="chart1" class='with-3d-shadow with-transitions'>
<form class="form-inline" style="text-align: center;">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">dropdown<span class="caret"></span></button>
</div>
</form>
<svg></svg>
</div>
<script src="../lib/d3.v3.js"></script>
<script src="../nv.d3.js"></script>
<script src="../src/tooltip.js"></script>
<script src="../src/utils.js"></script>
<script src="../src/models/legend.js"></script>
<script src="../src/models/axis.js"></script>
<script src="../src/models/multiBar.js"></script>
<script src="../src/models/multiBarChart.js"></script>
<script src="stream_layers.js"></script>
<script src="multiBarChart3.js"></script>
<script src="../src/jquery-2.1.1.js"></script>
</body>
</html>
Here is the javascript:
function drawChart(){
var test_data = stream_layers(3,128,.1).map(function(data, i) {
return {
key: 'Stream' + i,
values: data
};
});
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
.margin({bottom: 100})
.transitionDuration(300)
.delay(0)
.rotateLabels(0)
.groupSpacing(0.1)
;
chart.multibar
.hideable(true);
chart.xAxis
.axisLabel("X")
.tickFormat(d3.format('d'));
chart.yAxis
.axisLabel("Y")
.tickFormat(d3.format(',.1f'));
chart.stacked(true);
d3.select('#chart1 svg')
.datum(test_data)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
};
//$(function(){
drawChart();
//});
I want the input tag value to draw on canvas...the following code didn't work.
window.onload()=draw()
draw(){
var canvas=document.getElementById('canvas');
var ctx=canvas.getContext('2d');
var text=document.getElementById('item').value
ctx.fillStyle="#3e3e3e";
ctx.font="16px Arial";
ctx.fillText(text,50,50);
}
You can "listen" for any keyup events and draw the text on the canvas
Here's code and a Fiddle: http://jsfiddle.net/m1erickson/ug88R/
<!doctype html>
<html>
<head>
<script>
function draw(event){
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var text=document.getElementById('item').value
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle="#3e3e3e";
ctx.font="16px Arial";
ctx.fillText(text,50,50);
}
window.addEventListener("keyup", draw, true);
</script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
</head>
<body>
<canvas id="canvas" width=300 height=300></canvas>
<input type="text" id="item">
</body>
</html>