almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.85k stars 1.48k forks source link

Graph2d customized options.format.minorLabels function causes validation error #3115

Open physchemcoder opened 7 years ago

physchemcoder commented 7 years ago

I define the customizeMinorLabels function below to add unit(like s or ms) to the minor labels in the Graph2d X axis. It actually works and I can see the customized minor labels. But I also see the error message below shown up in developer console window. It seems that validation code is not happy with my customizeMinorLabels function. Is it a code bug in validation? Or I don't use minorLabels correctly?

"Invalid type received for "minorLabels". Expected: object. Received [function] "function customizeMinorLabels(date, scale, step)"

function customizeMinorLabels(date, scale, step) {
    var minorLabelsFormat = {
        millisecond: 'SSS',
        second: 's',
        minute: 'HH:mm',
        hour: 'HH:mm',
        weekday: 'ddd D',
        day: 'D',
        month: 'MMM',
        year: 'YYYY'
    };
    var minorLabelsUnit = {
        millisecond: 'ms',
        second: 's',
        minute: '',
        hour: '',
        weekday: '',
        day: '',
        month: '',
        year: ''
    };
    var format = minorLabelsFormat[scale];
    var unit = minorLabelsUnit[scale];
    return format && format.length > 0 ? vis.moment(date).format(format) + unit : '';
}

var optionsForIOSize = {
        sampling: true,
        drawPoints: { enabled: false, size: 3 },
        interpolation: false,
        legend: false,
        clickToUse: true,
        start: startTime,
        end: endTime,
        dataAxis: {
            left: { title: { text: "Throughput(MB/s)" } },
            right: { title: { text: "QueueDepth" } }
        },
        format: {
            minorLabels: customizeMinorLabels
        }
    };
bradh commented 7 years ago

Thanks for the report. Can you do this as a jsfiddle / jsbin instead? Its a lot easier to reproduce that way, and ensures we have common understanding of the problem.

physchemcoder commented 7 years ago

Thanks for prompt response. Here you go. Please let me know if it doesn't work for you. http://jsfiddle.net/3c48r3w2/7/

physchemcoder commented 7 years ago

Can anyone take a look at the repro? Thanks.

bradh commented 7 years ago

Please don't feel ignored. There are a lot of issues, and every developer is doing this on their own time, so sometimes it takes a while.

benunternaehrer commented 6 years ago

+1