-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple table drawing functionality. #841
Conversation
Hi thanks for this great work. Can you update the table to add info in it after it has been created? |
I'm still working on that. However, as a workaround, you can index the table like a list, since it's just a VGroup. The way I've set it up now, the first few objects in the VGroup are the field names/headings. After the field names, the next few objects are reserved for those in the first column (the leftmost one) and are ordered top to bottom. The next few objects are the values in the column to the immediate right of it and so on, until all the records are in the VGroup. The object present immediately after the records is the horizontal line. The objects present after that are the vertical separators. Once you know which object to modify, you can ReplacementTransform() them with the new value you want them to be. For example: from manimlib.imports import *
from sanim.anim_tools.tables import *
class Tables(Scene):
def construct(self):
tabledict={
TextMobject("TextMobject Input"):[TextMobject("Must"),TextMobject("add"),TextMobject("element"),TextMobject("retrieval.")],
TexMobject("TexMobject Input"):[TexMobject(r"e^{\iota\pi}+1 = 0"),TexMobject(r"Tex: \alpha\theta\epsilon")],
Text("Text input",font="Lucida Grande"):[Text("Text",font="sans-serif"),Text("is"),Text("Supported")],
"Raw String Input":["Defaults","to","TextMobject."]
}
table=Table.get_table(tabledict,line_color=GREY,raw_string_color=BLUE)
table.move_to((0,0,0))
self.play(Write(table.scale(0.5)),run_time=2)
#CHECK THIS OUT ↓
newvalue=TextMobject("New Value").move_to(table[0]) #The first index is the first columns heading
self.play(ReplacementTransform(table[0],newvalue))
self.wait(1) The code above gives this output: Adding info will be a bit more difficult. I'll get to that soon! |
Thanks it worked. The counting does not include empty table cells? It's a bit strange. Looking forward to the rest of your code! |
Perhaps you could use empty strings for those locations?
…On Wed, 12 Feb, 2020, 23:17 Nathenat, ***@***.***> wrote:
Thanks it worked. The counting does not include empty table cells? It's a
bit strange. Looking forward to the rest of your code!
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#841?email_source=notifications&email_token=AH5H6JHULQEGJT4VEVJ34LLRCQY4ZA5CNFSM4J7XGHK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELRXAIA#issuecomment-585330720>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH5H6JHA4HKP6CTPVUDJTELRCQY4ZANCNFSM4J7XGHKQ>
.
|
Hey! I managed to add basic Record addition and removal to the table. You can get the most recent version of the script here: https://github.com/Aathish04/sanim/ I've had to make some major changes regarding how everything works. Table() is now it's own type of Mobject, and not just a VGroup. You can still use it like a VGroup though. You can use See the example below: from manimlib.imports import *
from sanim.anim_tools.tables import *
class Tables(Scene):
def construct(self):
tabledict={
TextMobject("TextMobject Input"):[TextMobject("Must"),TextMobject("add"),TextMobject("element"),TextMobject("retrieval.")],
TexMobject("TexMobject Input"):[TexMobject(r"e^{\iota\pi}+1 = 0"),TexMobject(r"Tex: \alpha\theta\epsilon")],
"Raw String Input":["Defaults","to","TextMobject."],
Text("Text input",font="Lucida Grande"):[Text("Text",font="Alys Script Bold"),Text("is",font="serif"),Text("Supported",font="serif")],
}
table=Table(tabledict=tabledict,line_color=GRAY,raw_string_color=BLUE)
table.move_to((0,0,0))
table.scale(0.5)
self.play(Write(table),run_time=2)
self.play(Write(table.add_record(record=TextMobject("Hello"),field_num=1)))
self.play(Uncreate(table.remove_record(field_num=1,record_num=0)))
self.wait(1) Hope this helps! I'm still working on Field addition and removal. That is a lot harder than I thought ;) |
For the empty string, I had already tried and the cell was ignored in the numbering. Thanks a lot for the new code, I'll use it asap and let you know if I have any feedback. |
Please do tell me if there are any wierd bugs etc!
…On Mon, 17 Feb, 2020, 16:08 Nathenat, ***@***.***> wrote:
For the empty string, I had already tried and the cell was ignored in the
numbering.
Thanks a lot for the new code, I'll use it asap and let you know if I have
any feedback.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#841?email_source=notifications&email_token=AH5H6JBWIESUY7JKRRHEIHTRDJSLNA5CNFSM4J7XGHK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL546JY#issuecomment-586927911>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH5H6JBQ5CHKJNYT2ESI2UDRDJSLNANCNFSM4J7XGHKQ>
.
|
First Off:
You’re using a really old version of the Manim Library.
Instead of using the version with Pip, you should use the version from GitHub.
… On 03-Apr-2020, at 17:18, AIE- Machine Learning & Image Processing ***@***.***> wrote:
<https://user-images.githubusercontent.com/48950631/78357406-0de4cd00-75cf-11ea-9181-738fa08e7f68.png>
I am getting this error. Any Suggestions?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub <#841 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AH5H6JH7QEK6QUZCFYYZ7ODRKXEI3ANCNFSM4J7XGHKQ>.
|
I'm having the error:
NameError: name 'Table' is not defined I put the file tables.py into the folder manimlib/mobjects, not sure what the issue is. |
Have you added |
Like @tony031218 mentioned, also add Also, |
FOR THE REFERENCE OF ANYONE WHO STUMBLES UPON THIS THREAD: |
Simple adding the latest version of |
Can you please file an issue on the repository I linked stating what went wrong and the traceback/errors, if any? |
Motivation
Tables are really useful for displaying data concisely, which is really useful when making animations on topics such as statistics and science. Currently, Manim can only generate Tables easily through LaTeX, which results in difficulty when generating tables programmatically.
Results Obtained
With this addition, tables can be made by calling
Table.get_table(<dictionary>)
, where the main, required parameter is a dictionary with the Keys as the field names and Values per Key are the corresponding records.The code above generates the following table:
Further customisations can be made by passing a
line_color
andtext_color
in the same function like so:Table.get_table(tabledict,line_color=GREEN,text_color=BLUE)
Both of these values default to WHITE.
Changes Made:
A single file named
tables.py
has been added tomanimlib/mobjects
. This file contains the entirety of the logic used.manimlib.imports
has been edited to import the aforementioned file.Future plans for this feature include a wraparound for text and
better length measuring of LaTeX strings to ensure proper table column widths, as well asbetter table element retrieval, since you can only retrieve elements by indexing the resultant VGroup() as of now.EDIT: I'm closing this PR, since I feel this would work better as an addon to Manim rather than as a core feature. I added support for Text(), TexMobjects(), TextMobjects() and strings. Those interested can find it here. An example on how to use all its features are here.