Comments (8)
Hi @auggywonger!
There are a few issues with the code:
There is no "large" div for the "small" element to be cloned into.Sorry, the "large" div is being created.SVG don't expand by using css to change their dimensions. The actualThe SVG is affected by CSS dimensions!width
andheight
attributes of the SVG need to be changed.
Here is a working demo
- There was a second "small" div being added, so that name was changed to "large".
- The
initialzed
callback is used to adjust the dimensions of thelarge
div SVG dimensions. - I started out by tweaking some of the dimensions,
500px
is just a little too big for a JSFiddle demo, but I hope this gives you a better idea.
$(function() {
var zoom_container = d3.select("body")
.append("div")
.attr("id", "zoom")
var svg = zoom_container.append("div")
.attr("class", "small")
.append("svg")
.attr({
viewBox: "0 0 50 50",
width: 50,
height: 50
});
svg.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", 50)
.attr("height", 50)
.attr("fill", "red")
zoom_container.append("div")
.attr("class", "large");
$("#zoom").anythingZoomer({
edit: true,
clone: true,
initialized: function(e, zoomer) {
zoomer.$large.find('svg').attr({
width: 100,
height: 100
});
},
});
});
from anythingzoomer.
Thanks for the reply!
I can see that the code works on jsfiddle. However, when I copy the code over to my environment, I still have the same issue... This is the code I am running right now.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Time Squared Prototype</title>
<script type="text/javascript" src="//d3js.org/d3.v3.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="js/jquery.anythingzoomer.js"></script>
<style type="text/css">
.hostbar {
position: absolute;
left: 0;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
.small svg {
width: 100px;
height: 100px;
}
.large svg {
width: 250px;
height: 250px;
}
.az-wrap {
margin-top: 50px;
}
/* AnythingZoomer */
.az-wrap,
.az-small,
.az-large {
position: relative;
}
.az-wrap-inner {
display: block;
margin: 0 auto;
/* center small & large content */
}
/* This wraps the large image and hides it */
.az-zoom {
background: #fff;
border: #333 1px solid;
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
overflow: hidden;
z-index: 100;
display: none;
-moz-box-shadow: inset 0px 0px 4px #000;
-webkit-box-shadow: inset 0px 0px 4px #000;
box-shadow: inset 0px 0px 4px #000;
}
/* Class applied to az-mover when large image is windowed */
.az-windowed {
overflow: hidden;
position: absolute;
}
/* Class applied to az-mover when large image is fully shown */
.az-expanded {
height: auto;
width: auto;
position: static;
overflow: visible;
}
/* overlay small area */
.az-overlay {
background-color: #000;
opacity: 0.3;
filter: alpha(opacity=30);
z-index: 10;
}
/* fade out small content when hovering
.az-hovered > * {
opacity: 0.5;
filter: alpha(opacity=50);
}
*/
/* edit mode coordinate styling */
.az-coords {
display: none;
/* hidden when expanded */
}
.az-zoom .az-coords {
display: block;
position: absolute;
top: 0;
right: 0;
background: #000;
background: rgba(0, 0, 0, 0.5);
color: #fff;
}
</style>
</head>
<body>
<script type="text/javascript">
var zoom_container = d3.select("body")
.append("div")
.attr("id", "zoom")
var svg = zoom_container.append("div")
.attr("class", "small")
.append("svg")
.attr({
viewBox: "0 0 50 50",
width: 50,
height: 50
});
svg.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", 50)
.attr("height", 50)
.attr("fill", "red")
zoom_container.append("div")
.attr("class", "large");
$("#zoom").anythingZoomer({
edit: true,
clone: true,
initialized: function(e, zoomer) {
zoomer.$large.find('svg').attr({
width: 100,
height: 100
});
},
});
</script>
</body>
</html>
I am developing my code on my Windows laptop and viewing it with Google chrome. My code is kept in a folder where I installed node.js. I also have a server.js script in the folder. The code from server.js is below:
#!/usr/bin/env node
var express = require('express');
var app = express();
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(express.static('./'));
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
The html code is kept in index.html in the folder. To run the code, I run the command node server.js from the folder in the command prompt.
Perhaps I am doing something really obvious and silly that I missed?
from anythingzoomer.
Press F12 to see if there are any javascript errors. Also, don't use jQuery v1.3.2, try something newer like v3.1.0.
from anythingzoomer.
Thanks! Updating my jquery version did the trick.
I have some follow-up questions:
-
If I have enabled the clone option, do I need to explicitly create a large div? I thought that a large div would be automatically created.
-
In http://stackoverflow.com/questions/38754427/using-jquery-anythingzoomer-plugin-to-magnify-svgs , how come the demo code works even though the dimensions of the svg were not specified in javascript?
from anythingzoomer.
The large div content is created when clone
is set to true
, not the div itself.
If you mean the original demo, the dimensions are set for the rect
:
svg.append("rect")
.attr("x", 0)
.attr("y", 100)
.attr("width", 20)
.attr("height", 20)
.attr("fill", "red")
and the viewBox
on the svg
is set to 500x500.
For the large div, only the svg the css adjusts the size of the svg.width
and height
need to be adjusted. Not the rect
dimensions, nor the svg viewBox
Update: provided the correct info.
from anythingzoomer.
Hi,
Apologies, I sent the wrong link in my last post. I meant the demo in http://stackoverflow.com/questions/21553145/how-to-achieve-magnifying-square-effect-for-d3-charts .
from anythingzoomer.
Sorry, you're right... I provided incorrect information.
You only need the to set the dimensions of the svg using css. I think the original demo didn't appear to work because the dimensions of the rect
were 20x20 and the viewBox
was set to 500x500, so there was a very small target to find in a very small result window provided by jsFiddle.
from anythingzoomer.
Thanks! That clears things up.
from anythingzoomer.
Related Issues (20)
- Large Container Positioning Problem
- div contets HOT 1
- Different sizes images HOT 4
- Zoom displays large image only HOT 2
- conflicts with jquery wrapAll() HOT 1
- Hover doesnot work properly when -transform-rotate is done HOT 6
- Using zoom in multiple stacked images for Chrome / Safari HOT 5
- Plugin not showing zoom window when implemented on bootstrap modal HOT 2
- Issue while rotating image. HOT 4
- image map HOT 3
- Is it possible to rotate zoomer automatically on page load HOT 4
- Cloned Image Offset HOT 3
- Responsive Image HOT 4
- Enable/Disable Anything Zoomer HOT 1
- Show coordinates of large image HOT 6
- Make zoomDim configurable in options HOT 1
- Zooming over input/radio elements HOT 8
- How to use dynamic id based this plugin ? HOT 1
- Canvas compatibility ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anythingzoomer.