Creatomg specific elements for certain values in data
I am trying to create a table with d3js in node. For the table I'd like to create a column which is sort of a gantt chart. For that I need a svg element in the last column. But I am having difficulties understanding how I can run a function for the last column which use values for other columns and creates a svg element.
Code creating columns and rows:
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints);
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td") //<-- ?
At the let cells
is it possible to run a function on the .append("td") to place a svg element in the last column and run a function on that svg element constructing the visualization?
data looks like this:
dataPoints = [
{
"Task" : "A",
"Start": "Thu Dec 01 2011",
"Finish": Thu Dec 01 2012"
},
{
"Task" : "B",
"Start": "Thu Dec 01 2012",
"Finish": Thu Dec 01 2013"
}
]
Full Code:
module powerbi.extensibility.visual {
interface DataPoint {};
interface ViewModel {
dataPoints: DataPoint;
};
export class Visual implements IVisual {
private host: IVisualHost;
private svg: d3.Selection<SVGAElement>;
private barGroup: d3.Selection<SVGAElement>;
private divContainer: d3.Selection<HTMLDivElement>;
private table: d3.Selection<HTMLTableElement>;
private tbody: d3.Selection<HTMLTableRowElement>;
private thead: d3.Selection<HTMLTableHeaderCellElement>;
private HeadColumns = ;
constructor(options: VisualConstructorOptions) {
options.element.style.overflow = 'auto';
this.host = options.host;
this.divContainer = d3.select(options.element)
.append("div")
.classed("divContainer", true)
.attr("width", "100%")
.attr("height", "100%");
this.table = d3.select(".divContainer")
.append("table")
.classed("hello", true)
.style("background-color", "#72B6E7")
.attr("width", "100%")
.attr("height", "100%");
this.thead = d3.select("table")
.append("thead");
this.tbody = d3.select("table")
.append("tbody");
}
public update(options: VisualUpdateOptions) {
let ViewModel = this.getViewModel(options);
let width = options.viewport.width;
let height = options.viewport.height;
//Creates Header Column Names
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
//Creats Rows
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints)
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td")
.text(function (d) {
return d;
});
}
private getViewModel(options: VisualUpdateOptions): ViewModel {
let dv = options.dataViews;
let viewModel: ViewModel = {
dataPoints: ,
};
let Table = dv[0].table
let TableRows = Table.rows
let TableLen = Table.rows.length
let TableColumnNumber = Table.columns.length
let TableColumns =
this.HeadColumns = ;
for (let i = 0, len = TableColumnNumber; i < len; i++){
let tmp = {};
tmp["ColumnName"] = Table.columns[i].displayName;
this.HeadColumns.push(Table.columns[i].displayName);
TableColumns.push(tmp);
}
for (let i = 0, len = TableLen; i < len; i++){
var tmp_ = {};
for (let k = 0, len = TableColumns.length; k < len; k++){
tmp_[TableColumns[k].ColumnName] = <string>TableRows[i][k];
}
viewModel.dataPoints.push(tmp_);
}
return viewModel;
}
}
}
node.js d3.js powerbi
add a comment |
I am trying to create a table with d3js in node. For the table I'd like to create a column which is sort of a gantt chart. For that I need a svg element in the last column. But I am having difficulties understanding how I can run a function for the last column which use values for other columns and creates a svg element.
Code creating columns and rows:
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints);
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td") //<-- ?
At the let cells
is it possible to run a function on the .append("td") to place a svg element in the last column and run a function on that svg element constructing the visualization?
data looks like this:
dataPoints = [
{
"Task" : "A",
"Start": "Thu Dec 01 2011",
"Finish": Thu Dec 01 2012"
},
{
"Task" : "B",
"Start": "Thu Dec 01 2012",
"Finish": Thu Dec 01 2013"
}
]
Full Code:
module powerbi.extensibility.visual {
interface DataPoint {};
interface ViewModel {
dataPoints: DataPoint;
};
export class Visual implements IVisual {
private host: IVisualHost;
private svg: d3.Selection<SVGAElement>;
private barGroup: d3.Selection<SVGAElement>;
private divContainer: d3.Selection<HTMLDivElement>;
private table: d3.Selection<HTMLTableElement>;
private tbody: d3.Selection<HTMLTableRowElement>;
private thead: d3.Selection<HTMLTableHeaderCellElement>;
private HeadColumns = ;
constructor(options: VisualConstructorOptions) {
options.element.style.overflow = 'auto';
this.host = options.host;
this.divContainer = d3.select(options.element)
.append("div")
.classed("divContainer", true)
.attr("width", "100%")
.attr("height", "100%");
this.table = d3.select(".divContainer")
.append("table")
.classed("hello", true)
.style("background-color", "#72B6E7")
.attr("width", "100%")
.attr("height", "100%");
this.thead = d3.select("table")
.append("thead");
this.tbody = d3.select("table")
.append("tbody");
}
public update(options: VisualUpdateOptions) {
let ViewModel = this.getViewModel(options);
let width = options.viewport.width;
let height = options.viewport.height;
//Creates Header Column Names
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
//Creats Rows
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints)
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td")
.text(function (d) {
return d;
});
}
private getViewModel(options: VisualUpdateOptions): ViewModel {
let dv = options.dataViews;
let viewModel: ViewModel = {
dataPoints: ,
};
let Table = dv[0].table
let TableRows = Table.rows
let TableLen = Table.rows.length
let TableColumnNumber = Table.columns.length
let TableColumns =
this.HeadColumns = ;
for (let i = 0, len = TableColumnNumber; i < len; i++){
let tmp = {};
tmp["ColumnName"] = Table.columns[i].displayName;
this.HeadColumns.push(Table.columns[i].displayName);
TableColumns.push(tmp);
}
for (let i = 0, len = TableLen; i < len; i++){
var tmp_ = {};
for (let k = 0, len = TableColumns.length; k < len; k++){
tmp_[TableColumns[k].ColumnName] = <string>TableRows[i][k];
}
viewModel.dataPoints.push(tmp_);
}
return viewModel;
}
}
}
node.js d3.js powerbi
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of yourrows
, i.e. something likerows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.
– altocumulus
Nov 13 '18 at 13:02
add a comment |
I am trying to create a table with d3js in node. For the table I'd like to create a column which is sort of a gantt chart. For that I need a svg element in the last column. But I am having difficulties understanding how I can run a function for the last column which use values for other columns and creates a svg element.
Code creating columns and rows:
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints);
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td") //<-- ?
At the let cells
is it possible to run a function on the .append("td") to place a svg element in the last column and run a function on that svg element constructing the visualization?
data looks like this:
dataPoints = [
{
"Task" : "A",
"Start": "Thu Dec 01 2011",
"Finish": Thu Dec 01 2012"
},
{
"Task" : "B",
"Start": "Thu Dec 01 2012",
"Finish": Thu Dec 01 2013"
}
]
Full Code:
module powerbi.extensibility.visual {
interface DataPoint {};
interface ViewModel {
dataPoints: DataPoint;
};
export class Visual implements IVisual {
private host: IVisualHost;
private svg: d3.Selection<SVGAElement>;
private barGroup: d3.Selection<SVGAElement>;
private divContainer: d3.Selection<HTMLDivElement>;
private table: d3.Selection<HTMLTableElement>;
private tbody: d3.Selection<HTMLTableRowElement>;
private thead: d3.Selection<HTMLTableHeaderCellElement>;
private HeadColumns = ;
constructor(options: VisualConstructorOptions) {
options.element.style.overflow = 'auto';
this.host = options.host;
this.divContainer = d3.select(options.element)
.append("div")
.classed("divContainer", true)
.attr("width", "100%")
.attr("height", "100%");
this.table = d3.select(".divContainer")
.append("table")
.classed("hello", true)
.style("background-color", "#72B6E7")
.attr("width", "100%")
.attr("height", "100%");
this.thead = d3.select("table")
.append("thead");
this.tbody = d3.select("table")
.append("tbody");
}
public update(options: VisualUpdateOptions) {
let ViewModel = this.getViewModel(options);
let width = options.viewport.width;
let height = options.viewport.height;
//Creates Header Column Names
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
//Creats Rows
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints)
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td")
.text(function (d) {
return d;
});
}
private getViewModel(options: VisualUpdateOptions): ViewModel {
let dv = options.dataViews;
let viewModel: ViewModel = {
dataPoints: ,
};
let Table = dv[0].table
let TableRows = Table.rows
let TableLen = Table.rows.length
let TableColumnNumber = Table.columns.length
let TableColumns =
this.HeadColumns = ;
for (let i = 0, len = TableColumnNumber; i < len; i++){
let tmp = {};
tmp["ColumnName"] = Table.columns[i].displayName;
this.HeadColumns.push(Table.columns[i].displayName);
TableColumns.push(tmp);
}
for (let i = 0, len = TableLen; i < len; i++){
var tmp_ = {};
for (let k = 0, len = TableColumns.length; k < len; k++){
tmp_[TableColumns[k].ColumnName] = <string>TableRows[i][k];
}
viewModel.dataPoints.push(tmp_);
}
return viewModel;
}
}
}
node.js d3.js powerbi
I am trying to create a table with d3js in node. For the table I'd like to create a column which is sort of a gantt chart. For that I need a svg element in the last column. But I am having difficulties understanding how I can run a function for the last column which use values for other columns and creates a svg element.
Code creating columns and rows:
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints);
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td") //<-- ?
At the let cells
is it possible to run a function on the .append("td") to place a svg element in the last column and run a function on that svg element constructing the visualization?
data looks like this:
dataPoints = [
{
"Task" : "A",
"Start": "Thu Dec 01 2011",
"Finish": Thu Dec 01 2012"
},
{
"Task" : "B",
"Start": "Thu Dec 01 2012",
"Finish": Thu Dec 01 2013"
}
]
Full Code:
module powerbi.extensibility.visual {
interface DataPoint {};
interface ViewModel {
dataPoints: DataPoint;
};
export class Visual implements IVisual {
private host: IVisualHost;
private svg: d3.Selection<SVGAElement>;
private barGroup: d3.Selection<SVGAElement>;
private divContainer: d3.Selection<HTMLDivElement>;
private table: d3.Selection<HTMLTableElement>;
private tbody: d3.Selection<HTMLTableRowElement>;
private thead: d3.Selection<HTMLTableHeaderCellElement>;
private HeadColumns = ;
constructor(options: VisualConstructorOptions) {
options.element.style.overflow = 'auto';
this.host = options.host;
this.divContainer = d3.select(options.element)
.append("div")
.classed("divContainer", true)
.attr("width", "100%")
.attr("height", "100%");
this.table = d3.select(".divContainer")
.append("table")
.classed("hello", true)
.style("background-color", "#72B6E7")
.attr("width", "100%")
.attr("height", "100%");
this.thead = d3.select("table")
.append("thead");
this.tbody = d3.select("table")
.append("tbody");
}
public update(options: VisualUpdateOptions) {
let ViewModel = this.getViewModel(options);
let width = options.viewport.width;
let height = options.viewport.height;
//Creates Header Column Names
this.thead.selectAll("th")
.data(this.HeadColumns)
.enter()
.append("th")
.text(function(d) { return d; });
//Creats Rows
let rows = this.tbody.selectAll("tr")
.data(ViewModel.dataPoints)
rows.enter().append("tr");
rows.exit().remove();
let cells = rows.selectAll("td")
.data(function(row) {
return d3.map(row).values();
})
.enter()
.append("td")
.text(function (d) {
return d;
});
}
private getViewModel(options: VisualUpdateOptions): ViewModel {
let dv = options.dataViews;
let viewModel: ViewModel = {
dataPoints: ,
};
let Table = dv[0].table
let TableRows = Table.rows
let TableLen = Table.rows.length
let TableColumnNumber = Table.columns.length
let TableColumns =
this.HeadColumns = ;
for (let i = 0, len = TableColumnNumber; i < len; i++){
let tmp = {};
tmp["ColumnName"] = Table.columns[i].displayName;
this.HeadColumns.push(Table.columns[i].displayName);
TableColumns.push(tmp);
}
for (let i = 0, len = TableLen; i < len; i++){
var tmp_ = {};
for (let k = 0, len = TableColumns.length; k < len; k++){
tmp_[TableColumns[k].ColumnName] = <string>TableRows[i][k];
}
viewModel.dataPoints.push(tmp_);
}
return viewModel;
}
}
}
node.js d3.js powerbi
node.js d3.js powerbi
asked Nov 13 '18 at 11:33
Art Vandelay_Art Vandelay_
82
82
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of yourrows
, i.e. something likerows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.
– altocumulus
Nov 13 '18 at 13:02
add a comment |
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of yourrows
, i.e. something likerows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.
– altocumulus
Nov 13 '18 at 13:02
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of your
rows
, i.e. something like rows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.– altocumulus
Nov 13 '18 at 13:02
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of your
rows
, i.e. something like rows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.– altocumulus
Nov 13 '18 at 13:02
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280130%2fcreatomg-specific-elements-for-certain-values-in-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280130%2fcreatomg-specific-elements-for-certain-values-in-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Side note: if this is D3 v4 or v5 you need to merge the update and enter selections of your
rows
, i.e. something likerows = rows.enter().append("tr").merge(rows)
. Otherwise, you'll only be manipulating the updated rows leaving out the newly entered ones.– altocumulus
Nov 13 '18 at 13:02