Skip to content

Commit

Permalink
Update formatLabel, add options
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorizzo committed Nov 7, 2018
1 parent 1f5fe56 commit 7d609ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ See: [package.json](https://github.com/emiliorizzo/vue-d3-barchart/blob/master/p
- **data**: Array of values or objects *(see options: getX,getY)*

- **options**:
-
- **size**:{w,h}
- **getX**: function(d)
- **getY**: function(d)
Expand All @@ -73,7 +73,7 @@ See: [package.json](https://github.com/emiliorizzo/vue-d3-barchart/blob/master/p

- **formatX**: Function(x) --> x
- **formatY**: Function(y) --> y
- **formatLabel**(d, formatX, formatY) -> Array, one value per line
- **formatLabel**(d, formatX, formatY) -> <Array> , one value per line: **String | Object**: {style,css,txt}

*default:*
```javasctipt
Expand Down
13 changes: 10 additions & 3 deletions src/vue-d3-barchart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
@touchstart='barClick(over)'
)
text.label( :x='lineX + fontSize' y='0' :font-size='fontSize')
tspan.label-line(v-for='txt,index in label'
:key='index' :x='lineX + fontSize' dy='1.2em' :class='"l-" + index ' ) {{txt}}
tspan.label-line(v-for='line,index in label'
:key='index' :x='lineX + fontSize' dy='1.2em' :class='line.css' :style='line.style') {{line.txt}}

</template>
<script>
Expand Down Expand Up @@ -367,7 +367,14 @@ export default {
return d.join(' ')
},
createLabel (bar) {
return this.formatLabel(bar, this.formatX, this.formatY)
let label = this.formatLabel(bar, this.formatX, this.formatY)
return label.map((v, i) => {
let style = v.style || {}
let css = v.css || []
css.push(`l-${i}`)
let txt = v.txt || v
return { style, css, txt, i }
})
},
init () {
let opts = this.opts
Expand Down

0 comments on commit 7d609ac

Please sign in to comment.