Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ plox-*.tar

# Temporary files, for example, from tests.
/tmp/

# Ignore "Desktop Services Store" hidden file
.DS_Store
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ Once you have those, you can render a `graph` component within your HEEx templat

```html
<.graph id="example_graph" dimensions={@dimensions}>
<.x_axis_labels :let={date} axis={@x_axis}>
<Plox.Helpers.Axis.x_labels :let={date} axis={@x_axis}>
{Calendar.strftime(date, "%-m/%-d")}
</.x_axis_labels>
</Plox.Helpers.Axis.x_labels>

<.y_axis_labels :let={value} axis={@y_axis} ticks={5}>
<Plox.Helpers.Axis.y_labels :let={value} axis={@y_axis} ticks={5}>
{value}
</.y_axis_labels>
</Plox.Helpers.Axis.y_labels>

<.x_axis_grid_lines axis={@x_axis} stroke="#D3D3D3" />
<.y_axis_grid_lines axis={@y_axis} ticks={5} stroke="#D3D3D3" />
<Plox.Helpers.Grid.vertical_lines axis={@x_axis} dimensions={@dimensions} />
<Plox.Helpers.Grid.horizontal_lines axis={@y_axis} dimensions={@dimensions} ticks={5} />

<.polyline points={points(@dataset[:x], @dataset[:y])} stroke="#EC7E16" stroke-width={2} />

Expand Down
24 changes: 17 additions & 7 deletions docs/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ dataset =
```html
<.graph id="example_graph" dimensions={@dimensions}>
<!-- Render axis labels and lines individually -->
<.x_axis_labels :let={date} axis={@x_axis}>
<Plox.Helpers.Axis.x_labels :let={date} axis={@x_axis}>
{Calendar.strftime(date, "%-m/%-d")}
</.x_axis_labels>
</Plox.Helpers.Axis.x_labels>

<.y_axis_labels :let={value} axis={@y_axis} ticks={5}>
<Plox.Helpers.Axis.y_labels :let={value} axis={@y_axis} ticks={5}>
{value}
</.y_axis_labels>

<.x_axis_grid_lines axis={@x_axis} stroke="#D3D3D3" />
<.y_axis_grid_lines axis={@y_axis} ticks={5} stroke="#D3D3D3" />
</Plox.Helpers.Axis.y_labels>

<Plox.Helpers.Grid.vertical_lines
axis={@x_axis}
dimensions={@dimensions}
stroke="#D3D3D3"
/>

<Plox.Helpers.Grid.horizontal_lines
axis={@y_axis}
dimensions={@dimensions}
ticks={5}
stroke="#D3D3D3"
/>

<!-- Use the `points/2` helper to generate a list of {x, y} tuples from our Dataset -->
<.polyline points={points(@dataset[:x], @dataset[:y])} stroke="#EC7E16" stroke-width={2} />
Expand Down
57 changes: 44 additions & 13 deletions examples/animated_demo_live.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ defmodule AnimatedDemoLive do

import Plox

alias Plox.Helpers.Axis
alias Plox.Helpers.Grid

@interval 1000

@impl Phoenix.LiveView
Expand Down Expand Up @@ -83,26 +86,54 @@ defmodule AnimatedDemoLive do
def render(assigns) do
~H"""
<.graph dimensions={@dimensions}>
<.y_axis_labels :let={value} axis={@y_axis} ticks={5}>
<Axis.y_labels :let={value} axis={@y_axis} ticks={5}>
{value}
</.y_axis_labels>
</Axis.y_labels>

<.y_axis_grid_lines axis={@y_axis} ticks={5} stroke="#D3D3D3" />
<Grid.horizontal_lines axis={@y_axis} dimensions={@dimensions} ticks={5} />

<.x_axis_labels :let={datetime} axis={@x_axis} step={5} start={@nearest_5_second}>
<Axis.x_labels :let={datetime} axis={@x_axis} step={5} start={@nearest_5_second}>
{Calendar.strftime(datetime, "%-I:%M:%S")}
</.x_axis_labels>
</Axis.x_labels>

<.x_axis_grid_lines axis={@x_axis} step={5} start={@nearest_5_second} stroke="#D3D3D3" />
<.x_axis_grid_line axis={@x_axis} value={@x_axis.scale.first} stroke="#D3D3D3" />
<.x_axis_grid_line axis={@x_axis} value={@x_axis.scale.last} stroke="#D3D3D3" />
<Grid.vertical_lines axis={@x_axis} dimensions={@dimensions} step={5} start={@nearest_5_second} />

<%!-- vertical marker for "now" with a label --%>
<.x_axis_label axis={@x_axis} value={@now} position={:top} stroke="red">
Now ({Calendar.strftime(@now, "%-I:%M:%S")})
</.x_axis_label>
<%!-- draw left boundary of the graph --%>
<line
x1={graph_left(@dimensions)}
x2={graph_left(@dimensions)}
y1={graph_top(@dimensions)}
y2={graph_bottom(@dimensions)}
stroke="#D3D3D3"
/>

<.x_axis_grid_line axis={@x_axis} value={@now} stroke="red" />
<%!-- draw right boundary of the graph --%>
<line
x1={graph_right(@dimensions)}
x2={graph_right(@dimensions)}
y1={graph_top(@dimensions)}
y2={graph_bottom(@dimensions)}
stroke="#D3D3D3"
/>

<%!-- vertical marker for "now" with a label above the graph --%>
<text
x={@x_axis[@now]}
y={above_graph(@dimensions)}
dominant-baseline="text-bottom"
text-anchor="middle"
stroke="red"
>
({Calendar.strftime(@now, "%-I:%M:%S")})
</text>

<line
x1={@x_axis[@now]}
x2={@x_axis[@now]}
y1={graph_top(@dimensions)}
y2={graph_bottom(@dimensions)}
stroke="red"
/>

<.polyline points={points(@dataset1[:x], @dataset1[:y])} stroke="orange" stroke-width="2" />
<.polyline points={points(@dataset2[:x], @dataset2[:y])} stroke="blue" stroke-width="2" />
Expand Down
38 changes: 25 additions & 13 deletions examples/demo_live.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ defmodule DemoLive do

import Plox

alias Plox.Helpers.Axis
alias Plox.Helpers.Grid

@impl Phoenix.LiveView
def mount(_params, _session, socket) do
{:ok, mount_simple_line_graph(socket)}
Expand Down Expand Up @@ -69,22 +72,31 @@ defmodule DemoLive do
<h2>Example graph</h2>

<.graph dimensions={@dimensions}>
<.x_axis_labels :let={date} axis={@x_axis}>
<%!-- X-axis labels --%>
<Axis.x_labels :let={date} axis={@x_axis}>
{Calendar.strftime(date, "%-m/%-d")}
</.x_axis_labels>

<%!-- this wraps text... why does it take in `axis`?? if we want to follow the SVG, we need to pass in `x` --%>
<.x_axis_label axis={@x_axis} value={~D[2023-08-02]} position={:top} color="red">
{"Important Day"}
</.x_axis_label>

<.x_axis_grid_lines axis={@x_axis} stroke="#D3D3D3" />

<.y_axis_labels :let={value} axis={@y_axis} ticks={5}>
</Axis.x_labels>

<%!-- Add label for a specific date above the graph --%>
<text
x={@x_axis[~D[2023-08-02]]}
y={above_graph(@dimensions)}
dominant-baseline="text-bottom"
text-anchor="middle"
>
Important Day
</text>

<%!-- X-axis grid lines --%>
<Grid.vertical_lines axis={@x_axis} dimensions={@dimensions} ticks={5} />

<%!-- Y-axis labels --%>
<Axis.y_labels :let={value} axis={@y_axis} ticks={5}>
{value}
</.y_axis_labels>
</Axis.y_labels>

<.y_axis_grid_lines axis={@y_axis} ticks={5} stroke="#D3D3D3" />
<%!-- Y-axis grid lines --%>
<Grid.horizontal_lines axis={@y_axis} dimensions={@dimensions} ticks={5} />

<.polyline points={points(@dataset[:x], @dataset[:y])} stroke="orange" stroke-width={2} />

Expand Down
Loading