@politicalwatch/tipi-uikit 1.7.9 → 1.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@politicalwatch/tipi-uikit",
3
- "version": "1.7.9",
3
+ "version": "1.7.10",
4
4
  "main": "src/components/index.js",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -1,9 +1,9 @@
1
- import d3chart from "../d3.chart";
2
- import { select, selectAll } from "d3-selection";
3
- import { scaleBand, scaleLinear, scaleOrdinal } from "d3-scale";
4
- import { max } from "d3-array";
5
- import { transition } from "d3-transition";
6
- import { axisBottom, axisLeft } from "d3-axis";
1
+ import d3chart from '../d3.chart';
2
+ import { select, selectAll } from 'd3-selection';
3
+ import { scaleBand, scaleLinear, scaleOrdinal } from 'd3-scale';
4
+ import { max } from 'd3-array';
5
+ import { transition } from 'd3-transition';
6
+ import { axisBottom, axisLeft } from 'd3-axis';
7
7
  import {
8
8
  easeLinear,
9
9
  easePolyIn,
@@ -41,8 +41,8 @@ import {
41
41
  easeBounceIn,
42
42
  easeBounce,
43
43
  easeBounceOut,
44
- easeBounceInOut
45
- } from "d3-ease";
44
+ easeBounceInOut,
45
+ } from 'd3-ease';
46
46
  import {
47
47
  schemeCategory10,
48
48
  schemeAccent,
@@ -53,8 +53,8 @@ import {
53
53
  schemeSet1,
54
54
  schemeSet2,
55
55
  schemeSet3,
56
- schemeTableau10
57
- } from "d3-scale-chromatic";
56
+ schemeTableau10,
57
+ } from 'd3-scale-chromatic';
58
58
 
59
59
  const d3 = {
60
60
  select,
@@ -112,13 +112,13 @@ const d3 = {
112
112
  schemeSet1,
113
113
  schemeSet2,
114
114
  schemeSet3,
115
- schemeTableau10
115
+ schemeTableau10,
116
116
  };
117
117
 
118
- import pluralize from "pluralize";
118
+ import pluralize from 'pluralize';
119
119
 
120
- const REFERENCE = "Texto de referencia";
121
- const SCANNED = "Texto escaneado";
120
+ const REFERENCE = 'Texto de referencia';
121
+ const SCANNED = 'Texto escaneado';
122
122
 
123
123
  /**
124
124
  * D3 Bar Chart
@@ -127,30 +127,30 @@ class d3barchart extends d3chart {
127
127
  constructor(selection, data, config) {
128
128
  super(selection, data, config, {
129
129
  margin: { top: 10, right: 30, bottom: 20, left: 40 },
130
- key: "key",
130
+ key: 'key',
131
131
  currentKey: false,
132
132
  values: [],
133
- orientation: "vertical",
133
+ orientation: 'vertical',
134
134
  labelRotation: 0,
135
135
  color: {
136
136
  key: false,
137
137
  keys: false,
138
138
  scheme: false,
139
- current: "#1f77b4",
140
- default: "#AAA",
141
- axis: "#000"
139
+ current: '#1f77b4',
140
+ default: '#AAA',
141
+ axis: '#000',
142
142
  },
143
143
  axis: {
144
144
  yTitle: false,
145
145
  xTitle: false,
146
- yFormat: ".0f",
147
- xFormat: ".0f",
146
+ yFormat: '.0f',
147
+ xFormat: '.0f',
148
148
  yTicks: 10,
149
- xTicks: 10
149
+ xTicks: 10,
150
150
  },
151
151
  tooltip: { label: false, suffix: false, suffixPlural: false },
152
152
  keys: { [SCANNED]: SCANNED, [REFERENCE]: REFERENCE },
153
- transition: { duration: 350, ease: "easeLinear" }
153
+ transition: { duration: 350, ease: 'easeLinear' },
154
154
  });
155
155
  }
156
156
 
@@ -160,7 +160,7 @@ class d3barchart extends d3chart {
160
160
  initChart() {
161
161
  // Set up dimensions
162
162
  this.getDimensions();
163
- this.initChartFrame("barchart");
163
+ this.initChartFrame('barchart');
164
164
 
165
165
  if (this.cfg.tooltip.suffix && this.cfg.tooltip.suffixPlural) {
166
166
  pluralize.addIrregularRule(this.cfg.tooltip.suffix, this.cfg.tooltip.suffixPlural);
@@ -172,23 +172,23 @@ class d3barchart extends d3chart {
172
172
  this.yScale = d3.scaleLinear();
173
173
 
174
174
  // Axis group
175
- this.axisg = this.g.append("g").attr("class", "chart__axis chart__axis--barchart");
175
+ this.axisg = this.g.append('g').attr('class', 'chart__axis chart__axis--barchart');
176
176
 
177
177
  // Horizontal grid
178
178
  this.yGrid = this.axisg
179
- .append("g")
180
- .attr("class", "chart__grid chart__grid--y chart__grid--barchart");
179
+ .append('g')
180
+ .attr('class', 'chart__grid chart__grid--y chart__grid--barchart');
181
181
 
182
182
  // Bottom axis
183
- this.xAxis = this.axisg.append("g").attr("class", "chart__axis-x chart__axis-x--barchart");
183
+ this.xAxis = this.axisg.append('g').attr('class', 'chart__axis-x chart__axis-x--barchart');
184
184
 
185
185
  // Vertical axis title
186
186
  if (this.cfg.axis.yTitle)
187
187
  this.yAxisTitle = this.axisg
188
- .append("text")
189
- .attr("class", "chart__axis-title chart__axis-title--barchart")
190
- .attr("transform", "rotate(-90)")
191
- .style("text-anchor", "middle");
188
+ .append('text')
189
+ .attr('class', 'chart__axis-title chart__axis-title--barchart')
190
+ .attr('transform', 'rotate(-90)')
191
+ .style('text-anchor', 'middle');
192
192
 
193
193
  this.setChartDimension();
194
194
  this.updateChart();
@@ -200,10 +200,10 @@ class d3barchart extends d3chart {
200
200
  setScales() {
201
201
  this.xScale
202
202
  .rangeRound(
203
- this.cfg.orientation !== "horizontal" ? [0, this.cfg.width] : [0, this.cfg.height]
203
+ this.cfg.orientation !== 'horizontal' ? [0, this.cfg.width] : [0, this.cfg.height]
204
204
  )
205
205
  .paddingInner(0.1)
206
- .domain(this.data.map(d => d[this.cfg.key]));
206
+ .domain(this.data.map((d) => d[this.cfg.key]));
207
207
 
208
208
  this.xScaleInn
209
209
  .domain(this.cfg.values)
@@ -213,18 +213,18 @@ class d3barchart extends d3chart {
213
213
  const yMax = this.calculateBiggestNumber();
214
214
  this.yScale
215
215
  .rangeRound(
216
- this.cfg.orientation !== "horizontal" ? [0, this.cfg.height] : [this.cfg.width, 0]
216
+ this.cfg.orientation !== 'horizontal' ? [0, this.cfg.height] : [this.cfg.width, 0]
217
217
  )
218
218
  .domain([yMax, 0]);
219
219
 
220
220
  if (this.cfg.color.scheme instanceof Array === true) {
221
221
  this.colorScale = d3.scaleOrdinal().range(this.cfg.color.scheme);
222
- } else if (typeof this.cfg.color.scheme === "string") {
222
+ } else if (typeof this.cfg.color.scheme === 'string') {
223
223
  this.colorScale = d3.scaleOrdinal(d3[this.cfg.color.scheme]);
224
224
  }
225
225
 
226
226
  const yGridFunction =
227
- this.cfg.orientation !== "horizontal"
227
+ this.cfg.orientation !== 'horizontal'
228
228
  ? d3
229
229
  .axisLeft(this.yScale)
230
230
  .tickSize(-this.cfg.width)
@@ -235,13 +235,13 @@ class d3barchart extends d3chart {
235
235
  .ticks(this.cfg.axis.yTicks, this.cfg.axis.yFormat);
236
236
 
237
237
  const xAxisFunction =
238
- this.cfg.orientation !== "horizontal" ? d3.axisBottom(this.xScale) : d3.axisLeft(this.xScale);
238
+ this.cfg.orientation !== 'horizontal' ? d3.axisBottom(this.xScale) : d3.axisLeft(this.xScale);
239
239
 
240
240
  // Horizontal grid
241
241
  this.yGrid
242
242
  .attr(
243
- "transform",
244
- this.cfg.orientation !== "horizontal" ? "translate(0,0)" : `translate(0,${this.cfg.height})`
243
+ 'transform',
244
+ this.cfg.orientation !== 'horizontal' ? 'translate(0,0)' : `translate(0,${this.cfg.height})`
245
245
  )
246
246
  .transition(this.transition)
247
247
  .call(yGridFunction);
@@ -249,8 +249,8 @@ class d3barchart extends d3chart {
249
249
  // Bottom axis
250
250
  this.xAxis
251
251
  .attr(
252
- "transform",
253
- this.cfg.orientation !== "horizontal" ? `translate(0,${this.cfg.height})` : "translate(0,0)"
252
+ 'transform',
253
+ this.cfg.orientation !== 'horizontal' ? `translate(0,${this.cfg.height})` : 'translate(0,0)'
254
254
  )
255
255
  .call(xAxisFunction);
256
256
  }
@@ -262,30 +262,30 @@ class d3barchart extends d3chart {
262
262
  // SVG element
263
263
  this.svg
264
264
  .attr(
265
- "viewBox",
266
- `0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${this.cfg.height +
267
- this.cfg.margin.top +
268
- this.cfg.margin.bottom}`
265
+ 'viewBox',
266
+ `0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${
267
+ this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom
268
+ }`
269
269
  )
270
- .attr("width", this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
271
- .attr("height", this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
270
+ .attr('width', this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
271
+ .attr('height', this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
272
272
 
273
273
  // Vertical axis title
274
274
  if (this.cfg.axis.yTitle)
275
275
  this.yAxisTitle
276
- .attr("y", -this.cfg.margin.left + 10)
277
- .attr("x", -this.cfg.height / 2)
276
+ .attr('y', -this.cfg.margin.left + 10)
277
+ .attr('x', -this.cfg.height / 2)
278
278
  .text(this.cfg.axis.yTitle);
279
279
 
280
280
  // Bottom axis label rotation
281
281
  if (this.cfg.labelRotation !== 0)
282
282
  this.xAxis
283
- .selectAll("text")
284
- .attr("y", Math.cos((this.cfg.labelRotation * Math.PI) / 180) * 9)
285
- .attr("x", Math.sin((this.cfg.labelRotation * Math.PI) / 180) * 9)
286
- .attr("dy", ".35em")
287
- .attr("transform", `rotate(${this.cfg.labelRotation})`)
288
- .style("text-anchor", "start");
283
+ .selectAll('text')
284
+ .attr('y', Math.cos((this.cfg.labelRotation * Math.PI) / 180) * 9)
285
+ .attr('x', Math.sin((this.cfg.labelRotation * Math.PI) / 180) * 9)
286
+ .attr('dy', '.35em')
287
+ .attr('transform', `rotate(${this.cfg.labelRotation})`)
288
+ .style('text-anchor', 'start');
289
289
  }
290
290
 
291
291
  /**
@@ -294,17 +294,17 @@ class d3barchart extends d3chart {
294
294
  bindData() {
295
295
  // Set transition
296
296
  this.transition = d3
297
- .transition("t")
297
+ .transition('t')
298
298
  .duration(this.cfg.transition.duration)
299
299
  .ease(d3[this.cfg.transition.ease]);
300
300
 
301
301
  // Bars groups
302
- this.g.selectAll(".chart__bar-group").remove();
303
- this.itemg = this.g.selectAll(".chart__bar-group").data(this.data, d => d[this.cfg.key]);
302
+ this.g.selectAll('.chart__bar-group').remove();
303
+ this.itemg = this.g.selectAll('.chart__bar-group').data(this.data, (d) => d[this.cfg.key]);
304
304
  }
305
305
 
306
306
  hasComparissionData() {
307
- return this.data.some(item => item[REFERENCE] > 0);
307
+ return this.data.some((item) => item[REFERENCE] > 0);
308
308
  }
309
309
 
310
310
  calculateTotals() {
@@ -369,43 +369,44 @@ class d3barchart extends d3chart {
369
369
 
370
370
  const newbars = this.itemg
371
371
  .enter()
372
- .append("g")
373
- .attr("class", "chart__bar-group chart__bar-group--barchart")
374
- .attr("transform", d => {
375
- if (this.cfg.orientation !== "horizontal") {
372
+ .append('g')
373
+ .attr('class', 'chart__bar-group chart__bar-group--barchart')
374
+ .attr('transform', (d) => {
375
+ if (this.cfg.orientation !== 'horizontal') {
376
376
  return `translate(${this.xScale(d[this.cfg.key])},0)`;
377
377
  }
378
378
  return `translate(0,${this.xScale(d[this.cfg.key])})`;
379
379
  });
380
380
 
381
381
  const rects = newbars
382
- .selectAll(".chart__bar")
383
- .data(d =>
384
- this.cfg.values.map(v => {
382
+ .selectAll('.chart__bar')
383
+ .data((d) =>
384
+ this.cfg.values.map((v) => {
385
385
  const dat = { ...d };
386
386
  dat[this.cfg.key] = d[this.cfg.key];
387
387
  return dat;
388
388
  })
389
389
  )
390
390
  .enter()
391
- .append("rect")
392
- .attr("class", "chart__bar chart__bar--barchart")
393
- .classed("chart__bar--current", d => {
391
+ .append('rect')
392
+ .attr('class', 'chart__bar chart__bar--barchart')
393
+ .classed('chart__bar--current', (d) => {
394
394
  return this.cfg.currentKey && d[this.cfg.key] === this.cfg.currentKey;
395
395
  })
396
- .attr("x", (d, i) => {
397
- return this.cfg.orientation !== "horizontal"
396
+ .attr('x', (d, i) => {
397
+ return this.cfg.orientation !== 'horizontal'
398
398
  ? this.xScaleInn(this.cfg.values[i % this.cfg.values.length])
399
399
  : 0;
400
400
  })
401
- .attr("y", (d, i) => {
402
- return this.cfg.orientation !== "horizontal"
401
+ .attr('y', (d, i) => {
402
+ return this.cfg.orientation !== 'horizontal'
403
403
  ? this.cfg.height
404
404
  : this.xScaleInn(this.cfg.values[i % this.cfg.values.length]);
405
405
  })
406
- .attr("height", 0)
407
- .attr("width", 0)
408
- .on("mouseover", (d, i) => {
406
+ .attr('height', 0)
407
+ .attr('width', 0)
408
+ .on('mouseover', (d, i) => {
409
+ console.log('MOUSEOVER in barchart', d);
409
410
  const key = this.cfg.values[i % this.cfg.values.length];
410
411
  const label = this.cfg.tooltip.suffixPlural
411
412
  ? pluralize(this.cfg.tooltip.suffix, d[key])
@@ -418,15 +419,15 @@ class d3barchart extends d3chart {
418
419
  const text = this.cfg.tooltip.suffix
419
420
  ? `<div>${labelKey}: ${percentage}% ${label}</div>`
420
421
  : `<div>${labelKey}: ${percentage}%</div>`;
421
- this.tooltip.html(text).classed("active", true);
422
+ this.tooltip.html(text).classed('active', true);
422
423
  })
423
- .on("mouseout", () => {
424
- this.tooltip.classed("active", false);
424
+ .on('mouseout', () => {
425
+ this.tooltip.classed('active', false);
425
426
  })
426
- .on("mousemove", () => {
427
+ .on('mousemove', () => {
427
428
  this.tooltip
428
- .style("left", window.event["pageX"] - 28 + "px")
429
- .style("top", window.event["pageY"] - 40 + "px");
429
+ .style('left', window.event['pageX'] - 28 + 'px')
430
+ .style('top', window.event['pageY'] - 40 + 'px');
430
431
  });
431
432
  }
432
433
 
@@ -437,37 +438,37 @@ class d3barchart extends d3chart {
437
438
  const totals = this.calculateTotals();
438
439
 
439
440
  // Bars groups
440
- this.itemg.transition(this.transition).attr("transform", d => {
441
- return this.cfg.orientation !== "horizontal"
441
+ this.itemg.transition(this.transition).attr('transform', (d) => {
442
+ return this.cfg.orientation !== 'horizontal'
442
443
  ? `translate(${this.xScale(d[this.cfg.key])},0)`
443
444
  : `translate(0,${this.xScale(d[this.cfg.key])})`;
444
445
  });
445
446
  // Bars
446
447
  this.g
447
- .selectAll(".chart__bar")
448
+ .selectAll('.chart__bar')
448
449
  .transition(this.transition)
449
- .attr("fill", (d, i) => this.colorElement(d, this.cfg.values[i % this.cfg.values.length]))
450
- .attr("opacity", (d, i) => (i % 2 == 1 && this.hasComparissionData() ? 0.6 : 1))
451
- .attr("x", (d, i) => {
452
- return this.cfg.orientation !== "horizontal"
450
+ .attr('fill', (d, i) => this.colorElement(d, this.cfg.values[i % this.cfg.values.length]))
451
+ .attr('opacity', (d, i) => (i % 2 == 1 && this.hasComparissionData() ? 0.6 : 1))
452
+ .attr('x', (d, i) => {
453
+ return this.cfg.orientation !== 'horizontal'
453
454
  ? this.xScaleInn(this.cfg.values[i % this.cfg.values.length])
454
455
  : 0;
455
456
  })
456
- .attr("y", (d, i) => {
457
- return this.cfg.orientation !== "horizontal"
457
+ .attr('y', (d, i) => {
458
+ return this.cfg.orientation !== 'horizontal'
458
459
  ? this.yScale(+d[this.cfg.values[i % this.cfg.values.length]])
459
460
  : this.xScaleInn(this.cfg.values[i % this.cfg.values.length]);
460
461
  })
461
- .attr("width", (d, i) => {
462
+ .attr('width', (d, i) => {
462
463
  const key = this.cfg.values[i % this.cfg.values.length];
463
464
  const percentage = this.calculatePercentage(d[key], totals[key]);
464
465
 
465
- return this.cfg.orientation !== "horizontal"
466
+ return this.cfg.orientation !== 'horizontal'
466
467
  ? this.xScaleInn.bandwidth()
467
468
  : this.yScale(percentage);
468
469
  })
469
- .attr("height", (d, i) => {
470
- return this.cfg.orientation !== "horizontal"
470
+ .attr('height', (d, i) => {
471
+ return this.cfg.orientation !== 'horizontal'
471
472
  ? this.cfg.height - this.yScale(+d[this.cfg.values[i % this.cfg.values.length]])
472
473
  : this.xScaleInn.bandwidth();
473
474
  });
@@ -477,11 +478,7 @@ class d3barchart extends d3chart {
477
478
  * Remove chart's elements without data
478
479
  */
479
480
  exitElements() {
480
- this.itemg
481
- .exit()
482
- .transition(this.transition)
483
- .style("opacity", 0)
484
- .remove();
481
+ this.itemg.exit().transition(this.transition).style('opacity', 0).remove();
485
482
  }
486
483
  }
487
484
 
@@ -1,229 +1,334 @@
1
1
  import d3chart from '../d3.chart';
2
- import {select, selectAll} from 'd3-selection';
3
- import {scaleLinear, scaleOrdinal} from 'd3-scale';
4
- import {max, min, sum} from 'd3-array';
5
- import {pie, arc} from 'd3-shape';
6
- import {transition} from 'd3-transition';
7
- import {interpolate} from 'd3-interpolate';
8
- import {easeLinear, easePolyIn, easePolyOut, easePoly,
9
- easePolyInOut, easeQuadIn, easeQuadOut, easeQuad, easeQuadInOut,
10
- easeCubicIn, easeCubicOut, easeCubic, easeCubicInOut, easeSinIn,
11
- easeSinOut, easeSin, easeSinInOut, easeExpIn, easeExpOut, easeExp,
12
- easeExpInOut, easeCircleIn, easeCircleOut, easeCircle, easeCircleInOut,
13
- easeElasticIn, easeElastic, easeElasticOut, easeElasticInOut, easeBackIn,
14
- easeBackOut, easeBack, easeBackInOut, easeBounceIn, easeBounce,
15
- easeBounceOut, easeBounceInOut} from 'd3-ease';
16
- import {schemeCategory10, schemeAccent, schemeDark2, schemePaired,
17
- schemePastel1, schemePastel2, schemeSet1, schemeSet2, schemeSet3,
18
- schemeTableau10} from 'd3-scale-chromatic';
2
+ import { select, selectAll } from 'd3-selection';
3
+ import { scaleLinear, scaleOrdinal } from 'd3-scale';
4
+ import { max, min, sum } from 'd3-array';
5
+ import { pie, arc } from 'd3-shape';
6
+ import { transition } from 'd3-transition';
7
+ import { interpolate } from 'd3-interpolate';
8
+ import {
9
+ easeLinear,
10
+ easePolyIn,
11
+ easePolyOut,
12
+ easePoly,
13
+ easePolyInOut,
14
+ easeQuadIn,
15
+ easeQuadOut,
16
+ easeQuad,
17
+ easeQuadInOut,
18
+ easeCubicIn,
19
+ easeCubicOut,
20
+ easeCubic,
21
+ easeCubicInOut,
22
+ easeSinIn,
23
+ easeSinOut,
24
+ easeSin,
25
+ easeSinInOut,
26
+ easeExpIn,
27
+ easeExpOut,
28
+ easeExp,
29
+ easeExpInOut,
30
+ easeCircleIn,
31
+ easeCircleOut,
32
+ easeCircle,
33
+ easeCircleInOut,
34
+ easeElasticIn,
35
+ easeElastic,
36
+ easeElasticOut,
37
+ easeElasticInOut,
38
+ easeBackIn,
39
+ easeBackOut,
40
+ easeBack,
41
+ easeBackInOut,
42
+ easeBounceIn,
43
+ easeBounce,
44
+ easeBounceOut,
45
+ easeBounceInOut,
46
+ } from 'd3-ease';
47
+ import {
48
+ schemeCategory10,
49
+ schemeAccent,
50
+ schemeDark2,
51
+ schemePaired,
52
+ schemePastel1,
53
+ schemePastel2,
54
+ schemeSet1,
55
+ schemeSet2,
56
+ schemeSet3,
57
+ schemeTableau10,
58
+ } from 'd3-scale-chromatic';
19
59
 
20
- const d3 = {select, selectAll, scaleLinear, scaleOrdinal, max, min, sum, transition, pie, arc, interpolate,
21
- easeLinear, easePolyIn, easePolyOut, easePoly, easePolyInOut, easeQuadIn, easeQuadOut,
22
- easeQuad, easeQuadInOut, easeCubicIn, easeCubicOut, easeCubic, easeCubicInOut,
23
- easeSinIn, easeSinOut, easeSin, easeSinInOut, easeExpIn, easeExpOut, easeExp,
24
- easeExpInOut, easeCircleIn, easeCircleOut, easeCircle, easeCircleInOut,
25
- easeElasticIn, easeElastic, easeElasticOut, easeElasticInOut, easeBackIn,
26
- easeBackOut, easeBack, easeBackInOut, easeBounceIn, easeBounce, easeBounceOut,
27
- easeBounceInOut, schemeCategory10, schemeAccent, schemeDark2, schemePaired,
28
- schemePastel1, schemePastel2, schemeSet1, schemeSet2, schemeSet3,
29
- schemeTableau10};
60
+ const d3 = {
61
+ select,
62
+ selectAll,
63
+ scaleLinear,
64
+ scaleOrdinal,
65
+ max,
66
+ min,
67
+ sum,
68
+ transition,
69
+ pie,
70
+ arc,
71
+ interpolate,
72
+ easeLinear,
73
+ easePolyIn,
74
+ easePolyOut,
75
+ easePoly,
76
+ easePolyInOut,
77
+ easeQuadIn,
78
+ easeQuadOut,
79
+ easeQuad,
80
+ easeQuadInOut,
81
+ easeCubicIn,
82
+ easeCubicOut,
83
+ easeCubic,
84
+ easeCubicInOut,
85
+ easeSinIn,
86
+ easeSinOut,
87
+ easeSin,
88
+ easeSinInOut,
89
+ easeExpIn,
90
+ easeExpOut,
91
+ easeExp,
92
+ easeExpInOut,
93
+ easeCircleIn,
94
+ easeCircleOut,
95
+ easeCircle,
96
+ easeCircleInOut,
97
+ easeElasticIn,
98
+ easeElastic,
99
+ easeElasticOut,
100
+ easeElasticInOut,
101
+ easeBackIn,
102
+ easeBackOut,
103
+ easeBack,
104
+ easeBackInOut,
105
+ easeBounceIn,
106
+ easeBounce,
107
+ easeBounceOut,
108
+ easeBounceInOut,
109
+ schemeCategory10,
110
+ schemeAccent,
111
+ schemeDark2,
112
+ schemePaired,
113
+ schemePastel1,
114
+ schemePastel2,
115
+ schemeSet1,
116
+ schemeSet2,
117
+ schemeSet3,
118
+ schemeTableau10,
119
+ };
30
120
 
31
121
  /**
32
- * D3 Slices Chart
33
- */
34
- class d3sliceschart extends d3chart{
122
+ * D3 Slices Chart
123
+ */
124
+ class d3sliceschart extends d3chart {
125
+ constructor(selection, data, config) {
126
+ super(selection, data, config, {
127
+ margin: { top: 40, right: 20, bottom: 40, left: 20 },
128
+ key: '',
129
+ value: 'value',
130
+ color: {
131
+ key: false,
132
+ keys: false,
133
+ scheme: false,
134
+ current: '#1f77b4',
135
+ default: '#AAA',
136
+ axis: '#000',
137
+ },
138
+ radius: { inner: false, outter: false, padding: 0, round: 0 },
139
+ transition: { duration: 350, ease: 'easeLinear' },
140
+ });
141
+ }
35
142
 
36
- constructor(selection, data, config) {
37
- super(selection, data, config, {
38
- margin: {top: 40, right: 20, bottom: 40, left: 20},
39
- key: '',
40
- value: 'value',
41
- color : {key: false, keys: false, scheme: false, current: '#1f77b4', default: '#AAA', axis: '#000'},
42
- radius: {inner: false, outter: false, padding: 0, round: 0},
43
- transition: {duration: 350, ease: 'easeLinear'},
44
- });
45
- }
143
+ /**
144
+ * Init chart
145
+ */
146
+ initChart() {
147
+ // Set up dimensions
148
+ this.getDimensions();
149
+ this.initChartFrame('sliceschart');
46
150
 
47
- /**
48
- * Init chart
49
- */
50
- initChart() {
151
+ this.cScale = d3.scaleOrdinal();
152
+ this.rScale = d3.scaleLinear();
153
+ this.arc = d3.arc();
154
+ this.pie = d3
155
+ .pie()
156
+ .sort(null)
157
+ .value(() => 1)
158
+ .padAngle(this.cfg.radius.padding);
51
159
 
52
- // Set up dimensions
53
- this.getDimensions();
54
- this.initChartFrame('sliceschart');
160
+ if (this.cfg.radius && this.cfg.radius.inner) {
161
+ const outRadius = this.cfg.radius.outter
162
+ ? this.cfg.radius.outter
163
+ : Math.min(this.cfg.width, this.cfg.height) / 2;
164
+ this.cfg.radius.relation = this.cfg.radius.inner ? this.cfg.radius.inner / outRadius : 0;
165
+ }
55
166
 
56
- this.cScale = d3.scaleOrdinal();
57
- this.rScale = d3.scaleLinear();
58
- this.arc = d3.arc();
59
- this.pie = d3.pie()
60
- .sort(null)
61
- .value(() => 1)
62
- .padAngle(this.cfg.radius.padding);
167
+ this.gcenter = this.g.append('g');
168
+ this.setChartDimension();
169
+ this.updateChart();
63
170
 
64
- if(this.cfg.radius && this.cfg.radius.inner){
65
- const outRadius = this.cfg.radius.outter ? this.cfg.radius.outter : Math.min(this.cfg.width, this.cfg.height) / 2;
66
- this.cfg.radius.relation = this.cfg.radius.inner
67
- ? this.cfg.radius.inner / outRadius
68
- : 0;
69
- }
171
+ this.centerText = this.g
172
+ .append('text')
173
+ .attr('x', this.cfg.width / 2)
174
+ .attr('y', this.cfg.height / 2 + 10)
175
+ .attr('text-anchor', 'middle');
176
+ }
70
177
 
71
- this.gcenter = this.g.append('g');
72
- this.setChartDimension();
73
- this.updateChart();
178
+ /**
179
+ * Set up chart dimensions (non depending on data)
180
+ */
181
+ setChartDimension() {
182
+ // SVG element
183
+ this.svg
184
+ .attr(
185
+ 'viewBox',
186
+ `0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom}`
187
+ )
188
+ .attr('width', this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
189
+ .attr('height', this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
74
190
 
75
- this.centerText = this.g.append('text')
76
- .attr('x', this.cfg.width / 2)
77
- .attr('y', (this.cfg.height / 2) + 10)
78
- .attr('text-anchor', 'middle');
79
- }
191
+ // Center element
192
+ this.gcenter.attr('transform', `translate(${this.cfg.width / 2}, ${this.cfg.height / 2})`);
193
+ }
80
194
 
81
- /**
82
- * Set up chart dimensions (non depending on data)
83
- */
84
- setChartDimension(){
85
- // SVG element
86
- this.svg
87
- .attr("viewBox", `0 0 ${this.cfg.width+this.cfg.margin.left+this.cfg.margin.right} ${this.cfg.height+this.cfg.margin.top+this.cfg.margin.bottom}`)
88
- .attr("width", this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
89
- .attr("height", this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
90
-
91
- // Center element
92
- this.gcenter
93
- .attr('transform', `translate(${this.cfg.width/2}, ${this.cfg.height/2})`);
94
- }
195
+ /**
196
+ * Bind data to main elements groups
197
+ */
198
+ bindData() {
199
+ this.itemg = this.gcenter
200
+ .selectAll('.chart__slice-group')
201
+ .data(this.pie(this.data), (d) => d.data[this.cfg.key]);
95
202
 
96
- /**
97
- * Bind data to main elements groups
98
- */
99
- bindData(){
100
- this.itemg = this.gcenter.selectAll('.chart__slice-group')
101
- .data(this.pie(this.data), d => d.data[this.cfg.key]);
203
+ // Set transition
204
+ this.transition = d3
205
+ .transition('t')
206
+ .duration(this.cfg.transition.duration)
207
+ .ease(d3[this.cfg.transition.ease]);
208
+ }
102
209
 
103
- // Set transition
104
- this.transition = d3.transition('t')
105
- .duration(this.cfg.transition.duration)
106
- .ease(d3[this.cfg.transition.ease]);
210
+ /**
211
+ * Set up scales
212
+ */
213
+ setScales() {
214
+ // Set up radius
215
+ this.cfg.radius.outter =
216
+ this.cfg.radius && this.cfg.radius.outter
217
+ ? this.cfg.radius.outter
218
+ : Math.min(this.cfg.width, this.cfg.height) / 2;
219
+ this.inRadius = this.cfg.radius && this.cfg.radius.inner ? this.cfg.radius.inner : 0;
220
+ if (this.cfg.radius.relation) {
221
+ this.inRadius = this.cfg.radius.outter * this.cfg.radius.relation;
107
222
  }
108
223
 
109
- /**
110
- * Set up scales
111
- */
112
- setScales(){
224
+ // Set up arcs
225
+ this.arc = d3
226
+ .arc()
227
+ .outerRadius(this.cfg.radius.outter)
228
+ .innerRadius(this.inRadius)
229
+ .cornerRadius(this.cfg.radius.round);
113
230
 
114
- // Set up radius
115
- this.cfg.radius.outter = this.cfg.radius && this.cfg.radius.outter ? this.cfg.radius.outter : Math.min(this.cfg.width, this.cfg.height) / 2;
116
- this.inRadius = this.cfg.radius && this.cfg.radius.inner ? this.cfg.radius.inner : 0;
117
- if(this.cfg.radius.relation){
118
- this.inRadius = this.cfg.radius.outter * this.cfg.radius.relation;
119
- }
120
-
121
- // Set up arcs
122
- this.arc = d3.arc()
123
- .outerRadius(this.cfg.radius.outter)
124
- .innerRadius(this.inRadius)
125
- .cornerRadius(this.cfg.radius.round);
126
-
127
- let max = d3.max(this.data, d => d[this.cfg.value]);
128
- if (max == 0) {
129
- max = 1;
130
- }
231
+ let max = d3.max(this.data, (d) => d[this.cfg.value]);
232
+ if (max == 0) {
233
+ max = 1;
234
+ }
131
235
 
132
- this.rScale
133
- .range([this.inRadius, this.cfg.radius.outter])
134
- .domain([0, max]);
236
+ this.rScale.range([this.inRadius, this.cfg.radius.outter]).domain([0, max]);
135
237
 
136
- // Set up color scheme
137
- if(this.cfg.color.scheme){
138
- if(this.cfg.color.scheme instanceof Array === true){
139
- this.colorScale = d3.scaleOrdinal()
140
- .domain(this.data.map(d=>d[this.cfg.key]))
141
- .range(this.cfg.color.scheme);
142
- }else{
143
- this.colorScale = d3.scaleOrdinal(d3[this.cfg.color.scheme])
144
- .domain(this.data.map(d=>d[this.cfg.key]));
145
- }
146
- }
238
+ // Set up color scheme
239
+ if (this.cfg.color.scheme) {
240
+ if (this.cfg.color.scheme instanceof Array === true) {
241
+ this.colorScale = d3
242
+ .scaleOrdinal()
243
+ .domain(this.data.map((d) => d[this.cfg.key]))
244
+ .range(this.cfg.color.scheme);
245
+ } else {
246
+ this.colorScale = d3
247
+ .scaleOrdinal(d3[this.cfg.color.scheme])
248
+ .domain(this.data.map((d) => d[this.cfg.key]));
249
+ }
147
250
  }
251
+ }
148
252
 
149
- /**
150
- * Add new chart's elements
151
- */
152
- enterElements(){
253
+ /**
254
+ * Add new chart's elements
255
+ */
256
+ enterElements() {
257
+ const newg = this.itemg
258
+ .enter()
259
+ .append('g')
260
+ .attr('class', 'chart__slice-group chart__slice-group--sliceschart');
153
261
 
154
- const newg = this.itemg
155
- .enter().append('g')
156
- .attr("class", "chart__slice-group chart__slice-group--sliceschart");
262
+ // BACKGROUNDS
263
+ newg
264
+ .append('path')
265
+ .attr('class', 'chart__slice chart__slice--sliceschart')
266
+ //.on('mouseover', (d, i) => {
267
+ // const key = d.data[this.cfg.key];
268
+ // const value = d.data[this.cfg.value];
269
+ // this.tooltip.html(() => {
270
+ // return `<div>${key}: ${value}</div>`;
271
+ // })
272
+ // .classed('active', true);
273
+ //})
274
+ //.on('mouseout', () => {
275
+ // this.tooltip.classed('active', false);
276
+ //})
277
+ //.on('mousemove', () => {
278
+ // this.tooltip
279
+ // .style('left', window.event['pageX'] - 28 + 'px')
280
+ // .style('top', window.event['pageY'] - 40 + 'px');
281
+ //})
282
+ .on('mouseover', (d, i) => {
283
+ console.log('MOUSEOVER in sliceschart', d);
284
+ const total = d3.sum(this.data, (d) => d.value);
285
+ const value = d.data.value > 0 && total > 0 ? Math.round((d.data.value / total) * 100) : 0;
286
+ const key = d.data[this.cfg.key];
287
+ this.centerText.text(`${key}: ${value}%`);
288
+ })
289
+ .on('mouseout', () => {
290
+ this.centerText.text('');
291
+ })
292
+ .transition(this.transition)
293
+ .delay((d, i) => i * this.cfg.transition.duration)
294
+ .attrTween('d', (d) => {
295
+ const i = d3.interpolate(d.startAngle + 0.1, d.endAngle);
296
+ return (t) => {
297
+ d.endAngle = i(t);
298
+ return this.arc(d);
299
+ };
300
+ })
301
+ .style('fill', (d) => this.cfg.color.default)
302
+ .style('opacity', 1);
157
303
 
158
- // BACKGROUNDS
159
- newg.append("path")
160
- .attr("class", "chart__slice chart__slice--sliceschart")
161
- //.on('mouseover', (d, i) => {
162
- // const key = d.data[this.cfg.key];
163
- // const value = d.data[this.cfg.value];
164
- // this.tooltip.html(() => {
165
- // return `<div>${key}: ${value}</div>`;
166
- // })
167
- // .classed('active', true);
168
- //})
169
- //.on('mouseout', () => {
170
- // this.tooltip.classed('active', false);
171
- //})
172
- //.on('mousemove', () => {
173
- // this.tooltip
174
- // .style('left', window.event['pageX'] - 28 + 'px')
175
- // .style('top', window.event['pageY'] - 40 + 'px');
176
- //})
177
- .on('mouseover', (d, i) => {
178
- const total = d3.sum(this.data, d => d.value);
179
- const value = d.data.value > 0 && total > 0
180
- ? Math.round((d.data.value / total)*100)
181
- : 0;
182
- const key = d.data[this.cfg.key];
183
- this.centerText.text(`${key}: ${value}%`);
184
- })
185
- .on('mouseout', () => {
186
- this.centerText.text('');
187
- })
188
- .transition(this.transition)
189
- .delay((d,i) => i * this.cfg.transition.duration)
190
- .attrTween('d', d => {
191
- const i = d3.interpolate(d.startAngle+0.1, d.endAngle);
192
- return t => {
193
- d.endAngle = i(t);
194
- return this.arc(d);
195
- };
196
- })
197
- .style("fill", d=> this.cfg.color.default)
198
- .style('opacity', 1);
304
+ // FILLS
305
+ newg
306
+ .append('path')
307
+ .attr('class', 'chart__slice chart__slice--sliceschart')
308
+ .transition(this.transition)
309
+ .delay((d, i) => i * this.cfg.transition.duration)
310
+ .attrTween('d', (d) => {
311
+ const i = d3.interpolate(d.startAngle + 0.1, d.endAngle);
312
+ const arc = d3
313
+ .arc()
314
+ .outerRadius(this.rScale(d.data[this.cfg.value]))
315
+ .innerRadius(this.inRadius)
316
+ .cornerRadius(this.cfg.radius.round);
317
+ return (t) => {
318
+ d.endAngle = i(t);
319
+ return arc(d);
320
+ };
321
+ })
322
+ .style('fill', (d) => this.colorElement(d.data))
323
+ .style('pointer-events', 'none')
324
+ .style('opacity', 1);
325
+ }
199
326
 
200
- // FILLS
201
- newg.append("path")
202
- .attr("class", "chart__slice chart__slice--sliceschart")
203
- .transition(this.transition)
204
- .delay((d,i) => i * this.cfg.transition.duration)
205
- .attrTween('d', d => {
206
- const i = d3.interpolate(d.startAngle+0.1, d.endAngle);
207
- const arc = d3.arc()
208
- .outerRadius(this.rScale(d.data[this.cfg.value]))
209
- .innerRadius(this.inRadius)
210
- .cornerRadius(this.cfg.radius.round);
211
- return t => {
212
- d.endAngle = i(t);
213
- return arc(d);
214
- };
215
- })
216
- .style("fill", d=> this.colorElement(d.data))
217
- .style('pointer-events', 'none')
218
- .style('opacity', 1);
219
-
220
- }
221
-
222
- /**
223
- * Update chart's elements based on data change
224
- */
225
- updateElements(){
226
- /*
327
+ /**
328
+ * Update chart's elements based on data change
329
+ */
330
+ updateElements() {
331
+ /*
227
332
  // PATHS
228
333
  this.itemg.selectAll(".chart__slice")
229
334
  .style('opacity', 0)
@@ -233,40 +338,36 @@ class d3sliceschart extends d3chart{
233
338
  .attrTween('d', d => {
234
339
  const i = d3.interpolate(d.startAngle+0.1, d.endAngle);
235
340
  return t => {
236
- d.endAngle = i(t);
341
+ d.endAngle = i(t);
237
342
  return this.arc(d)
238
343
  }
239
344
  })
240
345
  .style("fill", this.cfg.color.default)
241
346
  .style('opacity', 1);
242
347
  */
243
- }
244
-
245
- /**
246
- * Remove chart's elements without data
247
- */
248
- exitElements(){
249
- this.itemg.exit()
250
- .transition(this.transition)
251
- .style("opacity", 0)
252
- .remove();
253
- }
348
+ }
254
349
 
255
- midAngle(d){
256
- return d.startAngle + (d.endAngle - d.startAngle)/2;
257
- }
350
+ /**
351
+ * Remove chart's elements without data
352
+ */
353
+ exitElements() {
354
+ this.itemg.exit().transition(this.transition).style('opacity', 0).remove();
355
+ }
258
356
 
259
- /**
260
- * Store the displayed angles in _current.
261
- * Then, interpolate from _current to the new angles.
262
- * During the transition, _current is updated in-place by d3.interpolate.
263
- */
264
- arcTween(a) {
265
- var i = d3.interpolate(this._current, a);
266
- this._current = i(0);
267
- return (t) => this.arc(i(t)) ;
268
- }
357
+ midAngle(d) {
358
+ return d.startAngle + (d.endAngle - d.startAngle) / 2;
359
+ }
269
360
 
361
+ /**
362
+ * Store the displayed angles in _current.
363
+ * Then, interpolate from _current to the new angles.
364
+ * During the transition, _current is updated in-place by d3.interpolate.
365
+ */
366
+ arcTween(a) {
367
+ var i = d3.interpolate(this._current, a);
368
+ this._current = i(0);
369
+ return (t) => this.arc(i(t));
370
+ }
270
371
  }
271
372
 
272
373
  export default d3sliceschart;
@@ -258,6 +258,7 @@ class d3wordscloud extends d3chart {
258
258
  .attr('fill', (d) => d.color)
259
259
  .attr('transform', (d) => `translate(${[d.x, d.y]})rotate(${d.rotate})`)
260
260
  .on('mouseover', (d) => {
261
+ console.log('MOUSEOVER in wordscoud', d);
261
262
  const label = this.cfg.tooltip.suffixPlural
262
263
  ? pluralize(this.cfg.tooltip.suffix, d.value)
263
264
  : this.cfg.tooltip.suffix;