Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/api-reference/from_gql_create.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Import from a GQL CREATE query
------------------------------

.. automodule:: neo4j_viz.gql_create
:members:
2 changes: 1 addition & 1 deletion docs/source/api-reference/from_neo4j.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Import from Neo4j
------------------------------------------------
-----------------

.. automodule:: neo4j_viz.neo4j
:members:
64 changes: 58 additions & 6 deletions docs/source/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Integration with other libraries
In addition to creating graphs from scratch, with ``neo4j-viz`` as is shown in the
:doc:`Getting started section <./getting-started>`, you can also import data directly from external sources.
In this section we will cover how to import data from `Pandas DataFrames <https://pandas.pydata.org/>`_,
`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/>`_ and
`Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_.
`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/>`_,
`Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_ and
`GQL CREATE queries <https://neo4j.com/docs/cypher-manual/current/clauses/create/>`_.


.. contents:: On this page:
Expand Down Expand Up @@ -159,7 +160,7 @@ more extensive example.


Neo4j Database
---------------
--------------

The ``neo4j-viz`` library provides a convenience method for importing data from Neo4j.
It requires and additional dependency to be installed, which you can do by running:
Expand All @@ -171,15 +172,15 @@ It requires and additional dependency to be installed, which you can do by runni
Once you have installed the additional dependency, you can use the :doc:`from_neo4j <./api-reference/from_neo4j>` method
to import query results from Neo4j.

The ``from_neo4j`` method takes one mandatory positional parameters:
The ``from_neo4j`` method takes one mandatory positional parameter:

* A ``result`` representing the query result either in form of `neo4j.graph.Graph` or `neo4j.Result`.

The ``node_caption`` parameter is also optional, and indicates the node property to use for the caption of each node in the visualization.

We can also provide an optional ``size_property`` parameter, which should refer to a node property,
and will be used to determine the sizes of the nodes in the visualization.

The ``node_caption`` and ``relationship_caption`` parameters are also optional, and indicate the node and relationship properties to use for the captions of each element in the visualization.

The last optional property, ``node_radius_min_max``, can be used (and is used by default) to scale the node sizes for
the visualization.
It is a tuple of two numbers, representing the radii (sizes) in pixels of the smallest and largest nodes respectively in
Expand Down Expand Up @@ -218,3 +219,54 @@ In this small example, we import a graph from a Neo4j query result.

Please see the :doc:`Visualizing Neo4j Graphs tutorial <./tutorials/neo4j-example>` for a
more extensive example.


GQL ``CREATE`` query
--------------------

The ``neo4j-viz`` library provides a convenience method for creating visualization graphs from GQL ``CREATE`` queries via the :doc:`from_neo4j <./api-reference/from_gql_create>` method method.

The ``from_gql_create`` method takes one mandatory positional parameter:

* A valid ``query`` representing a GQL ``CREATE`` query as a string.

We can also provide an optional ``size_property`` parameter, which should refer to a node property,
and will be used to determine the sizes of the nodes in the visualization.

The ``node_caption`` and ``relationship_caption`` parameters are also optional, and indicate the node and relationship properties to use for the captions of each element in the visualization.

The last optional property, ``node_radius_min_max``, can be used (and is used by default) to scale the node sizes for
the visualization.
It is a tuple of two numbers, representing the radii (sizes) in pixels of the smallest and largest nodes respectively in
the visualization.
The node sizes will be scaled such that the smallest node will have the size of the first value, and the largest node
will have the size of the second value.
The other nodes will be scaled linearly between these two values according to their relative size.
This can be useful if node sizes vary a lot, or are all very small or very big.


Example
~~~~~~~

In this small example, we create a visualization graph from a GQL ``CREATE`` query.

.. code-block:: python

from neo4j_viz.gql_create import from_gql_create

query = """
CREATE
(a:User {name: 'Alice', age: 23}),
(b:User {name: 'Bridget', age: 34}),
(c:User {name: 'Charles', age: 45}),
(d:User {name: 'Dana', age: 56}),
(e:User {name: 'Eve', age: 67}),
(f:User {name: 'Fawad', age: 78}),

(a)-[:LINK {weight: 0.5}]->(b),
(a)-[:LINK {weight: 4}]->(c),
(e)-[:LINK {weight: 1.1}]->(d),
(e)-[:LINK {weight: -2}]->(f);
"""

VG = from_gql_create(query)
8 changes: 8 additions & 0 deletions examples/neo4j-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@
" )\n",
" print(result.summary.counters)"
]
},
{
"cell_type": "markdown",
"id": "daf2f685c2e13fb9",
"metadata": {},
"source": [
"**NOTE:** Since in this example we didn't already have a Neo4j DB populated with data, it would actually have been more convenient to use the serverless `from_gql_create` importer method to create our `VisualizationGraph`."
]
}
],
"metadata": {
Expand Down
Loading