@websy/websy-designs 1.4.38 → 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
  }
@@ -6798,7 +6821,12 @@ else {
6798
6821
  }
6799
6822
  this.options.data.series.forEach(s => {
6800
6823
  if (this.options.data[xData].scale !== 'Time') {
6801
- 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
+ }
6802
6830
  s.data.forEach(d => {
6803
6831
  if (d.x.value === xLabel) {
6804
6832
  if (!tooltipTitle) {
@@ -6887,7 +6915,7 @@ else {
6887
6915
  onLeft: xPoint > this.plotWidth / 2
6888
6916
  }
6889
6917
  if (xPoint > this.plotWidth / 2) {
6890
- 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)
6891
6919
  if (this.options.data[xData].scale !== 'Time') {
6892
6920
  // posOptions.left -= (this[xAxis].bandwidth())
6893
6921
  posOptions.left += 10
@@ -6896,7 +6924,7 @@ else {
6896
6924
  else {
6897
6925
  posOptions.left = xPoint + this.options.margin.left + this.options.margin.axisLeft + 15
6898
6926
  if (this.options.data[xData].scale !== 'Time') {
6899
- posOptions.left += (this[xAxis].bandwidth() / 2)
6927
+ posOptions.left += (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
6900
6928
  }
6901
6929
  }
6902
6930
  posOptions.top = this.options.margin.top + this.options.margin.axisTop
@@ -6904,7 +6932,7 @@ else {
6904
6932
  delete posOptions.onLeft
6905
6933
  let adjuster = 0
6906
6934
  if (this.options.data[xData].scale !== 'Time') {
6907
- adjuster = (this[xAxis].bandwidth() / 2) // - this.options.margin.top
6935
+ adjuster = (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2) // - this.options.margin.top
6908
6936
  }
6909
6937
  posOptions = {
6910
6938
  width: this.options.tooltipWidth,
@@ -6925,8 +6953,8 @@ else {
6925
6953
  // else {
6926
6954
  // xPoint = x0
6927
6955
  // }
6928
- if (this.options.data[xData].scale !== 'Time') {
6929
- 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
6930
6958
  }
6931
6959
  let trackingXStart = xPoint
6932
6960
  let trackingXEnd = xPoint
@@ -6995,6 +7023,7 @@ if (!this.options.data) {
6995
7023
  // tell the user no data has been provided
6996
7024
  }
6997
7025
  else {
7026
+ this.processedX = {}
6998
7027
  this.transition = d3.transition().duration(this.options.transitionDuration)
6999
7028
  if (this.options.data.bottom.scale && this.options.data.bottom.scale === 'Time') {
7000
7029
  this.parseX = function (input) {
@@ -7041,7 +7070,13 @@ else {
7041
7070
  // establish the space and size for the legend
7042
7071
  // the legend gets rendered so that we can get its actual size
7043
7072
  if (this.options.showLegend === true) {
7044
- 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
+ }
7045
7080
  if (this.options.legendPosition === 'top' || this.options.legendPosition === 'bottom') {
7046
7081
  this.legendArea.style('width', '100%')
7047
7082
  this.legend.options.align = 'center'
@@ -7213,18 +7248,30 @@ else {
7213
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
7214
7249
  this.brushNeeded = false
7215
7250
  if (this.options.orientation === 'vertical') {
7216
- if (this.options.maxBandWidth) {
7217
- 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)
7218
7259
  }
7219
7260
  // some if to check if brushing is needed
7220
- if (this.plotWidth / this.options.data.bottom.data.length < this.options.minBandWidth) {
7261
+ if (this.plotWidth / this.options.data.bottom.totalValueCount < this.options.minBandWidth) {
7221
7262
  this.brushNeeded = true
7222
7263
  this.plotHeight -= this.options.brushHeight
7223
7264
  }
7224
7265
  }
7225
7266
  else {
7226
7267
  // some if to check if brushing is needed
7227
- 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) {
7228
7275
  this.brushNeeded = true
7229
7276
  this.plotWidth -= this.options.brushHeight
7230
7277
  }
@@ -7279,14 +7326,39 @@ else {
7279
7326
  // this.tooltip.transform(this.options.margin.left + this.options.margin.axisLeft, this.options.margin.top + this.options.margin.axisTop)
7280
7327
  // Configure the bottom axis
7281
7328
  let bottomDomain = this.createDomain('bottom')
7282
- 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
+ }
7283
7355
  this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7284
7356
  .domain(bottomDomain)
7285
- .range([0, this.plotWidth])
7357
+ .range(bottomRange)
7286
7358
  if (!this.brushInitialized) {
7287
7359
  this.bottomBrushAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7288
7360
  .domain(bottomBrushDomain)
7289
- .range([0, this.plotWidth])
7361
+ .range(bottomRange)
7290
7362
  }
7291
7363
  if (this.bottomAxis.nice) {
7292
7364
  // this.bottomAxis.nice()
@@ -7458,6 +7530,10 @@ else {
7458
7530
  .style('text-anchor', `${((this.options.data.bottom && this.options.data.bottom.rotate) || 0) === 0 ? 'middle' : 'end'}`)
7459
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`)
7460
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
+ }
7461
7537
  }
7462
7538
  // Configure the left axis
7463
7539
  let leftDomain = this.createDomain('left')
@@ -7603,6 +7679,8 @@ this.options.data.series.forEach((series, index) => {
7603
7679
  this.renderLabels(series, index)
7604
7680
  this.renderedKeys[series.key] = series.type
7605
7681
  })
7682
+ this.refLineLayer.selectAll('.reference-line').remove()
7683
+ this.refLineLayer.selectAll('.reference-line-label').remove()
7606
7684
  if (this.options.refLines && this.options.refLines.length > 0) {
7607
7685
  this.options.refLines.forEach(l => this.renderRefLine(l))
7608
7686
  }
@@ -7614,21 +7692,21 @@ const drawArea = (xAxis, yAxis, curveStyle) => {
7614
7692
  return d3
7615
7693
  .area()
7616
7694
  .x(d => {
7617
- return this[xAxis](this.parseX(d.x.value))
7695
+ return this[`${xAxis}Axis`](this.parseX(d.x.value))
7618
7696
  })
7619
7697
  .y0(d => {
7620
- return this[yAxis](0)
7698
+ return this[`${yAxis}Axis`](0)
7621
7699
  })
7622
7700
  .y1(d => {
7623
- return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value)
7701
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
7624
7702
  })
7625
7703
  .curve(d3[curveStyle || this.options.curveStyle])
7626
7704
  }
7627
- let xAxis = 'bottomAxis'
7628
- let yAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
7629
- if (this.options.orienation === 'horizontal') {
7630
- xAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
7631
- 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'
7632
7710
  }
7633
7711
  let areas = this.areaLayer.selectAll(`.area_${series.key}`)
7634
7712
  .data([series.data])
@@ -7651,7 +7729,7 @@ areas.enter().append('path')
7651
7729
  .attr('d', d => drawArea(xAxis, yAxis, series.curveStyle)(d))
7652
7730
  .attr('class', `area_${series.key}`)
7653
7731
  .attr('id', `area_${series.key}`)
7654
- // .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)')
7655
7733
  // .style('stroke-width', series.lineWidth || this.options.lineWidth)
7656
7734
  .attr('fill', series.color)
7657
7735
  // .style('fill-opacity', 0)
@@ -7674,15 +7752,14 @@ if (this.options.orientation === 'horizontal') {
7674
7752
  // if (this.options.data.series.length > 1 && this.options.grouping === 'grouped') {
7675
7753
  // barWidth = barWidth / this.options.data.series.length - 4
7676
7754
  // }
7677
- function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7678
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7679
- let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
7755
+ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7680
7756
  let output
7681
7757
  if (this.options.orientation === 'horizontal') {
7682
- output = barWidth
7758
+ output = this.options.data[xAxis.replace('Brush', '')].bandWidth
7683
7759
  }
7684
7760
  else {
7685
- if (!getBarX.call(this, d, i, xAxis)) {
7761
+ let x = getBarX.call(this, d, i, xAxis)
7762
+ if (typeof x === 'undefined' || x === null) {
7686
7763
  return null
7687
7764
  }
7688
7765
  output = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
@@ -7692,26 +7769,19 @@ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
7692
7769
  }
7693
7770
  return output
7694
7771
  }
7695
- function getBarWidth (d, i, xAxis) {
7696
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7697
- let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data.series.length
7772
+ function getBarWidth (d, i, xAxis) {
7698
7773
  let output
7699
- if (this.options.orientation === 'horizontal') {
7700
- // let width = this[`${yAxis}Axis`](d.y.value)
7774
+ if (this.options.orientation === 'horizontal') {
7701
7775
  let width = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
7702
7776
  acummulativeY[d.y.index] += width
7703
7777
  output = width
7704
7778
  }
7705
7779
  else {
7706
- if (!getBarX.call(this, d, i, xAxis)) {
7780
+ let x = getBarX.call(this, d, i, xAxis)
7781
+ if (typeof x === 'undefined' || x === null) {
7707
7782
  return null
7708
- }
7709
- if (this.options.grouping === 'grouped') {
7710
- output = Math.max(1, groupedBarWidth)
7711
- }
7712
- else {
7713
- output = Math.max(1, barWidth)
7714
- }
7783
+ }
7784
+ output = Math.max(1, this.options.data[xAxis.replace('Brush', '')].bandWidth)
7715
7785
  }
7716
7786
  if (isNaN(output)) {
7717
7787
  return 0
@@ -7719,8 +7789,11 @@ function getBarWidth (d, i, xAxis) {
7719
7789
  return output
7720
7790
  }
7721
7791
  function getBarX (d, i, xAxis) {
7722
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7723
- 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
7724
7797
  let output
7725
7798
  if (this.options.orientation === 'horizontal') {
7726
7799
  if (this.options.grouping === 'stacked') {
@@ -7737,10 +7810,34 @@ function getBarX (d, i, xAxis) {
7737
7810
  }
7738
7811
  }
7739
7812
  else {
7740
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7741
- if (this.options.grouping === 'grouped') {
7742
- let barAdjustment = groupedBarWidth * index + (xAxis.indexOf('Brush') === -1 ? 5 : 1) // + (index > 0 ? 4 : 0)
7743
- 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)
7744
7841
  }
7745
7842
  else {
7746
7843
  // output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + (i * barWidth) + adjustment
@@ -7753,15 +7850,15 @@ function getBarX (d, i, xAxis) {
7753
7850
  return output
7754
7851
  }
7755
7852
  function getBarY (d, i, heightBounds, yAxis, xAxis) {
7756
- let barWidth = this[`${xAxis}Axis`].bandwidth()
7757
- 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
7758
7855
  let output
7759
7856
  if (this.options.orientation === 'horizontal') {
7760
7857
  if (this.options.grouping !== 'grouped') {
7761
7858
  output = this[`${xAxis}Axis`](this.parseX(d.x.value))
7762
7859
  }
7763
7860
  else {
7764
- 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)
7765
7862
  }
7766
7863
  }
7767
7864
  else {
@@ -7955,12 +8052,12 @@ function getLabelX (d, labelPosition = 'inside') {
7955
8052
  }
7956
8053
  }
7957
8054
  else {
7958
- 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)
7959
8056
  }
7960
8057
  }
7961
8058
  function getLabelY (d, labelPosition = 'inside') {
7962
8059
  if (this.options.orientation === 'horizontal') {
7963
- 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)
7964
8061
  }
7965
8062
  else {
7966
8063
  if (this.options.grouping === 'stacked') {
@@ -7979,23 +8076,34 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
7979
8076
  return d3
7980
8077
  .line()
7981
8078
  .x(d => {
7982
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7983
- 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
+ }
7984
8086
  })
7985
8087
  .y(d => {
7986
- 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
+ }
7987
8095
  })
7988
8096
  .curve(d3[curveStyle || this.options.curveStyle])
7989
8097
  }
7990
8098
  let xAxis = 'bottom'
7991
8099
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
7992
- if (this.options.orienation === 'horizontal') {
8100
+ if (this.options.orientation === 'horizontal') {
7993
8101
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
7994
8102
  yAxis = 'bottom'
7995
8103
  }
7996
8104
  let xBrushAxis = 'bottomBrush'
7997
8105
  let yBrushAxis = 'leftBrush'
7998
- if (this.options.orienation === 'horizontal') {
8106
+ if (this.options.orientation === 'horizontal') {
7999
8107
  xBrushAxis = 'leftBrush'
8000
8108
  yBrushAxis = 'bottomBrush'
8001
8109
  }
@@ -8081,8 +8189,6 @@ if (this.options.orientation === 'horizontal') {
8081
8189
  xAttr = 'y'
8082
8190
  length = this.plotHeight
8083
8191
  }
8084
- this.refLineLayer.selectAll('.reference-line').remove()
8085
- this.refLineLayer.selectAll('.reference-line-label').remove()
8086
8192
  this.refLineLayer
8087
8193
  .append('line')
8088
8194
  .attr(`${yAttr}1`, this[`${yAxis}Axis`](data.value))
@@ -8131,7 +8237,7 @@ const drawSymbol = (size) => {
8131
8237
  }
8132
8238
  let xAxis = 'bottom'
8133
8239
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
8134
- if (this.options.orienation === 'horizontal') {
8240
+ if (this.options.orientation === 'horizontal') {
8135
8241
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
8136
8242
  yAxis = 'bottom'
8137
8243
  }
@@ -8149,8 +8255,13 @@ symbols
8149
8255
  .attr('fill', series.fillSymbols ? series.color : 'white')
8150
8256
  .attr('stroke', series.color)
8151
8257
  .attr('transform', d => {
8152
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8153
- 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
+ }
8154
8265
  })
8155
8266
  // Enter
8156
8267
  symbols.enter()
@@ -8161,8 +8272,13 @@ symbols.enter()
8161
8272
  .attr('stroke', series.color)
8162
8273
  .attr('class', d => { return `symbol symbol_${series.key}` })
8163
8274
  .attr('transform', d => {
8164
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8165
- 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
+ }
8166
8282
  })
8167
8283
 
8168
8284
  }
@@ -8266,9 +8382,9 @@ if (el) {
8266
8382
  if (el) {
8267
8383
  el.classList.remove('has-error')
8268
8384
  }
8269
- // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8270
- // chartEl.classList.remove('hidden')
8271
- this.svg.classed('hidden', false)
8385
+ if (this.svg) {
8386
+ this.svg.classed('hidden', false)
8387
+ }
8272
8388
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8273
8389
  if (containerEl) {
8274
8390
  containerEl.classList.remove('active')
@@ -8283,8 +8399,10 @@ if (el) {
8283
8399
  el.classList.add('has-error')
8284
8400
  }
8285
8401
  // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8286
- // chartEl.classList.add('hidden')
8287
- this.svg.classed('hidden', true)
8402
+ // chartEl.classList.add('hidden')
8403
+ if (this.svg) {
8404
+ this.svg.classed('hidden', true)
8405
+ }
8288
8406
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8289
8407
  if (containerEl) {
8290
8408
  containerEl.classList.add('active')