Hello team, can you share the code for this plugin...
# gooddata-ui
m
r
Hi Mustafa, Radek here 🙂 We're currently doing some checks on the plugin code and making sure that it is up to date and ready to be shared, I will keep you posted!
m
Hi Radek, thank you very, looking forward to it
Hey Radek is there any progress about the plugin, we are still waiting for it
r
Hi Mustafa, apologies for the delay - this turned out to be a little more complicated than originally expected. The plugin has been added to the documentation relatively recently, and there's a process involving multiple we have to go through to be able to share it. Please accept my apologies for the delays, I've also requested the documentation to be updated to reflect this better!
m
Thanks for clarification, the thing is what i need right now is just a reference implementation showing how can i manipulate filters of an existing widget. So if you have metric selector plugin code that would be very helpful for as well
r
Thank you for the details! I'll have a look, I think I can point you in the right direction pretty quickly, I'll come back to you 🙂
m
thank you very much!
m
Hello Mustafa, the time-granularity-switch does not change filter, it changes the attribute slicing a metric. Specifically it changes trendBy of LineChart - https://www.gooddata.com/docs/gooddata-ui/latest/references/visual_components/line_chart/. 1. Dropdown allows users to select a date granularity. 2.
trendBy
state is updated based on the selection. 3. The
LineChart
re-renders with the updated
trendBy
value. The Chart switch does something similar and changes different properties of the visual components. Please let me know if it helped.
If you are interested in a plugin, I can connect you with our professional services team who can implement it for you.
m
Hi Martin, I actually tried to change trendBy in plugin but for some reason it did not work, my guess is code for mutating trendBy and return a new one does not work but I am not sure. > If you are interested in a plugin, I can connect you with our professional services team who can implement it for you. That would be great or it would be equally awesome if you can provide us example code that can chage granularity
👍 1
m
For the implementation I recommend starting with a simple LineChart (see GoodData LineChart Documentation). If it renders well, then continue to implement changing the
trendBy
attribute. To enable changing the
trendBy
attribute in your LineChart based on a dropdown selection, you need to introduce state management using React
useState
hook. Initialize a state variable for
trendBy
with a default value, create a dropdown menu that lists the available date granularities, and update the
trendBy
state when the user selects a different option. By passing this state variable to the LineChart as the
trendBy
prop, the chart will automatically re-render to reflect the new date granularity whenever the state changes.
Copy code
const exampleLineChart = () => {
    const [trendBy, setTrendBy] = useState(Md.DateMonth.Short);

....
Then write a handler for the dropdown to call
setTrendBy
with the selected value. Add a dropdown in the return statement and set its
onChange
to this handler. Finally, render the
LineChart
, passing
trendBy
as a prop.
m
Hey Martin thanks for reply, but looks like what you are explaning is how to change state of a new chart what we need to be able to change granularity of existing charts as a plugin, if i understood correctly we need to use
withCustomProvider
or
withCustomDecorator
, get the existing plugin state and modify it?
m
You are right, let me look into that.
Yes, you need to use the
withCustomProvider
to customize or better to say to replace an insight with a custom one providing the functionality you need. You can get some inspiration here: https://github.com/gooddata/gooddata-dashboard-plugins/blob/master/radial_bar_chart_plugin/src/dp_radial_bar_chart_plugin/Plugin.tsx#L29
🙌 1
I recommend to check code of this plugin, the concept used can be used also for creating the plugin providing changing of the date granularity for linecharts.