From 66ede597621e5a44bf37ec0bbabeb6fe8d97a81e Mon Sep 17 00:00:00 2001 From: Daniel Quathamer Date: Sat, 21 Jan 2023 19:32:17 +0100 Subject: [PATCH] Sankey Chart #6 --- .../sx_stylesheets_einfuegen_ba_ma_sankey.sql | 171 ++++++++++++++++++ superx/xml/30190_html_chart_sankey.xsl | 11 +- superx/xml/js/viz/sankey_v3.js | 19 +- superx/xml/viz_html_chart.xsl | 24 ++- 4 files changed, 215 insertions(+), 10 deletions(-) create mode 100755 src-modules/module/viz/schluesseltabellen/sx_stylesheets_einfuegen_ba_ma_sankey.sql diff --git a/src-modules/module/viz/schluesseltabellen/sx_stylesheets_einfuegen_ba_ma_sankey.sql b/src-modules/module/viz/schluesseltabellen/sx_stylesheets_einfuegen_ba_ma_sankey.sql new file mode 100755 index 0000000..c1f9d46 --- /dev/null +++ b/src-modules/module/viz/schluesseltabellen/sx_stylesheets_einfuegen_ba_ma_sankey.sql @@ -0,0 +1,171 @@ +--Freemarker Template +--Achtung: Macro fügt Inhalte ein +--Bitte nur Freemarker Variablen füllen + +<#assign masken = [ +{"mask":"30190", "filename":"30190_html_chart_sankey.xsl", "ord":"130"} +] /> + +<#assign stylesheet = [ +{"filename":"30190_html_chart_sankey.xsl", +"caption":"BA-MA Übergang Diagramm erzeugen", +"description":"Sankey-Diagramm", +"relation":"table", +"contenttype":"text/html", +"is_generic":"0" +} +] /> +<#assign stylesheet_field = [ + +] /> + +--Hier eventuell notwendige delete's auf die Tabellen sx_mask_style, sx_stylesheets oder stylesheet_field einfügen. + +--Achtung: ab hier nicht ändern, Mutterdatei ist $SUPERX_DIR/db/module/sos/schluesseltabellen/sx_stylesheets_fuellen.sql + <@sx_stylesheets_insert +m_masken=masken +m_stylesheet=stylesheet +m_stylesheet_field=stylesheet_field +/> + + +<#macro sx_stylesheets_insert m_masken m_stylesheet m_stylesheet_field> + +--Sicherstellen, dass keine Duplikate vorkommen: +--#################################################################################################### +<#foreach column in m_masken> +delete from sx_mask_style where maskeninfo_id=${column.mask} and stylesheet_id in (select tid from sx_stylesheets where filename ='${column.filename}') and ord=${column.ord}; + + +<#foreach column in m_stylesheet_field> +delete from stylesheet_field where stylesheet_id in (select tid from sx_stylesheets where filename ='${column.filename}'); + + + + + +-- Stylesheets füllen +--#################################################################################################### +create temp table tmp_stylesheets ( +tid serial not null, +filename CHAR(255) , +caption CHAR(255) , +description CHAR(255) , +relation CHAR(10) , +useragent CHAR(255) , +contenttype CHAR(200) , +is_generic smallint +); + +create temp table tmp_hilf (tid integer); +insert into tmp_hilf select max(tid) from sx_stylesheets; +update tmp_hilf set tid=1 where tid is null; + +<#assign counter_tid = 1 /> +<#foreach column in m_stylesheet> +insert into tmp_stylesheets (tid,filename,caption,description,relation,contenttype,is_generic) +select max(tid)+${counter_tid},'${column.filename}', +'${column.caption}', + '${column.description}', + '${column.relation}', +'${column.contenttype}', +${column.is_generic} +from tmp_hilf; +<#assign counter_tid = counter_tid + 1 /> + + +<#if TableFieldExists?exists && TableFieldExists('sx_stylesheets','is_generic')> +update sx_stylesheets set is_generic=1 +where filename in (select T.filename from tmp_stylesheets T where T.is_generic=1); + + + +--delete für tml_stylesheets hinzugefügt #ak 06.03.2013 +delete from tmp_stylesheets where filename in (select filename from sx_stylesheets); + + +insert into sx_stylesheets (tid, +filename, caption, description, relation, useragent, contenttype +<#if TableFieldExists?exists && TableFieldExists('sx_stylesheets','is_generic')> +,is_generic + +) +SELECT tid, filename, caption, description, relation, useragent, contenttype +<#if TableFieldExists?exists && TableFieldExists('sx_stylesheets','is_generic')> +,is_generic + +FROM tmp_stylesheets; + +drop table tmp_stylesheets; + + +-- Mask Style füllen +--#################################################################################################### +create temp table tmp_mask_style ( +tid serial not null, +maskeninfo_id INTEGER , +stylesheet_id INTEGER , +ord SMALLINT, +filename char(255) +); + +delete from tmp_hilf; +insert into tmp_hilf select max(tid) from sx_mask_style; +update tmp_hilf set tid=1 where tid is null; + +<#assign counter_tid = 1 /> +<#foreach column in m_masken> +insert into tmp_mask_style (tid,maskeninfo_id,ord,filename) +select max(tid)+${counter_tid},${column.mask},${column.ord},'${column.filename}' from tmp_hilf; + +update tmp_mask_style set stylesheet_id=(select max(tid) from sx_stylesheets where filename='${column.filename}') +where filename='${column.filename}'; +<#assign counter_tid = counter_tid + 1 /> + + +insert into sx_mask_style ( tid, maskeninfo_id, stylesheet_id, ord) +SELECT tid, maskeninfo_id, stylesheet_id, ord +FROM tmp_mask_style; + +drop table tmp_mask_style; + + +--Field zu Stylesheet Zuordnungen: +--#################################################################################################### +CREATE temp TABLE tmp_stylesheet_field +( +tid serial NOT NULL, +stylesheet_id INTEGER, +tablename char(255), +fieldname char(255), +filename char(255) +); + +delete from tmp_hilf; +insert into tmp_hilf select max(tid) from stylesheet_field; +update tmp_hilf set tid=1 where tid is null; + +<#assign counter_tid = 1 /> +<#foreach column in m_stylesheet_field> +INSERT INTO tmp_stylesheet_field (tid, filename, tablename, fieldname) +select max(tid)+${counter_tid}, '${column.filename}', '${column.tablename}', '${column.fieldname}' from tmp_hilf; + +update tmp_stylesheet_field set stylesheet_id=(select max(tid) from sx_stylesheets where filename='${column.filename}') +where filename='${column.filename}'; +<#assign counter_tid = counter_tid + 1 /> + + +insert into stylesheet_field ( tid, stylesheet_id, tablename, fieldname) +SELECT tid, stylesheet_id, tablename, fieldname +FROM tmp_stylesheet_field; + +drop table tmp_stylesheet_field; +drop table tmp_hilf; + +<#if SQLdialect='Postgres'> +select sp_update_sequence('sx_stylesheets'); +select sp_update_sequence('sx_mask_style'); +select sp_update_sequence('stylesheet_field'); + + + diff --git a/superx/xml/30190_html_chart_sankey.xsl b/superx/xml/30190_html_chart_sankey.xsl index 5c7ab26..953ecfa 100644 --- a/superx/xml/30190_html_chart_sankey.xsl +++ b/superx/xml/30190_html_chart_sankey.xsl @@ -81,7 +81,7 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:HtmlUtils="de.superx.util - + +

+ +
+ 
@@ -111,8 +115,7 @@ renderChart('chartDiv2',myChartModel); - + diff --git a/superx/xml/js/viz/sankey_v3.js b/superx/xml/js/viz/sankey_v3.js index 16f6401..ff9d257 100644 --- a/superx/xml/js/viz/sankey_v3.js +++ b/superx/xml/js/viz/sankey_v3.js @@ -63,18 +63,27 @@ var sLinks=getSankeyLinks(sNodes,data); //graph.links; .attr("class", "node") .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) - .call(d3.behavior.drag() + /*.call(d3.behavior.drag() .origin(function(d) { return d; }) .on("dragstart", function() { this.parentNode.appendChild(this); }) - .on("drag", dragmove)); + .on("drag", dragmove) + )*/ + ; // add the rectangles for the nodes node.append("rect") .attr("height", function(d) { return d.dy; }) .attr("width", sankey.nodeWidth()) .style("fill", function(d) { - return d.color = color(d.name.replace(/ .*/, "")); }) + //return d.color = color(d.name.replace(/ .*/, "")); + //return d3.scaleLinear().domain([0,3,10]).range(["blue","white","red"]); + var r = Math.floor(Math.random() * 255); + var g = Math.floor(Math.random() * 255); + var b = Math.floor(Math.random() * 255); + var col = "rgb(" + r + "," + g + "," + b + ")"; + return d.color = col; //"red"; + }) .style("stroke", function(d) { return d3.rgb(d.color).darker(2); }) .append("title") @@ -89,7 +98,7 @@ var sLinks=getSankeyLinks(sNodes,data); //graph.links; .attr("text-anchor", "end") .attr("transform", null) .text(function(d) { return d.name; }) - .filter(function(d) { return d.x < width / 2; }) + .filter(function(d) { return d.x < width / 2; }) .attr("x", 6 + sankey.nodeWidth()) .attr("text-anchor", "start"); @@ -207,7 +216,7 @@ function getMetadataOfVizTypeProperty(metaData,vizTypePropertyUniquename) function dragmove(d) { d3.select(this).attr("transform", "translate(" + d.x + "," + ( - d.y = Math.max(0, Math.min(height - d.dy, d3.event.y)) + d.y = Math.max(0, Math.min(d3.select(this).attr("height") - d.dy, d3.event.y)) ) + ")"); sankey.relayout(); link.attr("d", path); diff --git a/superx/xml/viz_html_chart.xsl b/superx/xml/viz_html_chart.xsl index 0a7c811..c5d5f23 100644 --- a/superx/xml/viz_html_chart.xsl +++ b/superx/xml/viz_html_chart.xsl @@ -275,7 +275,29 @@ vizTypeProperties.push(newVizTypeProperty);