Expose `umb-donut-chart` to use for pack...
# package-development
m
Anyone who has managed to reuse the
umb-donut-chart
in a v14-package? https://github.com/umbraco/Umbraco.CMS.Backoffice/issues/1832
a
I think I may have look at that in the past, but ended up just using Chart.js directly
m
Thanks! @Anders Bjerner "in the past" as in pre v14? Or did you look at it for v14?
a
Sorry - missed that part. Pre v14
w
Porbably got to pass the data as a property to the component in a certain format perhaps @Markus Johansson ?!
m
@Warren Buckley 😄 The chart is rendered if first to to the Log Viewer (to get the custom element registered) and then back to my element. So no problem with the markup, problem is that the element is lazy loaded in the Log Viewer but exported so as far as I understand there is no way for me to ensure it's registered before my custom element loads
w
Hmmm the storybook for it seems to work in isolation https://apidocs.umbraco.com/v14/ui/?path=/docs/umb-donut-chart--docs
@Warren Buckley the
.story.ts
file imports the element into the story so the element is registered when the story renders. In the scenario of using it in a extension there i now way to import it since it's not exported (as far as I understand)
m
@Warren Buckley do you mean that I should copy it? 😄
w
haha nah
m
haha 😄
I hope that someone from HQ looks at the issue I created, i think it's just a simple line to export the component so that it can be imported when needed. Not great if multiple packages would have to pull in 150k+ of chart.js
w
So your dashboard is just rendering with the child DOM for the slices in a render
It doesn't use chart.js
Its drawing a native pie chart with SVGs
m
The dashboard is reusing the donut chart from the Log Viewer
w
Old backoffice uses Chart.js for the charting - this is an isolated component
m
Yes, Chart.js is not shipped with the new backoffice
Yes, a Lit element shipped with the backoffice
I think that they wanted to avoid ChartJs as it's quite heavy
(not sure)
w
Probably
Will see if I can do a dashboard with a chart at lunchtime
And see what your running into
m
In my newsletter package I need other types of charts (line charts, bar charts etc) so in that case I had to use Chart.JS
but for this simple package it would be nice to avoid having to use ChartJs and just reuse the stuff that is already there.
w
Yeh of course
j
Seems like an oversight that the component isn't being exported from the log-viewer package (or simply being registered globally in the backoffice)
w
Yep can repro that I cant use it in dashboard
My super simple dashboard
Copy code
ts

import { LitElement, css, html, customElement} from "@umbraco-cms/backoffice/external/lit";
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";

@customElement('dashboard-chart')
export class DashboardChartElement extends UmbElementMixin(LitElement) {

    render() {
        return html`
            <uui-box headline="Dashboard with Pie Chart" style="margin:20px;">
                <p>Look at my chart</p>
                <umb-donut-chart description="Colors of fruits">
                    <umb-donut-slice color="red" name="Red" amount="10" kind="apples"></umb-donut-slice>
                    <umb-donut-slice color="green" name="Green" amount="20" kind="apples"></umb-donut-slice>
                    <umb-donut-slice color="yellow" name="Yellow" amount="10" kind="bananas"></umb-donut-slice>
                    <umb-donut-slice color="purple" name="Purple" amount="69" kind="plums"></umb-donut-slice>
                </umb-donut-chart>
            </uui-box>
        `;
    }
}

export default DashboardChartElement;

declare global {
  interface HTMLElementTagNameMap {
    'dashboard-chart': DashboardChartElement;
  }
}
If Jacob you havent done a PR I am sure me or Markus can
j
Yes, I think we could move this component out of the logviewer package, but as these things go, we are already loading a great deal of front. I'm thinking this could be a start of a "chart" package, that you could import when you need to.
I'm sure more chart-ish components would be needed in the future
w
I thought it would be in UUI library
j
Yeh, or that
w
But yeh some peope/packages need charts
Well I have no immediate need for it, but sounds like @Markus Johansson does
j
For now you could just make a PR that exports it from the log-viewer package. That way you can import it conditionally in your own package by
import '@umbraco-cms/backoffice/log-viewer';
eventually we'll move it to UUI to benefit everyone
w
Yeh will let @Markus Johansson take the PR claim as I have no direct need right now
m
@Jacob Overgaard I'll make that PR, sounds like a pragmatic solution
Thanks @Jacob Overgaard !
3 Views