Skip to content

Commit e04548d

Browse files
authored
Merge pull request #57 from JetJet13/develop
Add Hole in Line Charts | Merge to Master
2 parents 8478f5a + 0712166 commit e04548d

File tree

4 files changed

+210
-4
lines changed

4 files changed

+210
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mathbook",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"private": true,
55
"scripts": {
66
"start": "node ./bin/www",

src/front-end/public/javascripts/helperFunctions.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict"
2+
23
function handleError(err) {
34
console.error("something errored out", err)
45
const status = err.status
@@ -60,7 +61,30 @@ function createLineChart(selector, chartData, chartOptions) {
6061
if (chartOptions["axisX"]) {
6162
chartOptions["axisX"]["type"] = Chartist.AutoScaleAxis
6263
}
63-
return new Chartist.Line(selector, chartData, chartOptions)
64+
const chart = new Chartist.Line(selector, chartData, chartOptions)
65+
convertPointsToHoles(chart)
66+
return chart
67+
}
68+
69+
function convertPointsToHoles(chart) {
70+
chart.on("draw", function(data) {
71+
const pointIndex = data.index
72+
const series = data.series
73+
if (data.type === "point" && series[pointIndex].isHole) {
74+
var point = new Chartist.Svg(
75+
"circle",
76+
{
77+
cx: data.x,
78+
cy: data.y,
79+
// Edir r value for diffrent sizes
80+
r: 5,
81+
fill: "white"
82+
},
83+
"ct-hole"
84+
)
85+
data.element.replace(point)
86+
}
87+
})
6488
}
6589

6690
function uniqueId() {

src/front-end/public/stylesheets/chart-colors.css

+169
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
.ct-series-a .ct-point {
33
stroke: #3e8ef7;
44
}
5+
.ct-series-a .ct-hole {
6+
stroke: #3e8ef7;
7+
stroke-width: 2px;
8+
}
59

610
.ct-series-a .ct-area {
711
fill: #3e8ef7;
@@ -12,6 +16,11 @@
1216
stroke: #49de94;
1317
}
1418

19+
.ct-series-b .ct-hole {
20+
stroke: #49de94;
21+
stroke-width: 2px;
22+
}
23+
1524
.ct-series-b .ct-area {
1625
fill: #49de94;
1726
}
@@ -21,6 +30,11 @@
2130
stroke: #ff666b;
2231
}
2332

33+
.ct-series-c .ct-hole {
34+
stroke: #ff666b;
35+
stroke-width: 2px;
36+
}
37+
2438
.ct-series-c .ct-area {
2539
fill: #ff666b;
2640
}
@@ -30,6 +44,11 @@
3044
stroke: #9463f7;
3145
}
3246

47+
.ct-series-d .ct-hole {
48+
stroke: #9463f7;
49+
stroke-width: 2px;
50+
}
51+
3352
.ct-series-d .ct-area {
3453
fill: #9463f7;
3554
}
@@ -39,6 +58,11 @@
3958
stroke: hsl(22, 99%, 61%);
4059
}
4160

61+
.ct-series-e .ct-hole {
62+
stroke: hsl(22, 99%, 61%);
63+
stroke-width: 2px;
64+
}
65+
4266
.ct-series-e .ct-area {
4367
fill: hsl(22, 99%, 61%);
4468
}
@@ -48,6 +72,151 @@
4872
stroke: hsl(48, 100%, 67%);
4973
}
5074

75+
.ct-series-f .ct-hole {
76+
stroke: hsl(48, 100%, 67%);
77+
stroke-width: 2px;
78+
}
79+
5180
.ct-series-f .ct-area {
5281
fill: hsl(48, 100%, 67%);
5382
}
83+
84+
.ct-series-g .ct-line,
85+
.ct-series-g .ct-point {
86+
stroke: #0544d3;
87+
}
88+
89+
.ct-series-g .ct-hole {
90+
stroke: #0544d3;
91+
stroke-width: 2px;
92+
}
93+
94+
.ct-series-g .ct-area {
95+
fill: #0544d3;
96+
}
97+
98+
.ct-series-h .ct-line,
99+
.ct-series-h .ct-point {
100+
stroke: #6b0392;
101+
}
102+
103+
.ct-series-h .ct-hole {
104+
stroke: #6b0392;
105+
stroke-width: 2px;
106+
}
107+
108+
.ct-series-h .ct-area {
109+
fill: #6b0392;
110+
}
111+
112+
.ct-series-i .ct-line,
113+
.ct-series-i .ct-point {
114+
stroke: #f05b4f;
115+
}
116+
117+
.ct-series-i .ct-hole {
118+
stroke: #f05b4f;
119+
stroke-width: 2px;
120+
}
121+
122+
.ct-series-i .ct-area {
123+
fill: #f05b4f;
124+
}
125+
126+
.ct-series-j .ct-line,
127+
.ct-series-j .ct-point {
128+
stroke: #dda458;
129+
}
130+
131+
.ct-series-j .ct-hole {
132+
stroke: #dda458;
133+
stroke-width: 2px;
134+
}
135+
136+
.ct-series-j .ct-area {
137+
fill: #dda458;
138+
}
139+
140+
.ct-series-k .ct-line,
141+
.ct-series-k .ct-point {
142+
stroke: #eacf7d;
143+
}
144+
145+
.ct-series-k .ct-hole {
146+
stroke: #eacf7d;
147+
stroke-width: 2px;
148+
}
149+
150+
.ct-series-k .ct-area {
151+
fill: #eacf7d;
152+
}
153+
154+
.ct-series-l .ct-line,
155+
.ct-series-l .ct-point {
156+
stroke: #86797d;
157+
}
158+
159+
.ct-series-l .ct-hole {
160+
stroke: #86797d;
161+
stroke-width: 2px;
162+
}
163+
164+
.ct-series-l .ct-area {
165+
fill: #86797d;
166+
}
167+
168+
.ct-series-m .ct-line,
169+
.ct-series-m .ct-point {
170+
stroke: #b2c326;
171+
}
172+
173+
.ct-series-m .ct-hole {
174+
stroke: #b2c326;
175+
stroke-width: 2px;
176+
}
177+
178+
.ct-series-m .ct-area {
179+
fill: #b2c326;
180+
}
181+
182+
.ct-series-n .ct-line,
183+
.ct-series-n .ct-point {
184+
stroke: #6188e2;
185+
}
186+
187+
.ct-series-n .ct-hole {
188+
stroke: #6188e2;
189+
stroke-width: 2px;
190+
}
191+
192+
.ct-series-n .ct-area {
193+
fill: #6188e2;
194+
}
195+
196+
.ct-series-n .ct-line,
197+
.ct-series-n .ct-point {
198+
stroke: #6188e2;
199+
}
200+
201+
.ct-series-n .ct-hole {
202+
stroke: #6188e2;
203+
stroke-width: 2px;
204+
}
205+
206+
.ct-series-n .ct-area {
207+
fill: #6188e2;
208+
}
209+
210+
.ct-series-o .ct-line,
211+
.ct-series-o .ct-point {
212+
stroke: #a748ca;
213+
}
214+
215+
.ct-series-o .ct-hole {
216+
stroke: #a748ca;
217+
stroke-width: 2px;
218+
}
219+
220+
.ct-series-o .ct-area {
221+
fill: #a748ca;
222+
}

src/front-end/tags/chart-modal/chart-modal.tag

+15-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
<textarea id="chartSeries" class="textarea" placeholder="x;y pairs, ie. 1;2, 2;3, 3;4"></textarea>
110110
<p class="help">format: x;y => (1,3). e.g. 1;2 => (1,2)
111111
<br/>
112+
You are able to insert a hole in the chart: hole(x;y) => hole(1;2)
113+
<br/>
112114
Starting a new line (hitting enter) will add a new line plot
113115
</p>
114116
</div>
@@ -223,6 +225,12 @@
223225
const y = splitPoint[1]
224226
series.push({ x: x, y: y })
225227
}
228+
else if (self.isValidHolePoint(point)){
229+
const splitPoint = point.replace(/(hole\(){1}|(\){1})/g, '').split(';')
230+
const x = splitPoint[0]
231+
const y = splitPoint[1]
232+
series.push({ x: x, y: y, isHole: true })
233+
}
226234
else if (dataType[k] === "null"){
227235
series.push(null)
228236
}
@@ -243,7 +251,13 @@
243251
isValidInputPoint(point){
244252
// point should follow the following format: x;y => 1;3
245253
// decimals are allowed
246-
return /^(\-)?\d+(?:\.\d+)?[\;](\-)?\d+(?:\.\d+)?$/.test(point)
254+
return /^(\-)?\d+(?:\.\d+)?[\;]((\-)?\d+(?:\.\d+)?|(null)?)$/.test(point)
255+
}
256+
257+
isValidHolePoint(point){
258+
// point should follow the following format: hole(x;y) => hole(1;3)
259+
// decimals are allowed
260+
return /^(hole\()(\-)?\d+(?:\.\d+)?[\;]((\-)?\d+(?:\.\d+)?|(null)?)(\))$/.test(point)
247261
}
248262

249263
toggleOption(type){
@@ -324,7 +338,6 @@
324338
this.xAxisHigh = "null"
325339
this.yAxisLow = "null"
326340
this.yAxisHigh = "null"
327-
console.log('finished cleaning up fields')
328341
}
329342

330343
closeModal(){

0 commit comments

Comments
 (0)