plotly.rs icon indicating copy to clipboard operation
plotly.rs copied to clipboard

`Marker.color_array` doesn't support `Vec<f64>` anymore?

Open Ionizing opened this issue 2 years ago • 2 comments

Hi,

I just updated the dependencies of my tiny tool rsgrad, and found there are some breaking change related to color in plotly-rs. The ColorWrapper was removed, and the method impl Color for f64 was also removed. This means I have to transform Vec<f64> to Vec<impl Color> manually, which is rather fussy (I have to write a function to transform f64 to Box<dyn Color> according to each given ColorScalePallete). However, there are still marker.cmin(), marker.cmid() and marker.cmax() methods in API document, the question is do them change anything?

In the latest version of plotly-rs(0.8.3), I have no idea on how to assign the colors for each point in a trace like before (for example, the last fig of ncl bandstructure just used this feature). The examples in plotly-rs book are obsolete, while the large_data_sets in examples/basic_charts/src/main.rs just removes the support of color_array. All these changes just prevented me from adapting the new API of plotly, especially the 'new features' related to color.

So my question is could you please add an example on how to feed marker.color_array() with Vec<f64> or something like that to the documents?

Ionizing avatar Mar 10 '23 07:03 Ionizing

@Ionizing , does PR #155 made by @tectin0 fix your problem?

andrei-ng avatar Jun 19 '24 14:06 andrei-ng

@Ionizing , does PR #155 made by @tectin0 fix your problem?

Hi, thanks for the reply and PR. I'm busy working on other things these weeks. I'll try it next month when I have spare time.

Anyway, thanks for your reply and the PR.

Ionizing avatar Jun 19 '24 14:06 Ionizing

Migration done

Hi, I just migrated to the latest plotly.rs (v0.9.0) without much effort. Thanks for the job. The implementation of Color trait on String helped a lot, which means I can just simply remove my CustomColor wrapper over the deprecated ColorWrapper and use String directly as color. I really appreciate it.

Other issue

However, after the migration, I find something unexpected:

  1. The height of the graph seems to be fixed to several px instead of 100% of browser window;
  2. The redraw on resize function is broken, I have to refresh the page after the resize to get the graph rendered with new width.

Here are two HTML files: dos.zip

  • the old one is produced by old plotly.rs with plotly.js of v2.2.1;
  • the new one is produced by the latest plotly.rs with plotly.js of v2.12.1.

My machine:

  • macOS 13.5.1 (x86_64)
  • Chrome 127.0.6533.99 Official Build x86_64

Advice

Besides, I have an advice (just an advice, if not feasible, I can just maintain a fork with my own modifications):

The .width method of Bar is Option<usize>, while it is a float number in plotly.js. In some situation, we may need to display bar chart within a curve plot like this: image and it's useful to let user specify a proper barwidth to show well. In fact I forked and tried, and everything worked well. I know it may be unreasonable to make this (breaking) change, so this is only my tiny advice.

The original HTML file of the screenshot is enclosed here: tdm_smeared.zip

Thanks again and look forward to you reply!

Ionizing avatar Aug 10 '24 15:08 Ionizing