Skip to content

Commit 51b7925

Browse files
committed
restore d.attr on graphType: polyline
1 parent 7582644 commit 51b7925

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

site/js/playground.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use strict';
22

3-
// functionPlot({
4-
// target: '#playground',
5-
// data: [{
6-
// fn: 'x^2'
7-
// }]
8-
// })
3+
functionPlot({
4+
target: '#playground',
5+
data: [{
6+
fn: 'x^2',
7+
graphType: 'polyline',
8+
attr: {
9+
'stroke-width': 10
10+
}
11+
}]
12+
})
913

1014
// window.f = functionPlot({
1115
// target: '#playground',
@@ -82,38 +86,38 @@
8286
//});
8387

8488

85-
var options = {
86-
target: '#playground',
87-
data: [{
88-
fn: 'x'
89-
}]
90-
};
91-
$('body').append('<button id="update">update</button>')
92-
$('#update').click(function () {
93-
if (!options.title) {
94-
// add a title, a tip and change the function to y = x * x
95-
options.title = 'hello world';
96-
options.tip = {
97-
xLine: true,
98-
yLine: true
99-
};
100-
options.data[0] = {
101-
fn: 'x * x',
102-
derivative: {
103-
fn: '2 * x',
104-
updateOnMouseMove: true
105-
}
106-
}
107-
} else {
108-
// remove the title and the tip
109-
// update the function to be y = x
110-
delete options.title;
111-
delete options.tip;
112-
options.data[0] = {
113-
fn: 'x'
114-
}
115-
}
116-
functionPlot(options)
117-
})
118-
// initial plot
119-
functionPlot(options)
89+
// var options = {
90+
// target: '#playground',
91+
// data: [{
92+
// fn: 'x'
93+
// }]
94+
// };
95+
// $('body').append('<button id="update">update</button>')
96+
// $('#update').click(function () {
97+
// if (!options.title) {
98+
// // add a title, a tip and change the function to y = x * x
99+
// options.title = 'hello world';
100+
// options.tip = {
101+
// xLine: true,
102+
// yLine: true
103+
// };
104+
// options.data[0] = {
105+
// fn: 'x * x',
106+
// derivative: {
107+
// fn: '2 * x',
108+
// updateOnMouseMove: true
109+
// }
110+
// }
111+
// } else {
112+
// // remove the title and the tip
113+
// // update the function to be y = x
114+
// delete options.title;
115+
// delete options.tip;
116+
// options.data[0] = {
117+
// fn: 'x'
118+
// }
119+
// }
120+
// functionPlot(options)
121+
// })
122+
// // initial plot
123+
// functionPlot(options)

src/graph-types/polyline.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ export default function polyline (chart: Chart) {
7676
: null
7777
})
7878
.attr('d', pathD)
79+
80+
if (d.attr) {
81+
for (let k in d.attr) {
82+
path.attr(k, d.attr[k])
83+
}
84+
}
7985
})
80-
// .attr(d => {
81-
// if (d) console.log(d)
82-
// d.attr
83-
// })
8486

8587
// exit
8688
innerSelection.exit().remove()

0 commit comments

Comments
 (0)