Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a new Indicator? #504

Open
cswgr opened this issue May 10, 2022 · 1 comment
Open

How to add a new Indicator? #504

cswgr opened this issue May 10, 2022 · 1 comment

Comments

@cswgr
Copy link

cswgr commented May 10, 2022

I've read the docs, but in my project what happens is, that the following code just adds an additional DebugBar:

var debugbar = new PhpDebugBar.DebugBar();

debugbar.createIndicator('dbhost', 'cogs', 'connected db', 'right');

debugbar.setDataMap({
       'dbhost': ['time.duration_str', '0ms']
});

But of course I want to add the indicator to the existing bar.

What am I missing?

@parallels999
Copy link
Contributor

parallels999 commented Sep 27, 2023

Better on php collector with Renderable, and avoid adding js

var debugbar = new PhpDebugBar.DebugBar();

debugbar.createIndicator('dbhost_ind', 'cogs', 'connected db', 'right');

debugbar.setDataMap({
   'dbhost_ind': ['dbhost.duration_str', '0ms']
});

// Example adding dataset manually
debugbar.addDataSet({
    'dbhost': {'duration_str': '10ms'}
});

Your php colector must return

class DbHostCollector extends DataCollector /*implements Renderable*/
{
    /**
     * @return string
     */
    public function getName()
    {
        return 'dbhost';
    }

    /**
     * @return array
     */
    public function collect()
    {
        return array(
            'duration_str' => '10ms'
        );
    }

    // with Renderable `setDataMap` and `createIndicator` are not needed
    /*public function getWidgets()
    {
        return array(
            "dbhost_ind" => array(
                "icon" => "cogs",
                "tooltip" => "connected db",
                "map" => "dbhost.duration_str",
                "default" => "0ms"
            ),
        );
    }*/
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants