d3.js - 使带有图例的地图适合在调整窗口大小时改变大小的容器
问题描述
这是我当前的代码,它具有预定义的所有参数(即具有固定大小)
代码+演示:
https://plnkr.co/edit/AzflYyovnJ6YwE5I?preview
但问题是容器会响应我希望(地图+图例)适合它。(map+legend) 应该能够根据容器调整自己。
我的部分代码来自当前代码:
var map = d3.select("#chart")
const width = w;//map1.node().getBoundingClientRect().width;
const height = h;//width / 2;
const zoom = d3.zoom()
.scaleExtent([1, 40])
// .translateExtent([[0,0], [width, height]])
.extent([[0, 0], [width, height]])
.on("zoom", zoomed);
const svg = map.append("svg:svg")
.attr("width", width)
.attr("height", height)
.call(zoom);
const india = svg.append("g").attr("id", "india");
我从网上得到的解决方案中尝试了一些东西。但这对我没有用。
这是我失败的尝试:https ://plnkr.co/edit/KKiTe9exaBW8B9gP
编辑:
终于可以做到了,但是有问题。在调整大小时,我的地图消失了。
http://plnkr.co/edit/MjynaqFnE7qpad6G?preview
编辑2:
终于发现错误:这个来自SizeChange
函数的代码是所有的根源。我需要进行转换,使其位于中心我不知道该怎么做?
d3.select("g").attr("transform", "scale("+$("#chart").width() + $("#chart").height() + ")");
解决方案
推荐阅读
- javascript - 参数声明本身
- visual-studio-code - 在 Visual Code 终端上找到 nvm 和 gulp,但在 linux 终端上没有
- networking - 测验中的子网问题需要解释(见图)
- flutter - Flutter 无法从 url 加载图片
- java - 不支持 Spring Boot 405 POST 方法,但 GET 方法有效
- python - 字符图片网格 Python ATBS 索引超出范围
- c#-9.0 - 这是什么 C# 功能?
- javascript - 当使用新查询推送相同的路由时,创建的钩子不再运行
- swift - swift _ 推入 ViewController 会出现黑屏
- visual-studio-code - macOS 中的文本编辑器对两个带有 ANSI 转义码的文件的差异有问题吗?