Giter Club home page Giter Club logo

d3blocks's Introduction

Python Pypi Docs LOC Downloads Downloads License Forks Open Issues Project Status Medium GitHub Repo stars GitHub repo size Colab Donate


D3Blocks builds on the graphics of d3 javascript (d3js) to create the most visually attractive and useful charts with only a few lines of Python code! The documentation pages contains detailed information about the working of the blocks with many examples.


See here an overview for all the blogs


Installation (Pypi)

pip install d3blocks     # Normal installation
pip install -U d3blocks  # Force update

Installation (clone)

git clone https://github.com/d3blocks/d3blocks.git
cd d3blocks
pip install -U .

Import d3blocks package

from d3blocks import d3blocks
# Initialize
d3 = D3Blocks()

nr Block Function Blog
1 D3graph d3.d3graph() D3graph
2 Elasticgraph d3.elasticgraph() Elasticgraph
3 Sankey d3.sankey() Sankey
4 Movingbubbles d3.movingbubbles() Movingbubbles
5 Scatter d3.scatter() Scatter
6 Heatmap d3.heatmap() Heatmap
7 Chord diagram d3.chord() D3Blocks
8 Timeseries d3.timeseries() D3Blocks
9 Image slider d3.imageslider() D3Blocks
10 Violin plot d3.violin() D3Blocks
11 Particles d3.particles() D3Blocks
12 Treemap d3.treemap() D3Blocks
13 Maps d3.maps() D3Blocks
14 Circlepacking d3.circlepacking() D3Blocks
----- ------------------------------------------------------------------------------------ ------------------------------ --------------------------------------------------------------------------------------------------------------------------------------

References

d3blocks's People

Contributors

erdogant avatar oliver3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3blocks's Issues

Sankey: order of entries

Hi there,

Again, thanks for the amazing work.

I have a question related to the sankey graph. It seems that, when drawing the graph, the order of some elements changes, so that they get swapped. Here is an example:
Screenshot 2023-12-06 at 18 08 44

As you can see, within the second level of the relationships, allergies_reaction_2 is followed by conditions_patient, and then by allergy_code. However, in the dataframe that I am using as input allergies_reaction_2 is followed by allergy_code.

I was wondering if there is a way of forcing the order?

Thanks a lot!
Davide

Sunburst

Hi! Are you planning to add support for sunbursts? :)

What is the most effective way to contribute?

Hi!

This is an amazing project and I'd like to contribute. Sorry for the silly question but...what's the best way to do so? Are there any guidelines you followed? For example I'd like to add simpler charts such as barchart.

Thanks for your time!

Circular import error

Hi,

I've tried downloading your package following the instructions on the docs pages, using a clean Anaconda env and python 3.10, but I get circular import errors when importing the package in Python.

from d3blocks import D3Blocks
ImportError: cannot import name 'D3Blocks' from partially initialized module 'd3blocks' (most likely due to a circular import)

I tried multiple versions of the code (1.0.7, 1.0.6, 1.0.2) without success.

Any clues how to fix this?

Best regards,
Mike

The 'd3blocks.chord.Chord' package was not installed in a way that PackageLoader understands.

I've decided to start exploring this lib from the Chord Block example:

from d3blocks import D3Blocks
d3 = D3Blocks()
df = d3.import_example('stormofswords')
d3.chord(df)

After I ran this I got ValueError: The 'd3blocks.chord.Chord' package was not installed in a way that PackageLoader understands.
d3blocks was installed using pip on my Windows machine.

Full traceback:

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18292/2979146611.py in <module>
      2 d3 = D3Blocks()
      3 df = d3.import_example('stormofswords')
----> 4 d3.chord(df)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\d3blocks\d3blocks.py in chord(self, df, title, filepath, figsize, showfig, overwrite)
    561 
    562         # Create the plot
--> 563         self.config = Chord.show(df, self.config, labels=self.labels)
    564         # Open the webbrowser
    565         if self.config['showfig']: self.showfig()

~\AppData\Local\Programs\Python\Python39\lib\site-packages\d3blocks\chord\Chord.py in show(df, config, labels)
     41     X = get_data_ready_for_d3(df, labels)
     42     # Write to HTML
---> 43     write_html(X, config)
     44     # Return config
     45     return config

~\AppData\Local\Programs\Python\Python39\lib\site-packages\d3blocks\chord\Chord.py in write_html(X, config)
     68     }
     69 
---> 70     jinja_env = Environment(loader=PackageLoader(package_name=__name__, package_path='d3js'))
     71     index_template = jinja_env.get_template('chord.html.j2')
     72     index_file = Path(config['filepath'])

~\AppData\Local\Programs\Python\Python39\lib\site-packages\jinja2\loaders.py in __init__(self, package_name, package_path, encoding)
    307 
    308         if template_root is None:
--> 309             raise ValueError(
    310                 f"The {package_name!r} package was not installed in a"
    311                 " way that PackageLoader understands."

ValueError: The 'd3blocks.chord.Chord' package was not installed in a way that PackageLoader understands.

Moving Bubbles: Control of colors

Would it be possible to color based on a the item moving, and allow the colors to stay original no matter where they move? That could be helpful to show clusters of different groups at different times.

I cannot import d3blocks

image
I cannot import d3bloicks,.,, help me..
my code is
from d3blocks import D3Blocks

error is
ImportError: cannot import name 'D3Blocks' from partially initialized module 'd3blocks.d3blocks' (most likely due to a circular import) (C:\Users\user\anaconda3\lib\site-packages\d3blocks\d3blocks_init_.py)

How do I break a text label into multiple rows?

I just have started playing with the library,
was very impressed with all the beautiful diagrams.
I was wondering how do I break a long text for the labels into multiple rows?
I have noticed \n is getting ignored.

My code example:

    df = pd.DataFrame({'source': ['Europe\n(Population size: 742,041,249)',
                                  'Europe\n(Population size: 742,041,249)',
                                  'Europe\n(Population size: 742,041,249)',
                                  'Europe\n(Population size: 742,041,249)',
                                  ],
                       'target': ['Eastern Europe\n(288,176,491)',
                                  'Western Europe\n(195,841,934)',
                                  'Southern Europe\n(151,357,685)',
                                  'Northern Europe\n(106,896,543)']})
html = d3.tree(df,
               font={'size': 20},
               save_button=False)

Thanks

Great Work

Just wanted to leave a note at home much I appreciate this project.

Selecting colors for chord diagrams

Hi, when using the chord diagram on some data, I wanted to select the colors of the diagrams by myself, but it turns out I couldn't find a way to change the colormap.
It would be a great addition to the library, if it were possible to select the colors for chord diagrams.
In the meantime, thanks for this amazing library and keep up the great work!

The blogs/tutorials are behind a paywall

I was very excited to hear about D3 Blocks, but when I reached the GitHub page and looked for some sample programs, I saw that the links led me back to the articles on Medium.com, and as you can see from the screenshots in this link (https://ibb.co/Z1CdkmP), Medium has blocked access with a restriction of being able to read only 2 articles for free per day unless the User makes a payment for a subscription. This is not how an open source project's knowledge should be available.
I understand you wrote the articles on Medium because it provides good visibility. However, I request that you copy the same articles onto GitHub Pages or Blogger or WordPress or some other place where the content can be accessed without there being a paywall. At least the links in the readme should lead to those free sources instead of leading to Medium.

Change node shape and node label position in D3graph ?

Hello @erdogant :) This is a great library 👏. I am working on a project where I would like to use different node shapes (rectangle/triangle/or potentially something custom built). Is there a way to change the shape from circle to say rectangle for specific nodes in D3graph ? Similarly the node labels are currently plotted outside the node. I want to put them inside. Any way to make such a change ? In general we will be needing to make such small tweaks of different kinds. If you could also point to the parts of the d3blocks source code where you implement these kind of things (and how), we will be willing to implement some ourselves (maybe contribute here too). Looking forward to your response. Best wishes.

Recommendations: Put previous D3 items (i.e. D3graph) into D3 Blocks Main Repo

I think I would recommend putting all your code in one repo. For each potential user, having all of it under one roof makes much more sense, you will get less questions, and you won't have issues with shared code getting out of sync. It will cause a few folks to have to change their code slightly, but it will be worth it.

Inclusion of "ethical ads"

Hi,

thanks again for the time you invested in this project. Today I reviewed the code that was generated when I tried to use this library to create a chord diagram and was surprised to see that there is a script tag which loads some javascript from https://media.ethicalads.io and a div that is probably used to link your account to their service.

// ...
<div id="chart"></div>

<script async src='https://media.ethicalads.io/media/client/ethicalads.min.js'></script>
<div data-ea-publisher='erdogantgithubio' data-ea-type='text' data-ea-style='stickybox'></div>
// ...

Some examples can be found here: 1, 2, 3, etc.

In my opinion (could be totally wrong) this should either be omitted by default (opt in, not opt out) when generating diagrams or at least be disclosed in the README, not just the docstring/documentation page.
Otherwise, this kinda feels the same as if someone would install a lightweight crypto miner alongside free software without asking me or at least telling me that this would support further development and therefore is mandatory.

d3.violin fontsize argument affects tooltips, not tick labels

d3.violin(x = ground_truth.company,
          y = ground_truth.standard_cost_EUR,
          title = 'all cost data, fontsize = 20',
          color = ground_truth.color,
          opacity = 0.9,
          fontsize = 20,
          tooltip = list(ground_truth.standard_cost_EUR),
          ylim = ylim,
          bins = 20,
          figsize = (1000, 1000),
          showfig = True)

output:
image

d3.violin(x = ground_truth.company,
          y = ground_truth.standard_cost_EUR,
          title = 'all cost data, fontsize = 40',
          color = ground_truth.color,
          opacity = 0.9,
          fontsize = 40,
          tooltip = list(ground_truth.standard_cost_EUR),
          ylim = ylim,
          bins = 20,
          figsize = (1000, 1000),
          showfig = True)

output:
image

TypeError in version 1.2.10

First off, love the work you've done with the d3blocks package!

It looks like the most recent merge may've broke something. The error is flagged here:

reset_properties: bool = True):

This error occurs in version 1.2.10, but not in 1.2.9
image

Thanks again!

(I'm using python 3.7 atm)

matplotlib has no attribute colormaps when doing Sankey plots

Hi!

I was reading your article here and I tried to run one of the examples:

from d3blocks import D3Blocks

# Initialize
d3 = D3Blocks()

# Import example
df = d3.import_example('energy')

# Link settings
d3.sankey(df, link={"color": "source-target"})

After doing so, I get the following error:

In [11]: d3.sankey(df, link={"color": "source-target"}) 
    ...:                                                                                                                                                                                                     
[d3blocks] >INFO> Create label properties based on [Set1].
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-c0dd4004eea9> in <module>
----> 1 d3.sankey(df, link={"color": "source-target"})

~/.local/lib/python3.8/site-packages/d3blocks/d3blocks.py in sankey(self, df, title, filepath, figsize, node, link, margin, showfig, overwrite)
    954         # Set default label properties
    955         if not hasattr(self, 'labels'):
--> 956             labels = self.get_label_properties(labels=np.unique(df[['source', 'target']].values.ravel()), cmap=self.config['cmap'])
    957             self.set_label_properties(labels)
    958 

~/.local/lib/python3.8/site-packages/d3blocks/d3blocks.py in get_label_properties(self, labels, cmap)
   1244 
   1245         # Create unique colors
-> 1246         hexcolors = colourmap.generate(len(uil), cmap=cmap, scheme='hex')
   1247         # Make dict with properties
   1248         labels = make_dict_label_properties(uil, hexcolors)

~/.local/lib/python3.8/site-packages/colourmap/colourmap.py in generate(N, cmap, method, keep_alpha, scheme, verbose)
     64     else:
     65         # base = plt.cm.get_cmap(cmap)
---> 66         base = matplotlib.colormaps[cmap]
     67         color_list = base(np.linspace(0, 1, N))[:, 0:listlen].tolist()
     68         # If there are not enough colors in the cmap, use the seaborn method.

AttributeError: module 'matplotlib' has no attribute 'colormaps'

I'm using python 3.8 and d3blocks 1.0.8.

Thank you!

How to change node colors in sankey plots?

I would like to generate a sankey plot by using following code:

d3 = D3Blocks(chart='Sankey', frame=True)
d3.set_node_properpodties(data)
d3.set_edge_properties(data, color='target', opacity='target')
d3.sankey(data)

How to change node colors in sankey plots?

Working with very large graphs (d3graph)

I have a social graph with 1000 vertices, I generated a Pandas data frame and passed it to the d3graph function.
There are almost 100,000 lines in df.
And I failed to run the example on my own data (which is noticeably larger than in the base example). More precisely, it started, but the page was hanging terribly.

At the same time, the computer itself experienced almost no load. CPU and RAM usage was less than half.

Is it possible to fix this?
Perhaps there is some optimization or something else that I am not familiar with?

Can't create certain figures

I think this is a really cool project... unfortunately for me, certain figures aren't working. I can create the first D3graph example but at least sankey and chord diagrams aren't working.

When running
d3 = D3Blocks()
df = d3.import_example(data='energy')
d3.sankey(df, link={"color":"source-target"})
d3.show()

I am getting an error that reads:

d3.sankey(df, link={"color":"source-target"})
[d3blocks] >INFO> Cleaning edge_properties and config parameters..
[d3blocks] >INFO> Initializing [sankey]
[d3blocks] >INFO> Convert to Frame.
[d3blocks] >INFO> Node properties are set.
[d3blocks] >INFO> Edge properties are set.
[d3blocks] >INFO> File already exists and will be overwritten: [/var/folders/mf/43th5k2j7zzgfqmpt8vptg5r0000gp/T/d3blocks/sankey.html] [d3blocks] >INFO> File not found: [file:////var/folders/mf/43th5k2j7zzgfqmpt8vptg5r0000gp/T/d3blocks/sankey.html]`

I get similar errors when running:

d3 = D3Blocks(chart='Sankey', frame=True)
df = d3.import_example(data='energy')
d3.set_node_properties(df)
d3.set_edge_properties(df, color='target', opacity='target')
d3.show()

or the examples for creating a chord diagram.

I'd love to know if there is a fix for this.

Thanks

Required package scikit-learn is not installed

D3Blocks requires sklearn, but the module is not listed in setup.py
If d3blocks is installed in an empty environment, it cannot be used due to a ModuleNotFoundError:

python -m venv venv
source ./venv/scripts/activate
pip install d3blocks
python -c 'import d3blocks'
> ...
> ModuleNotFoundError: No module named 'sklearn'

New Issue: Moving Bubble Time Control

Could ticks be controlled? I.e. I believe Slow Medium and Fast define how many ticks happen per second, what if we could use larger time windows say "day" and be able to advance or rewind manually? Help tell a story at the speed of the story tellr?

Sankey font size

Hi there!

First of all, amazing work, I am using your sankey plots a lot and they are very helpful.

I was wondering whether there was a way of increasing the font size of the labels on each rectangle?

Best
Davide

Documentation Suggestion

I am not sure if it's a mistake in rendering, or something you may not see because you live here, but when I look at the documentation, its really hard to follow. Example from the link below.

  • param and type actually more like column headers. But because they are first thing on the line, it's hard to differentiate the variable name from the variable name
  • since words like df and color are so generic it gets melded into the words param and type
  • Could you use a markdown table that has param, type, example, default, and returns (for fucnctions and then display the variables in a table?

I know this may sound pedantic, but I really believe your d3blocks is fantastic, and think the way the docs are written may make it harder for folks then it should be to understand what is happening.

https://d3blocks.github.io/d3blocks/pages/html/Chord.html

param df
Input data containing the following columns: ‘source’ ‘target’ ‘weight’ ‘color’ (optional) ‘opacity’ (optional)

type df
pd.DataFrame()

param color
Link colors in Hex notation. Should be the same size as input DataFrame. * ‘source’: Color edges/links similar to that of source-color node. * ‘target’: Color edges/links similar to that of target-color node. * ‘source-target’: Color edges/link based on unique source-target edges using the colormap. * ‘#ffffff’: All links have the same hex color. * [‘#000000’, ‘#ffffff’,…]: Define per link.

type color
(default: ‘source’)

param opacity
Link Opacity. Should be the same size as input DataFrame. * ‘source’: Opacity of edges/links similar to that of source-opacity node. * ‘target’: Opacity of edges/links similar to that of target-opacity node. * 0.8: All links have the same opacity. * [0.1, 0.75,…]: Set opacity per edge/link.```

Library Import problem : ModuleNotFoundError: No module named 'movingbubbles'

After installing d3blocks via Pypi in Anaconda prompt, using: pip install -U d3blocks
Importing the library in Jupyter Notebook is impossible, as shown in the image below, I am on Python 3.9.12.
image

Searched for a solution or similar cases on the Internet, but I did not find any, maybe it is a very recent issue.

Tooltip in treemap

Hi!

I very much like this project.

I have a question/suggestion. Is it possible to have a tooltip in treemap graphs?

Adding Labels to D3graph links

Great project, really useful work!

Would it be possible to add the functionality of adding labels to the links/edges in the D3graphs? (edge properties)

An example of such a graph is found here.

This would be really helpful!

Sorting issue on Chord diagrams

Hello,

I am tryin to plot a chord diagram, but the results are the plots with alphabetically sorted nodes.
I need to plot the nodes as the order in the main dataframe.

Is there a way to do that?
Thanks!

error to import d3blocks in jupyter notebook

Hi,
I try to use d3blocks to embellish my work.
But I ave an error when I try to import it to a jupyter notebook
Could you help me to debugg ?

D

import os
from d3blocks import D3Blocks
from IPython.display import IFrame
d3 = D3Blocks()
df = d3.import_example('energy')
d3.chord(df)


TypeError Traceback (most recent call last)
Input In [8], in <cell line: 3>()
1 # Load d3blocks
2 import os
----> 3 from d3blocks import D3Blocks
4 from IPython.display import IFrame
5 # Initialize

File ~/.local/lib/python3.8/site-packages/d3blocks/init.py:1, in
----> 1 from d3blocks.d3blocks import D3Blocks
3 from d3blocks.utils import (
4 normalize,
5 )
7 author = 'Erdogan Taskesen, Oliver Verver'

File ~/.local/lib/python3.8/site-packages/d3blocks/d3blocks.py:15, in
13 import time
14 from typing import List, Union, Tuple
---> 15 from elasticgraph import Elasticgraph
16 import d3graph as d3network
18 import d3blocks.movingbubbles.Movingbubbles as Movingbubbles

File ~/.local/lib/python3.8/site-packages/elasticgraph/init.py:5, in
2 """Documentation about elasticgraph"""
4 import logging
----> 5 from elasticgraph.elasticgraph import Elasticgraph
7 logging.getLogger(name).addHandler(logging.NullHandler())
9 author = "RWS Datalab"

File ~/.local/lib/python3.8/site-packages/elasticgraph/elasticgraph.py:7, in
5 from pathlib import Path
6 from typing import List, Union, Tuple
----> 7 from d3graph import d3graph, json_create, data_checks, make_graph
8 from jinja2 import Environment, PackageLoader
10 logger = logging.getLogger('')

File ~/.local/lib/python3.8/site-packages/d3graph/init.py:1, in
----> 1 from d3graph.d3graph import d3graph
2 from packaging import version
4 from d3graph.d3graph import (
5 vec2adjmat,
6 adjmat2vec,
(...)
10 data_checks,
11 )

File ~/.local/lib/python3.8/site-packages/d3graph/d3graph.py:878, in
863 return dumps(data, separators=(',', ':'))
866 # %% Convert adjacency matrix to vector
867 def adjmat2dict(adjmat: pd.DataFrame,
868 filter_weight: float = 0.0,
869 scaler: str = 'zscore',
870 marker_start=None,
871 marker_end='arrow',
872 marker_color='#808080',
873 label=None,
874 label_color='#808080',
875 label_fontsize: int = 8,
876 edge_weight: int = 1,
877 edge_distance: int = 50,
--> 878 minmax: list[float] = [0.5, 15],
879 minmax_distance: list[float] = [50, 100],
880 ) -> dict:
881 """Convert adjacency matrix into vector with source and target.
882
883 Parameters
(...)
934
935 """
936 # Convert adjacency matrix into vector

TypeError: 'type' object is not subscriptable

movingbubbles graphic : moving with weird timedelta

Dear Erdogan,
Many thanks for making moving bubbles graphics available to python. This is so an astonishing way to tell stories with timeseries activities !

I am currently working on a study that focus on french people hobbies during the day, and moving bubbles are a pefect fit to tell this tale.
We basically ask people what they do at what time and for how long. So as an input, I have a pandas dataframe, with the id of the people who answered the study, their state and the state daytime. her is a sample of why I have for one ID :

image

For this ID, the day starts at 6 am by watching TV ("Regarder la TV") for 10 minutes and doing something else urelated to hobbies ("Hors loisirs"). So I was expecting the chart to start at 06:00 am, with a point at "Regarder la TV". Then I was expecting the point to move towards "hors loisirs" at 06:10 am, i.e. 10 minutes later, but it actually did not. And when playing the chat on fast mode, I saw the point moving towards "Hors Loisirs" at 16:00 (or 4 pm), 10 hours later. Surprinsingly, the point did not return to "Regarder la TV" when the clock got back to 06:00 am. And the point never went to the other states, even afer waiting for 5 full clock cycles. So I may miss something in the clock ticking but my guess would be some conversion missing...

More surprisingly, I tried a sample of 3 Ids, with the one described above, with the following program :
image
image

In the chart, I got a bizarre switch 2 minutes after the start (while no movements are expected), one point going from "Hors loisirs" to "Regarder un film" at 16:00 (= 4pm) while this move is not expected at all, and another unexpected movement at 21:00 (=9pm) from "Regarder la TV" to "Hors Loisirs".

Below is the code I ran :
from d3blocks import D3Blocks d3 = D3Blocks() d3.movingbubbles(test, speed={"slow": 1000, "medium": 200, "fast": 10}, title='d3blocks_movingbubbles', filepath=r'C:\Users\Anthony\VERTIGO\Commun - Documents\CROSS LOISIRS\HOBBY ONE\bubble_chart\2022\movingbubbles.html', )

I sent you the csv and the html files which I talk about, so that you can have a look at it.

Many thanks for you help !

Best Regards,

Anthony

PS : I also see that percentage do not correspond to the number of point in the chart : when there is a single point, one may expect the point state percentage to be 100%. By opening the html file in VScode, I fount out it came from the "readablePercent" function at line 371.
the variable "pct" is divide by 1000, which is the number of point in your example. But it should be divided by data.length where data is all the point informations.
I did not find where it was in the python code ^^

Saving graphics as high resolution image

Hi,

First of all thanks for all of the efforts that is going into this great project.

I was trying to save some graphics (chord diagrams) which I am creating from a jupyter notebook to include them in a publication, hence it would be great to save them in an image format with high resolution.

Would it be possible to save the diagrams directly into an image format rather than going through an intermediate html file? Right now my only option seems to be taking a screenshot of the picture which doesn't look very nice when rescaling the image.

Thanks a lot in advance for any advice.

No capability to change tick labels

d3.violin(x = ground_truth.company,
          y = ground_truth.cost,
          color = colors,
          tooltip = list(ground_truth.cost),
          ylim = ylim,
          bins = 20,
          figsize = (1000, 1000),
          showfig = True)

produces expected output, but the tick labels are very small; there appears to be no way to change either the text properties or the y-axis tick locations.

treemap example fails on d3.show()

When attempting to run the final step of the treemap example I get a failure:

>>> from d3blocks import D3Blocks
>>> d3 = D3Blocks(chart='Treemap', frame=True)
<brevity>
>>> df = d3.import_example('energy')
<brevity>
>>> d3.set_node_properties(df)
<brevity>
>>> print(d3.node_properties)
<brevity>
>>> d3.set_edge_properties(df)
<brevity>
>>> print(d3.edge_properties)
<brevity>
>>> d3.show()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/d3blocks/d3blocks.py", line 2190, in show
    html = self.chart.show(self.edge_properties, config=self.config, node_properties=self.node_properties, logger=logger, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/d3blocks/treemap/Treemap.py", line 133, in show
    return write_html(X, config, logger)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/d3blocks/treemap/Treemap.py", line 177, in write_html
    index_template = jinja_env.get_template('treemap.html.j2')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattcriswell/github/tech_debt_analysis/.venv/lib/python3.11/site-packages/jinja2/loaders.py", line 344, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: treemap.html.j2

I noticed I seemed to be missing the treemap.html.j2 file:

site-packages $ tree d3blocks/treemap/
d3blocks/treemap/
├── Treemap.py
├── __init__.py
├── __pycache__
│   ├── Treemap.cpython-311.pyc
│   └── __init__.cpython-311.pyc
└── d3js
    ├── __init__.py
    └── __pycache__
        └── __init__.cpython-311.pyc

After manually copying the file(s) from the repo everything seemed to work:

site-packages $ tree d3blocks/treemap/
d3blocks/treemap/
├── Treemap.py
├── __init__.py
├── __pycache__
│   ├── Treemap.cpython-311.pyc
│   └── __init__.cpython-311.pyc
└── d3js
    ├── __init__.py
    ├── __pycache__
    │   └── __init__.cpython-311.pyc
    ├── d3.v4.min.js
    └── treemap.html.j2

My suspicion is that the file is being missed when you build locally because of the treemap __pycache__ directory not being cleared in the make_clean.sh script.

Though it's not impossible that there's something wrong with my environment or perhaps there is some user error on my end.

This happens in a fresh virtual environment. My system is running:

Python 3.11.2 (main, Feb 16 2023, 02:55:59) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin

jupyter notebook support

There are many attempts of d3 intergretion out there. Abosolutely love this work.
Please consider add jupyter notebook support if possible.
Thank you very much!

Tidy tree feature

Is it currently possible to generate tidy trees similar to this example?
If not - is this feature planned?

"color for link " is not aviliable in chord.

I provided a list containing ['#000000',....] to the d3.chord, but it resulted in an error. The error occurred in the file ~/Software/anaconda3/lib/python3.8/site-packages/d3blocks/chord/Chord.py at line 342. in get_data_ready_for_d3(df, labels)
340 X = X + ' "links":['
341 for _, row in df.iterrows():
--> 342 X = X + '{"source":' + str(row['source_id']) + ',"target":' + str(row['target_id']) + ',"value":' + str(row['weight']) + ',"opacity":' + str(row['opacity']) + ',"color":' + '"' + str(row['color']) + '"' + '},'
343 X = X[:-1] + ']}'
345 # Return

When I set the color in the dataframe, it still didn't work. Do you know the reason and how to fix it?

Idea: Moving Bubble Bubble Size

What if you wanted to represent something in the bubble being a certain amount of something. Say KWhs... you when it was moving from one point to another, it would be cool to show 10 KWh as a tightly bound group of 10 moving together. Maybe it could be joined to a larger circle, but we may lose the ability to discern the meaning of the size other than "bigger". Just tossing ideas out here....

Tree Diagram 1-to-many visualization

What are your thoughts on having a simplified version of the tree visual to show dataframe/data structure that flows from 1 column to another.

Consider the table below:

image

Ideally the tree should be able to link up:
0-1-2-3(0 idx) ; then
0-1-2-3 (1 idx)

Basically it should all branch out from column 0: Which is a unique value; normalized to show consistency

How best to facet this data to achieve the above ^. Because under the hood your code seems to optimize and remove redundancy or duplicates ? So the resulting graph is not like

0-1-2-3 (n-idx); it could be something which is 2-3-(4 idx)

More context: I did a network representation of this, basically I would want the same representation branching from the largest node to the smallest, but in the form of a tree diagram

image

Idea: Sankey Over Time

Not sure how this work, but if you had a way to load multiple Sankey Charts with FWD, BACK button or just a loop where you could set it to ticks to walk through different sankeys . like if you wanted to show energy flow per money and evolve it. Something like that. Not sure how hard that would be, if it would just re render the sankey at different points in time? using dfferent data?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.