socialpredict icon indicating copy to clipboard operation
socialpredict copied to clipboard

Using d3.js for Chart Design

Open pwdel opened this issue 11 months ago • 11 comments

pwdel avatar Mar 02 '24 17:03 pwdel

https://github.com/DLabbate/stock-dashboard?tab=readme-ov-file

pwdel avatar Mar 02 '24 17:03 pwdel

Image

pwdel avatar Mar 02 '24 17:03 pwdel

Date Filter:

Image

pwdel avatar Mar 02 '24 17:03 pwdel

Rather than using rechart which is fairly limited and does not appear to have step charts, it seems like we should use:

https://github.com/AnyChart/AnyChart

re:

https://docs.anychart.com/Basic_Charts/Step_Line_Chart#:~:text=A%20step%20line%20chart%20is,or%20interest%20rates%20are%20visualized.

https://www.npmjs.com/package/anychart

Image

pwdel avatar Mar 05 '24 03:03 pwdel

Alternatively, d3 step chart:

https://codepen.io/vkbansal/pen/QjJXOe

Image

pwdel avatar Mar 05 '24 03:03 pwdel

Speaks to potential interactivity;

https://d3-graph-gallery.com/area

pwdel avatar Mar 05 '24 03:03 pwdel

Ok, here is what I was able to implement. How important is it to have:

  1. Tooltip which allows user to see exactly what the probability was at any given time?
  2. Capability to zoom in on past day, past week, past month, past year, all time?

Image

pwdel avatar Mar 05 '24 20:03 pwdel

d3 is a good choice.

I can see ticks will need to be adjusted. The usual trick is to add a selection with a resolution (1 min, 5 min, 1h, 1 day) and rescale to this.

In general, you'll need to pick a summary of what happened in a tick to draw it (mean price, hi/lo, close price, etc.). With this in mind, this particular graphic has one issue, which is that it moves in vertical steps -> visual language implies the odds have not moved for a while. This is not true in general.

jg-you avatar Mar 05 '24 20:03 jg-you

What do you mean by, "ticks" ?

Yes, I could add a change in resolution button, understood.

The step graph communicates that the probability changes instantaneously at the time of bet, which is effectively true.

FYI, here is the raw data from which this graph was derived:

https://github.com/openpredictionmarkets/socialpredict/blob/stylepage/frontend/src/tests/TestData.js#L23

    "probabilityChanges":[
        {"probability":0.5,"timestamp":"2023-11-11T04:59:00Z"},
        {"probability":0.9761904761904762,"timestamp":"2023-11-11T05:59:00Z"},
        {"probability":0.6612903225806451,"timestamp":"2023-11-11T06:14:00Z"},
        {"probability":0.7941176470588235,"timestamp":"2023-11-11T06:59:00Z"},
        {"probability":0.6639344262295082,"timestamp":"2023-11-11T07:14:00Z"}
    ],

So the graph is 100% reflecting that json array...e.g. the steps are not at the, "midpoint," but rather at the time of change.

Contrast this to our current graph which uses a rechart line graph, showing sloped changes between points. These sloped changes are misleading because they imply that the probability gradually changed over time rather than instantly.

image

If you are used to seeing a chart with a ton of volume, then it would look more like gradual changes over time, as the step functions from a zoomed out perspective look more, "smooth," ... if you would like I could generate data which shows this effect with our new step function chart here.

pwdel avatar Mar 05 '24 21:03 pwdel

Ticks = markers at the bottom, currently "11 Nov on repeat."

The flat style is accurate but crumbles when there are too many trades; it just becomes impossible to load.

The usual solution is to compute summary statistics and stick' em in line plot or area plot. Or to use financial charts like Candle sticks or Heiken Ashi.

jg-you avatar Mar 05 '24 21:03 jg-you

This was implemented but reverted to CanvasJS for the time being because 3ds has performance issues with larger datasets (over ~10000 points or so) and requires further calculations on the back end to be able to average out bins over time. Basically to make this scalable requires a lot more both back and front end design time.

pwdel avatar Mar 22 '24 12:03 pwdel