首页 \ 问答 \ 如何在d3.js中排列行中的矩形(How to arrange rectangles in rows in d3.js)

如何在d3.js中排列行中的矩形(How to arrange rectangles in rows in d3.js)

我有100个矩形 ,我想在10x10中排列。 我已经能够安排一行和一列,但我正在安排其他九个。 这是js小提琴:

码:

var ContainerWidth = document.querySelector('#mainContainer').offsetWidth;
   var rectWidth = ContainerWidth / 20
   console.log(ContainerWidth)
   var svgContainer = d3.select("#boxy")

   var rectangle = svgContainer.selectAll("rect")
     .data((function() {
       var arr = []
       for (var i = 1; i <= 100; i++) {
         arr.push(i)
       }
       return arr
     }()));

   var rectangle = rectangle.enter()
     .append("rect")
     .style("stroke", "black")
     .style("fill", "none")
     .attr("x", function(d, i) {
       if (i % 10 == 0) {
         return 5
       } else {
         return (i*45) + 3;
       }

     })
     .attr("y", function(d, i) {
       if (i % 10 == 0) {
         return i*4.2
       }

     })
     .attr("width", rectWidth)
     .attr("height", rectWidth);

结果看起来应该是这样的 在此处输入图像描述


I i have 100 rectangles that I want to arrange in 10x10. I have been able to arrange one row and column but I am stuck at arranging the other nine. Here is js fiddle:

code:

var ContainerWidth = document.querySelector('#mainContainer').offsetWidth;
   var rectWidth = ContainerWidth / 20
   console.log(ContainerWidth)
   var svgContainer = d3.select("#boxy")

   var rectangle = svgContainer.selectAll("rect")
     .data((function() {
       var arr = []
       for (var i = 1; i <= 100; i++) {
         arr.push(i)
       }
       return arr
     }()));

   var rectangle = rectangle.enter()
     .append("rect")
     .style("stroke", "black")
     .style("fill", "none")
     .attr("x", function(d, i) {
       if (i % 10 == 0) {
         return 5
       } else {
         return (i*45) + 3;
       }

     })
     .attr("y", function(d, i) {
       if (i % 10 == 0) {
         return i*4.2
       }

     })
     .attr("width", rectWidth)
     .attr("height", rectWidth);

the result should look something like this enter image description here


原文:https://stackoverflow.com/questions/41465866
更新时间:2024-03-22 07:03

最满意答案

遗产? 没有。

即使假设你有一个实际的域实体,它包含列表中的前三个字段,而Inventory也会对它进行扩展,你对该实体所做的任何查询都将不可避免地加载所有字段(如果映射到不同的表,则通过join)由于隐含多态性。

你可以做的是将第4和第5个属性映射为“懒惰”; 您的JPA提供程序必须使用字节码检测才能执行此操作:

@Basic(fetch = FetchType.LAZY)
private Integer unitssold;

@Basic(fetch = FetchType.LAZY)
private String ourcomment;

您必须在需要获取所有内容的查询中指定fetch all properties ; 其他人在首次访问之前不会检索属性值。

老实说,如果你的查询返回大的结果集并且“懒惰”属性本身相当大(例如,我不会单独使用Integer ;如果它可以变长,则String可能是可行的),这种方法是值得的。


Inheritance? No.

Even assuming you've had an actual domain entity that consisted of first three fields on your list and Inventory would have extended it, any query you would have made against that entity would inevitably load all fields (via join if mapped to a different table) due to implicit polymorphism.

What you can do is map the 4th and 5th properties as "lazy"; your JPA provider will have to employ bytecode instrumentation in order to be able to do that:

@Basic(fetch = FetchType.LAZY)
private Integer unitssold;

@Basic(fetch = FetchType.LAZY)
private String ourcomment;

You'll have to specify fetch all properties in queries where you need to fetch everything; others will not retrieve property value until first accessed.

To be honest, this approach is only worth it if your queries return large result sets and "lazy" properties are rather big themselves (e.g. I wouldn't do it for Integer alone; String may be feasible if it can get long)

相关问答

更多
  • 尝试这个 select distinct t from Trade t join t.combo c join c.legs l join l.exchange e where e.exchangeShortName = 'whatever' Try this select distinct t from Trade t join t.combo c join c.legs l join l.exchange e where e.exchangeShortName ...
  • 以下是可以提供帮助的查询: select c1 from Class1 c1 join c1.class2 c2 where c2.id in (1,2,3) group by c1 having count(c1)=3 ; Here is the query that can help: select c1 from Class1 c1 join c1.class2 c2 where c2.id in (1,2,3) group by c1 having count(c1)=3 ;
  • 我假设您使用的是“标准”JPA工具(JPT),因为您没有另行指定。 首先,您需要定义一个连接(在Data Source Exlporer中)。 您应该能够深入查看您需要使用的实际表格: 在创建JPA项目或激活JPA构面时,您可以在“JPA构面”页面上选择构架:有一个名为“覆盖连接的默认构架”的复选框以及一个选择“构架”的组合框: 当您要求生成实体时,您甚至可以选择模式(右键单击项目,JPA工具>从表生成实体...),然后获得此对话框: 快乐映射! I am assuming that you are usi ...
  • 不同JVM之间没有神奇的同步变化。 UI应用程序只会看到后端应用程序持久保存到数据库中的更改。 因此,简而言之,您需要强制实体的数据库持久性/查找。 请注意,您可能还会遇到缓存问题(例如,Hibernate默认会对实体进行一些自动缓存)。 如果UI应用程序已缓存实体,则即使持久存储到数据库中,它也不会看到后端应用程序所做的更改,直到UI应用程序也对数据库本身执行新查询。 因此,我建议您彻底测试并根据需要调整配置。 There is no magical synchronisation of changes ...
  • 将你的实体ID用作你的流程的businessKey怎么样? 然后,您可以对您的实体(具有特定标题的图书)执行查询,然后使用它在Activiti中检索您的过程 I've implemented my solution descirbed in the questions comments. I don't yet have a big dataset to test performance but it seems acceptable.
  • 当持续关系的非拥有方(包含'mappedBy'并且在您的情况下使用者)的实例时,您必须始终确保关系的双方都设置为按预期级联工作。 无论如何,您总是应该这样做,以确保您的域模型是正确的。 Consumer c = new Consumer(); ProfilePicure p = new ProfilePicture(); c.setProfilePicture(p);//see implementation //persist c Consumer.java @Entity @Table( ...
  • 如果你知道具体的清单ID不能你只是检索清单,并从它得到thingys的名单? Manifest m = em.find(Manifest.class, manifestId); List thingys = m.thingys; If you know the specific manifest ID couldn't you just retrieve that manifest and get the list of thingys from it? Manifest m = em.f ...
  • 由于审计日志表共享相同的列,因此可以创建一个“统一”这些表并将单个Java类映射到该视图的视图。 我相信你可以,因为你不需要写更新,我想。 作为替代方案,使用本机查询将是一个不错的选择。 编辑 : 1)如果您的审计日志已经是视图,则可以根据其他视图创建视图,如果您不想为每个视图创建映射Java类。 只记得添加一个值为1的虚拟列,如果该行来自“第一个”审核日志,则为2如果它来自第二个,依此类推,这样您就可以将它们分开。 2)为了使用本机查询,假设您的持久性提供程序是Hibernate,您可以在此示例中执行以下 ...
  • 遗产? 没有。 即使假设你有一个实际的域实体,它包含列表中的前三个字段,而Inventory也会对它进行扩展,你对该实体所做的任何查询都将不可避免地加载所有字段(如果映射到不同的表,则通过join)由于隐含多态性。 你可以做的是将第4和第5个属性映射为“懒惰”; 您的JPA提供程序必须使用字节码检测才能执行此操作: @Basic(fetch = FetchType.LAZY) private Integer unitssold; @Basic(fetch = FetchType.LAZY) private ...
  • 那么,我终于明白了。 它足以使实体实现一个通用接口(甚至不需要在Hibernate中声明该接口)。 然后,可以完成这样的查询: FROM my.package.CommonInterface obj WHERE obj IN (FROM EntityA WHERE fieldA=1) OR obj IN (FROM EntityB WHERE fieldB='a') 这样,您可以检索List 。 问题解决了。 Well, I finally figured i ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。