@websy/websy-designs 1.4.37 → 1.5.0

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.
@@ -6550,6 +6550,7 @@ class WebsyChart {
6550
6550
  lineWidth: 2,
6551
6551
  forceZero: true,
6552
6552
  grouping: 'grouped',
6553
+ groupPadding: 3,
6553
6554
  fontSize: 14,
6554
6555
  symbolSize: 20,
6555
6556
  showTrackingLine: true,
@@ -6558,7 +6559,8 @@ class WebsyChart {
6558
6559
  legendPosition: 'bottom',
6559
6560
  tooltipWidth: 200,
6560
6561
  brushHeight: 50,
6561
- minBandWidth: 30
6562
+ minBandWidth: 30,
6563
+ allowUnevenBands: true
6562
6564
  }
6563
6565
  this.elementId = elementId
6564
6566
  this.options = Object.assign({}, DEFAULTS, options)
@@ -6583,25 +6585,43 @@ class WebsyChart {
6583
6585
  xAxis += 'Brush'
6584
6586
  }
6585
6587
  xAxis += 'Axis'
6586
- let width = this[xAxis].step()
6587
6588
  let output
6588
- let domain = [...this[xAxis].domain()]
6589
- if (this.options.orientation === 'horizontal') {
6590
- domain = domain.reverse()
6591
- }
6592
- for (let j = 0; j < domain.length; j++) {
6593
- let breakA = this[xAxis](domain[j]) - (width / 2)
6594
- let breakB = breakA + width
6595
- if (input > breakA && input <= breakB) {
6596
- output = j
6597
- break
6589
+ let width = this.options.data[xAxis.replace('Brush', '').replace('Axis', '')].bandWidth
6590
+ if (this.customBottomRange) {
6591
+ for (let index = 0; index < this.customBottomRange.length; index++) {
6592
+ if (input > this.customBottomRange[index]) {
6593
+ if (this.customBottomRange[index + 1]) {
6594
+ if (input < this.customBottomRange[index + 1]) {
6595
+ output = index
6596
+ break
6597
+ }
6598
+ }
6599
+ else {
6600
+ output = index
6601
+ break
6602
+ }
6603
+ }
6598
6604
  }
6599
- }
6605
+ }
6606
+ else {
6607
+ let domain = [...this[xAxis].domain()]
6608
+ if (this.options.orientation === 'horizontal') {
6609
+ domain = domain.reverse()
6610
+ }
6611
+ for (let j = 0; j < domain.length; j++) {
6612
+ let breakA = this[xAxis](domain[j]) - (width / 2)
6613
+ let breakB = breakA + width
6614
+ if (input > breakA && input <= breakB) {
6615
+ output = j
6616
+ break
6617
+ }
6618
+ }
6619
+ }
6600
6620
  return output
6601
6621
  }
6602
6622
  let that = this
6603
6623
  this.brushed = function (event) {
6604
- console.log('brushing', event)
6624
+ console.log('brushing', event)
6605
6625
  that.brushedDomain = []
6606
6626
  let xAxis = 'bottom'
6607
6627
  let xAxisCaps = 'Bottom'
@@ -6609,6 +6629,9 @@ class WebsyChart {
6609
6629
  xAxis = 'left'
6610
6630
  xAxisCaps = 'Left'
6611
6631
  }
6632
+ if (!that[`${xAxis}Axis`]) {
6633
+ return
6634
+ }
6612
6635
  if (!that[`${xAxis}Axis`].invert) {
6613
6636
  that[`${xAxis}Axis`].invert = that.invertOverride
6614
6637
  }
@@ -6671,6 +6694,18 @@ class WebsyChart {
6671
6694
  .attr('id', `${this.elementId}_legend`)
6672
6695
  .attr('class', 'websy-chart-legend')
6673
6696
  this.legend = new WebsyDesigns.Legend(`${this.elementId}_legend`, {})
6697
+ this.errorContainer = d3.select(el).append('div')
6698
+ .attr('id', `${this.elementId}_errorContainer`)
6699
+ .attr('class', 'websy-vis-error-container')
6700
+ .html(`
6701
+ <div>
6702
+ <div id="${this.elementId}_errorTitle"></div>
6703
+ <div id="${this.elementId}_errorMessage"></div>
6704
+ </div>
6705
+ `)
6706
+ this.loadingContainer = d3.select(el).append('div')
6707
+ .attr('id', `${this.elementId}_loadingContainer`)
6708
+ this.loadingDialog = new WebsyDesigns.LoadingDialog(`${this.elementId}_loadingContainer`)
6674
6709
  this.prep()
6675
6710
  // el.innerHTML += `
6676
6711
  // <div id="${this.elementId}_errorContainer" class='websy-vis-error-container'>
@@ -6786,7 +6821,12 @@ else {
6786
6821
  }
6787
6822
  this.options.data.series.forEach(s => {
6788
6823
  if (this.options.data[xData].scale !== 'Time') {
6789
- xPoint = this[xAxis](this.parseX(xLabel))
6824
+ if (this.customBottomRange && this.customBottomRange.length > 0) {
6825
+ xPoint = this.customBottomRange[x0] + ((this.customBottomRange[x0 + 1] - this.customBottomRange[x0]) / 2)
6826
+ }
6827
+ else {
6828
+ xPoint = this[xAxis](this.parseX(xLabel))
6829
+ }
6790
6830
  s.data.forEach(d => {
6791
6831
  if (d.x.value === xLabel) {
6792
6832
  if (!tooltipTitle) {
@@ -6875,7 +6915,7 @@ else {
6875
6915
  onLeft: xPoint > this.plotWidth / 2
6876
6916
  }
6877
6917
  if (xPoint > this.plotWidth / 2) {
6878
- posOptions.left = xPoint - this.options.tooltipWidth + this.options.margin.left + this.options.margin.axisLeft + 15
6918
+ posOptions.left = xPoint - this.options.tooltipWidth - 15 // + this.options.margin.left + this.options.margin.axisLeft + 15)
6879
6919
  if (this.options.data[xData].scale !== 'Time') {
6880
6920
  // posOptions.left -= (this[xAxis].bandwidth())
6881
6921
  posOptions.left += 10
@@ -6884,7 +6924,7 @@ else {
6884
6924
  else {
6885
6925
  posOptions.left = xPoint + this.options.margin.left + this.options.margin.axisLeft + 15
6886
6926
  if (this.options.data[xData].scale !== 'Time') {
6887
- posOptions.left += (this[xAxis].bandwidth() / 2)
6927
+ posOptions.left += (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
6888
6928
  }
6889
6929
  }
6890
6930
  posOptions.top = this.options.margin.top + this.options.margin.axisTop
@@ -6892,7 +6932,7 @@ else {
6892
6932
  delete posOptions.onLeft
6893
6933
  let adjuster = 0
6894
6934
  if (this.options.data[xData].scale !== 'Time') {
6895
- adjuster = (this[xAxis].bandwidth() / 2) // - this.options.margin.top
6935
+ adjuster = (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2) // - this.options.margin.top
6896
6936
  }
6897
6937
  posOptions = {
6898
6938
  width: this.options.tooltipWidth,
@@ -6913,8 +6953,8 @@ else {
6913
6953
  // else {
6914
6954
  // xPoint = x0
6915
6955
  // }
6916
- if (this.options.data[xData].scale !== 'Time') {
6917
- xPoint += (this[xAxis].bandwidth() / 2) // - this.options.margin.top
6956
+ if (this.options.data[xData].scale !== 'Time' && this.customBottomRange.length === 0) {
6957
+ xPoint += (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2) // - this.options.margin.top
6918
6958
  }
6919
6959
  let trackingXStart = xPoint
6920
6960
  let trackingXEnd = xPoint
@@ -6983,6 +7023,7 @@ if (!this.options.data) {
6983
7023
  // tell the user no data has been provided
6984
7024
  }
6985
7025
  else {
7026
+ this.processedX = {}
6986
7027
  this.transition = d3.transition().duration(this.options.transitionDuration)
6987
7028
  if (this.options.data.bottom.scale && this.options.data.bottom.scale === 'Time') {
6988
7029
  this.parseX = function (input) {
@@ -7029,7 +7070,13 @@ else {
7029
7070
  // establish the space and size for the legend
7030
7071
  // the legend gets rendered so that we can get its actual size
7031
7072
  if (this.options.showLegend === true) {
7032
- let legendData = this.options.data.series.map((s, i) => ({value: s.label || s.key, color: s.color || this.options.colors[i % this.options.colors.length]}))
7073
+ let legendData = []
7074
+ if (this.options.legendData && this.options.legendData.length > 0) {
7075
+ legendData = this.options.legendData
7076
+ }
7077
+ else {
7078
+ this.options.data.series.map((s, i) => ({value: s.label || s.key, color: s.color || this.options.colors[i % this.options.colors.length]}))
7079
+ }
7033
7080
  if (this.options.legendPosition === 'top' || this.options.legendPosition === 'bottom') {
7034
7081
  this.legendArea.style('width', '100%')
7035
7082
  this.legend.options.align = 'center'
@@ -7201,18 +7248,30 @@ else {
7201
7248
  this.plotHeight = this.height - this.options.margin.legendTop - this.options.margin.legendBottom - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom - this.options.margin.axisTop
7202
7249
  this.brushNeeded = false
7203
7250
  if (this.options.orientation === 'vertical') {
7204
- if (this.options.maxBandWidth) {
7205
- this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.data || []).length * this.options.maxBandWidth)
7251
+ this.options.data.bottom.totalValueCount = this.options.data.bottom.data.reduce((a, b) => {
7252
+ if (typeof b.valueCount === 'undefined') {
7253
+ return a + 1
7254
+ }
7255
+ return a + b.valueCount
7256
+ }, 0)
7257
+ if (this.options.maxBandWidth) {
7258
+ this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.totalValueCount) * this.options.maxBandWidth)
7206
7259
  }
7207
7260
  // some if to check if brushing is needed
7208
- if (this.plotWidth / this.options.data.bottom.data.length < this.options.minBandWidth) {
7261
+ if (this.plotWidth / this.options.data.bottom.totalValueCount < this.options.minBandWidth) {
7209
7262
  this.brushNeeded = true
7210
7263
  this.plotHeight -= this.options.brushHeight
7211
7264
  }
7212
7265
  }
7213
7266
  else {
7214
7267
  // some if to check if brushing is needed
7215
- if (this.plotHeight / this.options.data.left.data.length < this.options.minBandWidth) {
7268
+ this.options.data.left.totalValueCount = this.options.data.left.data.reduce((a, b) => {
7269
+ if (typeof b.valueCount === 'undefined') {
7270
+ return a + 1
7271
+ }
7272
+ return a + b.valueCount
7273
+ }, 0)
7274
+ if (this.plotHeight / this.options.data.left.totalValueCount < this.options.minBandWidth) {
7216
7275
  this.brushNeeded = true
7217
7276
  this.plotWidth -= this.options.brushHeight
7218
7277
  }
@@ -7267,14 +7326,39 @@ else {
7267
7326
  // this.tooltip.transform(this.options.margin.left + this.options.margin.axisLeft, this.options.margin.top + this.options.margin.axisTop)
7268
7327
  // Configure the bottom axis
7269
7328
  let bottomDomain = this.createDomain('bottom')
7270
- let bottomBrushDomain = this.createDomain('bottom', true)
7329
+ let bottomBrushDomain = this.createDomain('bottom', true)
7330
+ let bottomRange = [0, this.plotWidth]
7331
+ this.customBottomRange = []
7332
+ if (this.options.allowUnevenBands === true) {
7333
+ if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].valueCount && this.options.data.bottom.scale === 'Ordinal') {
7334
+ let acc = 0
7335
+ this.customBottomRange = [0, ...this.options.data.bottom.data.map(d => {
7336
+ acc += d.valueCount
7337
+ return (this.plotWidth / this.options.data.bottom.totalValueCount) * acc
7338
+ })]
7339
+ }
7340
+ }
7341
+ this.options.data.bottom.step = this.plotWidth / this.options.data.bottom.totalValueCount
7342
+ this.options.data.bottom.bandWidth = this.options.data.bottom.step
7343
+ if (this.options.data.bottom.padding) {
7344
+ this.totalPadding = this.plotWidth * this.options.data.bottom.padding
7345
+ let rangeLength = bottomDomain.length
7346
+ if (this.customBottomRange.length > 0) {
7347
+ rangeLength = this.customBottomRange.length
7348
+ }
7349
+ this.bandPadding = (this.totalPadding / (rangeLength)) / 2
7350
+ this.options.data.bottom.bandWidth = (this.plotWidth - this.totalPadding) / this.options.data.bottom.totalValueCount
7351
+ }
7352
+ if (this.options.grouping === 'grouped' && this.options.data.series.length > 1) {
7353
+ this.options.data.bottom.bandWidth = this.options.data.bottom.bandWidth - (this.options.groupPadding * 2)
7354
+ }
7271
7355
  this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7272
7356
  .domain(bottomDomain)
7273
- .range([0, this.plotWidth])
7357
+ .range(bottomRange)
7274
7358
  if (!this.brushInitialized) {
7275
7359
  this.bottomBrushAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7276
7360
  .domain(bottomBrushDomain)
7277
- .range([0, this.plotWidth])
7361
+ .range(bottomRange)
7278
7362
  }
7279
7363
  if (this.bottomAxis.nice) {
7280
7364
  // this.bottomAxis.nice()
@@ -7446,6 +7530,10 @@ else {
7446
7530
  .style('text-anchor', `${((this.options.data.bottom && this.options.data.bottom.rotate) || 0) === 0 ? 'middle' : 'end'}`)
7447
7531
  .style('transform-origin', ((this.options.data.bottom && this.options.data.bottom.rotate) || 0) === 0 ? '0 0' : `0 ${((this.options.data.bottom && this.options.data.bottom.fontSize) || this.options.fontSize)}px`)
7448
7532
  }
7533
+ if (this.customBottomRange.length > 0) {
7534
+ this.bottomAxisLayer.selectAll('g')
7535
+ .attr('transform', (d, i) => `translate(${this.customBottomRange[i] + ((this.customBottomRange[i + 1] - this.customBottomRange[i]) / 2)}, 0)`)
7536
+ }
7449
7537
  }
7450
7538
  // Configure the left axis
7451
7539
  let leftDomain = this.createDomain('left')
@@ -7591,6 +7679,8 @@ this.options.data.series.forEach((series, index) => {
7591
7679
  this.renderLabels(series, index)
7592
7680
  this.renderedKeys[series.key] = series.type
7593
7681
  })
7682
+ this.refLineLayer.selectAll('.reference-line').remove()
7683
+ this.refLineLayer.selectAll('.reference-line-label').remove()
7594
7684
  if (this.options.refLines && this.options.refLines.length > 0) {
7595
7685
  this.options.refLines.forEach(l => this.renderRefLine(l))
7596
7686
  }
@@ -7602,21 +7692,21 @@ const drawArea = (xAxis, yAxis, curveStyle) => {
7602
7692
  return d3
7603
7693
  .area()
7604
7694
  .x(d => {
7605
- return this[xAxis](this.parseX(d.x.value))
7695
+ return this[`${xAxis}Axis`](this.parseX(d.x.value))
7606
7696
  })
7607
7697
  .y0(d => {
7608
- return this[yAxis](0)
7698
+ return this[`${yAxis}Axis`](0)
7609
7699
  })
7610
7700
  .y1(d => {
7611
- return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value)
7701
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
7612
7702
  })
7613
7703
  .curve(d3[curveStyle || this.options.curveStyle])
7614
7704
  }
7615
- let xAxis = 'bottomAxis'
7616
- let yAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
7617
- if (this.options.orienation === 'horizontal') {
7618
- xAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
7619
- yAxis = 'bottomAxis'
7705
+ let xAxis = 'bottom'
7706
+ let yAxis = series.axis === 'secondary' ? 'right' : 'left'
7707
+ if (this.options.orientation === 'horizontal') {
7708
+ xAxis = series.axis === 'secondary' ? 'right' : 'left'
7709
+ yAxis = 'bottom'
7620
7710
  }
7621
7711
  let areas = this.areaLayer.selectAll(`.area_${series.key}`)
7622
7712
  .data([series.data])
@@ -7639,7 +7729,7 @@ areas.enter().append('path')
7639
7729
  .attr('d', d => drawArea(xAxis, yAxis, series.curveStyle)(d))
7640
7730
  .attr('class', `area_${series.key}`)
7641
7731
  .attr('id', `area_${series.key}`)
7642
- // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
7732
+ .attr('transform', 'translate(' + (this.options.data[xAxis].scale === 'Time' ? 0 : this.options.data[`${xAxis}Axis`].bandWidth / 2) + ',0)')
7643
7733
  // .style('stroke-width', series.lineWidth || this.options.lineWidth)
7644
7734
  .attr('fill', series.color)
7645
7735
  // .style('fill-opacity', 0)
@@ -7662,15 +7752,14 @@ if (this.options.orientation === 'horizontal') {
7662
7752
  // if (this.options.data.series.length > 1 && this.options.grouping === 'grouped') {
7663
7753
  // barWidth = barWidth / this.options.data.series.length - 4
7664
7754
  // }
7665
- function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7666
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7667
- let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
7755
+ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7668
7756
  let output
7669
7757
  if (this.options.orientation === 'horizontal') {
7670
- output = barWidth
7758
+ output = this.options.data[xAxis.replace('Brush', '')].bandWidth
7671
7759
  }
7672
7760
  else {
7673
- if (!getBarX.call(this, d, i, xAxis)) {
7761
+ let x = getBarX.call(this, d, i, xAxis)
7762
+ if (typeof x === 'undefined' || x === null) {
7674
7763
  return null
7675
7764
  }
7676
7765
  output = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
@@ -7680,25 +7769,19 @@ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7680
7769
  }
7681
7770
  return output
7682
7771
  }
7683
- function getBarWidth (d, i, xAxis) {
7684
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7685
- let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data.series.length
7772
+ function getBarWidth (d, i, xAxis) {
7686
7773
  let output
7687
- if (this.options.orientation === 'horizontal') {
7688
- let width = this[`${yAxis}Axis`](d.y.value)
7774
+ if (this.options.orientation === 'horizontal') {
7775
+ let width = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
7689
7776
  acummulativeY[d.y.index] += width
7690
- output = Math.max(1, width)
7777
+ output = width
7691
7778
  }
7692
7779
  else {
7693
- if (!getBarX.call(this, d, i, xAxis)) {
7780
+ let x = getBarX.call(this, d, i, xAxis)
7781
+ if (typeof x === 'undefined' || x === null) {
7694
7782
  return null
7695
- }
7696
- if (this.options.grouping === 'grouped') {
7697
- output = Math.max(1, groupedBarWidth)
7698
- }
7699
- else {
7700
- output = Math.max(1, barWidth)
7701
- }
7783
+ }
7784
+ output = Math.max(1, this.options.data[xAxis.replace('Brush', '')].bandWidth)
7702
7785
  }
7703
7786
  if (isNaN(output)) {
7704
7787
  return 0
@@ -7706,22 +7789,55 @@ function getBarWidth (d, i, xAxis) {
7706
7789
  return output
7707
7790
  }
7708
7791
  function getBarX (d, i, xAxis) {
7709
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7710
- let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data.series.length
7792
+ // let barWidth = this.plotWidth / this.options.data[xAxis.replace('Brush', '')].totalValueCount
7793
+ // if (this.options.data[xAxis.replace('Brush', '')].padding) {
7794
+ // barWidth = barWidth - (barWidth * this.options.data[xAxis.replace('Brush', '')].padding)
7795
+ // }
7796
+ // let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data[xAxis.replace('Brush', '')].totalValueCount
7711
7797
  let output
7712
7798
  if (this.options.orientation === 'horizontal') {
7713
7799
  if (this.options.grouping === 'stacked') {
7714
- output = this[`${yAxis}Axis`](d.y.accumulative)
7800
+ let h = getBarWidth.call(this, d, i, xAxis)
7801
+ let adjustment = 0
7802
+ if (d.y.accumulative && d.y.accumulative !== 0) {
7803
+ adjustment = this[`${yAxis}Axis`](d.y.accumulative || 0)
7804
+ }
7805
+ output = this[`${yAxis}Axis`](0) + (adjustment * (d.y.value < 0 ? 1 : 0)) + (h * (d.y.value < 0 ? 1 : 0))
7715
7806
  }
7716
7807
  else {
7717
- output = 0
7808
+ let h = getBarWidth.call(this, d, i, xAxis)
7809
+ output = (this[`${yAxis}Axis`](0)) + (h * (d.y.value < 0 ? 1 : 0))
7718
7810
  }
7719
7811
  }
7720
7812
  else {
7721
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7722
- if (this.options.grouping === 'grouped') {
7723
- let barAdjustment = groupedBarWidth * index + (xAxis.indexOf('Brush') === -1 ? 5 : 1) // + (index > 0 ? 4 : 0)
7724
- output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + barAdjustment
7813
+ // let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this.options.data[xAxis.replace('Brush', '')].bandWidth / 2
7814
+ let adjustment = this.customBottomRange[i] + (i * this.options.data[xAxis.replace('Brush', '')].bandWidth)
7815
+ if (this.options.grouping === 'grouped') {
7816
+ let xIndex = 0
7817
+ if (this.processedX[d.x.value]) {
7818
+ xIndex = Math.max(0, this.processedX[d.x.value].indexOf(d.y.tooltipLabel))
7819
+ }
7820
+ let barAdjustment =
7821
+ (this.options.data[xAxis.replace('Brush', '')].bandWidth * xIndex) +
7822
+ (xIndex * this.options.groupPadding * 2) + this.options.groupPadding +
7823
+ (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
7824
+ // let barAdjustment =
7825
+ // (this.options.data[xAxis.replace('Brush', '')].step * xIndex) +
7826
+ // this.options.groupPadding
7827
+ // // (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
7828
+ if (this.customBottomRange.length > 0) {
7829
+ output = this.customBottomRange[this[xAxis.replace('Brush', '') + 'Axis'].domain().indexOf(d.x.value)] + barAdjustment
7830
+ }
7831
+ else {
7832
+ output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + barAdjustment
7833
+ }
7834
+ if (!this.processedX[d.x.value]) {
7835
+ this.processedX[d.x.value] = []
7836
+ }
7837
+ if (this.processedX[d.x.value].indexOf(d.y.tooltipLabel) === -1) {
7838
+ this.processedX[d.x.value].push(d.y.tooltipLabel)
7839
+ }
7840
+ console.log(d.x.value, d.y.tooltipLabel, xIndex, i, barAdjustment, output)
7725
7841
  }
7726
7842
  else {
7727
7843
  // output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + (i * barWidth) + adjustment
@@ -7734,15 +7850,15 @@ function getBarX (d, i, xAxis) {
7734
7850
  return output
7735
7851
  }
7736
7852
  function getBarY (d, i, heightBounds, yAxis, xAxis) {
7737
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7738
- let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
7853
+ // let barWidth = this[`${xAxis}Axis`].bandwidth()
7854
+ // let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
7739
7855
  let output
7740
7856
  if (this.options.orientation === 'horizontal') {
7741
7857
  if (this.options.grouping !== 'grouped') {
7742
7858
  output = this[`${xAxis}Axis`](this.parseX(d.x.value))
7743
7859
  }
7744
7860
  else {
7745
- output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + ((d.y.index || i) * barWidth)
7861
+ output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + ((d.y.index || i) * this.options.data[xAxis.replace('Brush', '')].barWidth)
7746
7862
  }
7747
7863
  }
7748
7864
  else {
@@ -7766,7 +7882,7 @@ bars
7766
7882
  .remove()
7767
7883
 
7768
7884
  bars
7769
- .attr('width', (d, i) => getBarWidth.call(this, d, i, xAxis))
7885
+ .attr('width', (d, i) => Math.abs(getBarWidth.call(this, d, i, xAxis)))
7770
7886
  .attr('height', (d, i) => getBarHeight.call(this, d, i, this.plotHeight, yAxis, xAxis))
7771
7887
  .attr('x', (d, i) => getBarX.call(this, d, i, xAxis))
7772
7888
  .attr('y', (d, i) => getBarY.call(this, d, i, this.plotHeight, yAxis, xAxis))
@@ -7776,7 +7892,7 @@ bars
7776
7892
  bars
7777
7893
  .enter()
7778
7894
  .append('rect')
7779
- .attr('width', (d, i) => getBarWidth.call(this, d, i, xAxis))
7895
+ .attr('width', (d, i) => Math.abs(getBarWidth.call(this, d, i, xAxis)))
7780
7896
  .attr('height', (d, i) => getBarHeight.call(this, d, i, this.plotHeight, yAxis, xAxis))
7781
7897
  .attr('x', (d, i) => getBarX.call(this, d, i, xAxis))
7782
7898
  .attr('y', (d, i) => getBarY.call(this, d, i, this.plotHeight, yAxis, xAxis))
@@ -7795,7 +7911,7 @@ if (!this.brushBarsInitialized[series.key]) {
7795
7911
  .remove()
7796
7912
 
7797
7913
  brushBars
7798
- .attr('width', (d, i) => getBarWidth.call(this, d, i, `${xAxis}Brush`))
7914
+ .attr('width', (d, i) => Math.abs(getBarWidth.call(this, d, i, `${xAxis}Brush`)))
7799
7915
  .attr('height', (d, i) => getBarHeight.call(this, d, i, this.options.brushHeight, `${yAxis}Brush`, `${xAxis}Brush`))
7800
7916
  .attr('x', (d, i) => getBarX.call(this, d, i, `${xAxis}Brush`))
7801
7917
  .attr('y', (d, i) => getBarY.call(this, d, i, this.options.brushHeight, `${yAxis}Brush`, `${xAxis}Brush`))
@@ -7805,7 +7921,7 @@ if (!this.brushBarsInitialized[series.key]) {
7805
7921
  brushBars
7806
7922
  .enter()
7807
7923
  .append('rect')
7808
- .attr('width', (d, i) => getBarWidth.call(this, d, i, `${xAxis}Brush`))
7924
+ .attr('width', (d, i) => Math.abs(getBarWidth.call(this, d, i, `${xAxis}Brush`)))
7809
7925
  .attr('height', (d, i) => getBarHeight.call(this, d, i, this.options.brushHeight, `${yAxis}Brush`, `${xAxis}Brush`))
7810
7926
  .attr('x', (d, i) => getBarX.call(this, d, i, `${xAxis}Brush`))
7811
7927
  .attr('y', (d, i) => getBarY.call(this, d, i, this.options.brushHeight, `${yAxis}Brush`, `${xAxis}Brush`))
@@ -7936,12 +8052,12 @@ function getLabelX (d, labelPosition = 'inside') {
7936
8052
  }
7937
8053
  }
7938
8054
  else {
7939
- return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
8055
+ return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
7940
8056
  }
7941
8057
  }
7942
8058
  function getLabelY (d, labelPosition = 'inside') {
7943
8059
  if (this.options.orientation === 'horizontal') {
7944
- return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
8060
+ return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
7945
8061
  }
7946
8062
  else {
7947
8063
  if (this.options.grouping === 'stacked') {
@@ -7960,23 +8076,34 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
7960
8076
  return d3
7961
8077
  .line()
7962
8078
  .x(d => {
7963
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7964
- return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8079
+ if (this.options.orientation === 'horizontal') {
8080
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8081
+ }
8082
+ else {
8083
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8084
+ return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8085
+ }
7965
8086
  })
7966
8087
  .y(d => {
7967
- return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8088
+ if (this.options.orientation === 'horizontal') {
8089
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8090
+ return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8091
+ }
8092
+ else {
8093
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8094
+ }
7968
8095
  })
7969
8096
  .curve(d3[curveStyle || this.options.curveStyle])
7970
8097
  }
7971
8098
  let xAxis = 'bottom'
7972
8099
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
7973
- if (this.options.orienation === 'horizontal') {
8100
+ if (this.options.orientation === 'horizontal') {
7974
8101
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
7975
8102
  yAxis = 'bottom'
7976
8103
  }
7977
8104
  let xBrushAxis = 'bottomBrush'
7978
8105
  let yBrushAxis = 'leftBrush'
7979
- if (this.options.orienation === 'horizontal') {
8106
+ if (this.options.orientation === 'horizontal') {
7980
8107
  xBrushAxis = 'leftBrush'
7981
8108
  yBrushAxis = 'bottomBrush'
7982
8109
  }
@@ -8062,8 +8189,6 @@ if (this.options.orientation === 'horizontal') {
8062
8189
  xAttr = 'y'
8063
8190
  length = this.plotHeight
8064
8191
  }
8065
- this.refLineLayer.selectAll('.reference-line').remove()
8066
- this.refLineLayer.selectAll('.reference-line-label').remove()
8067
8192
  this.refLineLayer
8068
8193
  .append('line')
8069
8194
  .attr(`${yAttr}1`, this[`${yAxis}Axis`](data.value))
@@ -8112,7 +8237,7 @@ const drawSymbol = (size) => {
8112
8237
  }
8113
8238
  let xAxis = 'bottom'
8114
8239
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
8115
- if (this.options.orienation === 'horizontal') {
8240
+ if (this.options.orientation === 'horizontal') {
8116
8241
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
8117
8242
  yAxis = 'bottom'
8118
8243
  }
@@ -8130,8 +8255,13 @@ symbols
8130
8255
  .attr('fill', series.fillSymbols ? series.color : 'white')
8131
8256
  .attr('stroke', series.color)
8132
8257
  .attr('transform', d => {
8133
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8134
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8258
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8259
+ if (this.options.orientation === 'horizontal') {
8260
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8261
+ }
8262
+ else {
8263
+ return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8264
+ }
8135
8265
  })
8136
8266
  // Enter
8137
8267
  symbols.enter()
@@ -8142,8 +8272,13 @@ symbols.enter()
8142
8272
  .attr('stroke', series.color)
8143
8273
  .attr('class', d => { return `symbol symbol_${series.key}` })
8144
8274
  .attr('transform', d => {
8145
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8146
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8275
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8276
+ if (this.options.orientation === 'horizontal') {
8277
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8278
+ }
8279
+ else {
8280
+ return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8281
+ }
8147
8282
  })
8148
8283
 
8149
8284
  }
@@ -8247,22 +8382,27 @@ if (el) {
8247
8382
  if (el) {
8248
8383
  el.classList.remove('has-error')
8249
8384
  }
8250
- // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8251
- // chartEl.classList.remove('hidden')
8252
- this.svg.classed('hidden', false)
8385
+ if (this.svg) {
8386
+ this.svg.classed('hidden', false)
8387
+ }
8253
8388
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8254
8389
  if (containerEl) {
8255
8390
  containerEl.classList.remove('active')
8256
8391
  }
8257
8392
  }
8393
+ hideLoading () {
8394
+ this.loadingDialog.hide()
8395
+ }
8258
8396
  showError (options) {
8259
8397
  const el = document.getElementById(`${this.elementId}`)
8260
8398
  if (el) {
8261
8399
  el.classList.add('has-error')
8262
8400
  }
8263
8401
  // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8264
- // chartEl.classList.add('hidden')
8265
- this.svg.classed('hidden', true)
8402
+ // chartEl.classList.add('hidden')
8403
+ if (this.svg) {
8404
+ this.svg.classed('hidden', true)
8405
+ }
8266
8406
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8267
8407
  if (containerEl) {
8268
8408
  containerEl.classList.add('active')
@@ -8280,6 +8420,9 @@ if (el) {
8280
8420
  }
8281
8421
  }
8282
8422
  }
8423
+ showLoading (options) {
8424
+ this.loadingDialog.show(options)
8425
+ }
8283
8426
  }
8284
8427
 
8285
8428
  class WebsyLegend {