如何在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);
原文:https://stackoverflow.com/questions/41465866
最满意答案
遗产? 没有。
即使假设你有一个实际的域实体,它包含列表中的前三个字段,而
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( ...
-
如何查询JPA中多对多关系中的实体列表?(How do I query a list of entities in a many to many relationship in JPA?)[2022-03-12]
如果你知道具体的清单ID不能你只是检索清单,并从它得到thingys的名单? Manifest m = em.find(Manifest.class, manifestId); Listthingys = 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 ... -
jpa非管理实体(jpa non managed entities)[2023-12-06]
由于审计日志表共享相同的列,因此可以创建一个“统一”这些表并将单个Java类映射到该视图的视图。 我相信你可以,因为你不需要写更新,我想。 作为替代方案,使用本机查询将是一个不错的选择。 编辑 : 1)如果您的审计日志已经是视图,则可以根据其他视图创建视图,如果您不想为每个视图创建映射Java类。 只记得添加一个值为1的虚拟列,如果该行来自“第一个”审核日志,则为2如果它来自第二个,依此类推,这样您就可以将它们分开。 2)为了使用本机查询,假设您的持久性提供程序是Hibernate,您可以在此示例中执行以下 ... -
使用JPA查询部分实体(Query partial entities with JPA)[2023-06-13]
遗产? 没有。 即使假设你有一个实际的域实体,它包含列表中的前三个字段,而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 ...