Custom activity charts

This was a fantastic skeleton, thanks

added to the intervals chart as background zones

will add to the 30 min block chart (but colour the bars) shortly

4 Likes

If someone has time and skills, I would love to get the kilometers spent per Gratient custom cart (e.g. 10km above 8% grade, 5km above 10% grade etc.)

1 Like

I’m looking for something similar

In my case, I want to put the VAM in perspective of zones, for example, how long the athlete stays in each ascent measure divided by 100 units.

2 Likes

Some types of charts only make sense for certain types of activities (e.g. run activities, activities with power, activities with at least one interval, activities with certain custom streams etc.).

Perhaps there should be a way to signal “don’t draw this chart for this activity”. Either simply not setting a value for chart or setting a value containing a reason - or error message.

(posted in the wrong thread first, so now I have to put some more text so they’re not similar)

Thats a good idea. If the script does not return a value or returns null then the chart is hidden completely when displayed on an activity. Unfortunately you can’t use “return” in these scripts without defining a function and invoking it:

function chart() {
  if (true) return // not the right type of activity or whatever
  // your chart code
  return { data: [], layout: { title: { "Hello" } } }
}
chart()

If you are editing the chart script then you will see “Script did not return a value object” instead of just blank.

1 Like

I’ve been using labeled blocks to get around that, and around excessive nesting - see break in labeled blocks.

I think the function approach is a bit less exotic but this seems to work too. I’m not sure how you’ve implemented the sandbox so not sure if there’s any advantages to any approach.

I didn’t know about those, thanks:

out: {
  if (true) break out; // not the right type of activity or whatever
  // your chart code
  let chart = { data: [] }
  chart
}
1 Like

This also creates unexpected behaviour as Plotly disregards Text values in the x-array when numbers are present. If some work intervals do not have a label, only those will be plotted and the intervals with a text label will not be shown.
I haven’t found a way yet to tell Plotly that it needs to interpret the whole x-array as text values, so I came up with this intermediate solution:

x.push("°" + (iv.label ? c + "-" + iv.label : c))

The ° sign as first character, makes sure that all values in the x-array are considered as text values.
image

You can remove that and just include this in the layout options:

layout = {
  ...
  xaxis:{"type": "category"}
}
1 Like

Thanks for that tip!
Works like a charm.