@@ -6,20 +6,200 @@ import * as configApi from '../../config';
6
6
import addSVGAccessibilityFields from '../../accessibility' ;
7
7
8
8
let conf = configApi . getConfig ( ) ;
9
-
10
9
/**
11
- * Draws a Pie Chart with the data given in text.
10
+ * Draws a Bar Chart with the data given in text.
12
11
*
13
12
* @param text
13
+ * @param txt
14
14
* @param id
15
+ * @param _version
16
+ * @param diagObj
15
17
*/
18
+ // export const drawBarChart = (txt, id, _version, diagObj) => {
19
+ // try {
20
+ // let locDiagType;
21
+
22
+ // conf = configApi.getConfig();
23
+ // log.debug('Rendering info diagram\n' + txt);
24
+ // locDiagType = diagObj.db.getDiagramType();
25
+ // const securityLevel = configApi.getConfig().securityLevel;
26
+ // // Handle root and Document for when rendering in sandbox mode
27
+ // let sandboxElement;
28
+ // if (securityLevel === 'sandbox') {
29
+ // sandboxElement = select('#i' + id);
30
+ // }
31
+ // const root =
32
+ // securityLevel === 'sandbox'
33
+ // ? select(sandboxElement.nodes()[0].contentDocument.body)
34
+ // : select('body');
35
+ // const doc = securityLevel === 'sandbox' ? sandboxElement.nodes()[0].contentDocument : document;
36
+
37
+ // // Parse the Pie Chart definition
38
+ // diagObj.db.clear();
39
+ // diagObj.parser.parse(txt);
40
+ // log.debug('Parsed info diagram');
41
+ // const elem = doc.getElementById(id);
42
+ // width = elem.parentElement.offsetWidth;
43
+
44
+ // if (typeof width === 'undefined') {
45
+ // width = 1200;
46
+ // }
47
+
48
+ // if (typeof conf.useWidth !== 'undefined') {
49
+ // width = conf.useWidth;
50
+ // }
51
+ // if (typeof conf.pie.useWidth !== 'undefined') {
52
+ // width = conf.pie.useWidth;
53
+ // }
54
+
55
+ // const diagram = root.select('#' + id);
56
+ // configureSvgSize(diagram, height, width, conf.pie.useMaxWidth);
57
+
58
+ // addSVGAccessibilityFields(diagObj.db, diagram, id);
59
+ // // Set viewBox
60
+ // elem.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
61
+
62
+ // // Fetch the default direction, use TD if none was found
63
+ // var margin = 40;
64
+ // var legendRectSize = 18;
65
+ // var legendSpacing = 4;
66
+
67
+ // var radius = Math.min(width, height) / 2 - margin;
68
+
69
+ // var svg = diagram
70
+ // .append('g')
71
+ // .attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')');
72
+
73
+ // var data = diagObj.db.getSections();
74
+ // var sum = 0;
75
+ // Object.keys(data).forEach(function (key) {
76
+ // sum += data[key];
77
+ // });
78
+
79
+ // const themeVariables = conf.themeVariables;
80
+ // var myGeneratedColors = [
81
+ // themeVariables.pie1,
82
+ // themeVariables.pie2,
83
+ // themeVariables.pie3,
84
+ // themeVariables.pie4,
85
+ // themeVariables.pie5,
86
+ // themeVariables.pie6,
87
+ // themeVariables.pie7,
88
+ // themeVariables.pie8,
89
+ // themeVariables.pie9,
90
+ // themeVariables.pie10,
91
+ // themeVariables.pie11,
92
+ // themeVariables.pie12,
93
+ // ];
94
+
95
+ // // Set the color scale
96
+ // var color = scaleOrdinal().range(myGeneratedColors);
97
+
98
+ // // Compute the position of each group on the pie:
99
+ // var pieData = Object.entries(data).map(function (el, idx) {
100
+ // return {
101
+ // order: idx,
102
+ // name: el[0],
103
+ // value: el[1],
104
+ // };
105
+ // });
106
+ // var pie = d3pie()
107
+ // .value(function (d) {
108
+ // return d.value;
109
+ // })
110
+ // .sort(function (a, b) {
111
+ // // Sort slices in clockwise direction
112
+ // return a.order - b.order;
113
+ // });
114
+ // var dataReady = pie(pieData);
115
+
116
+ // // Shape helper to build arcs:
117
+ // var arcGenerator = arc().innerRadius(0).outerRadius(radius);
118
+
119
+ // // Build the pie chart: each part of the pie is a path that we build using the arc function.
120
+ // svg
121
+ // .selectAll('mySlices')
122
+ // .data(dataReady)
123
+ // .enter()
124
+ // .append('path')
125
+ // .attr('d', arcGenerator)
126
+ // .attr('fill', function (d) {
127
+ // return color(d.data.name);
128
+ // })
129
+ // .attr('class', 'pieCircle');
130
+
131
+ // // Now add the percentage.
132
+ // // Use the centroid method to get the best coordinates.
133
+ // svg
134
+ // .selectAll('mySlices')
135
+ // .data(dataReady)
136
+ // .enter()
137
+ // .append('text')
138
+ // .text(function (d) {
139
+ // return ((d.data.value / sum) * 100).toFixed(0) + '%';
140
+ // })
141
+ // .attr('transform', function (d) {
142
+ // return 'translate(' + arcGenerator.centroid(d) + ')';
143
+ // })
144
+ // .style('text-anchor', 'middle')
145
+ // .attr('class', 'slice');
146
+
147
+ // svg
148
+ // .append('text')
149
+ // .text(diagObj.db.getDiagramTitle())
150
+ // .attr('x', 0)
151
+ // .attr('y', -(height - 50) / 2)
152
+ // .attr('class', 'pieTitleText');
153
+
154
+ // // Add the legends/annotations for each section
155
+ // var legend = svg
156
+ // .selectAll('.legend')
157
+ // .data(color.domain())
158
+ // .enter()
159
+ // .append('g')
160
+ // .attr('class', 'legend')
161
+ // .attr('transform', function (d, i) {
162
+ // var height = legendRectSize + legendSpacing;
163
+ // var offset = (height * color.domain().length) / 2;
164
+ // var horz = 12 * legendRectSize;
165
+ // var vert = i * height - offset;
166
+ // return 'translate(' + horz + ',' + vert + ')';
167
+ // });
168
+
169
+ // legend
170
+ // .append('rect')
171
+ // .attr('width', legendRectSize)
172
+ // .attr('height', legendRectSize)
173
+ // .style('fill', color)
174
+ // .style('stroke', color);
175
+
176
+ // legend
177
+ // .data(dataReady)
178
+ // .append('text')
179
+ // .attr('x', legendRectSize + legendSpacing)
180
+ // .attr('y', legendRectSize - legendSpacing)
181
+ // .text(function (d) {
182
+ // if (diagObj.db.getShowData() || conf.showData || conf.pie.showData) {
183
+ // return d.data.name + ' [' + d.data.value + ']';
184
+ // } else {
185
+ // return d.data.name;
186
+ // }
187
+ // });
188
+ // } catch (e) {
189
+ // log.error('Error while rendering info diagram');
190
+ // log.error(e);
191
+ // }
192
+ // };
193
+
16
194
let width ;
17
195
const height = 450 ;
18
196
export const draw = ( txt , id , _version , diagObj ) => {
19
197
try {
198
+ let locDiagType ;
199
+
20
200
conf = configApi . getConfig ( ) ;
21
201
log . debug ( 'Rendering info diagram\n' + txt ) ;
22
-
202
+ locDiagType = diagObj . db . getDiagramType ( ) ;
23
203
const securityLevel = configApi . getConfig ( ) . securityLevel ;
24
204
// Handle root and Document for when rendering in sandbox mode
25
205
let sandboxElement ;
@@ -191,4 +371,5 @@ export const draw = (txt, id, _version, diagObj) => {
191
371
192
372
export default {
193
373
draw,
374
+ // drawBarChart,
194
375
} ;
0 commit comments