Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
az2451
Resolver I
Resolver I

How does D3 Object function pbi.dsv work? JavaScript colon functions

Im struggling to understand the following code because i dont know which function sends/gets which paramaters from where and why:

 

 

pbi.dsv ( 

function(letters) { x.domain(letters.map(function(d) { return d.letter; })); y.domain([0, d3.max(letters, function(d) { return d.frequency; })]); svg.append("g")
... }

);

 

 

The object:

 

 

var pbi = {
width:1200, ... , dsv:function(accessor, callback) {
data = [ ... ]; if (arguments.length > 2) { callback=accessor,accessor = null; } else { data = data.map(function(d) {return accessor(d)}); } callback(data); } }

 

 

So which function is called first?

I know that pbi.dsv(...) calls the function from the object pbi.dsv:function (accessor, callback) { ... } and also retrieves the data from it.

 

But from where the parameters accessor and callback are filled? Does it get the data from PowerBI itself?

 

What exactly happens in this step. Which data fills the variable letters? Is it the result of pbi.dsv:function (accessor, callback) { ... }?

 

pbi.dsv(function(letters) { ... });

 

I couldnt find any documentation which explains this kind of functions to me and how they exactly work. I only understand that this would for example show an alert with the message "Hello". But still doesnt get how they work when parameters are filled inside the functions head. 

 

 

var obj = {
    test: function() {
        alert('Hello');
    }
};

obj.test();

 

I would thank You very much if you can explain me the syntax or a good website which explains it.

 

1 ACCEPTED SOLUTION
v-viig
Community Champion
Community Champion

The dsv function will execute accessor first for each item of original data array.

After that, the callback will be executed. The callback will receive the data array.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

View solution in original post

1 REPLY 1
v-viig
Community Champion
Community Champion

The dsv function will execute accessor first for each item of original data array.

After that, the callback will be executed. The callback will receive the data array.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors